c language
I want a program from 1 to 1000 armstrong numbers with source code?
Dear Friend,
Here is the source code use it with syntax: %26lt;program_name%26gt; %26lt;start%26gt; %26lt;end%26gt;
This will generate a list of all armstrong numbers between start and end
---------------------------- Source Code ------------------------------
#include%26lt;stdio.h%26gt;
#include%26lt;stdlib.h%26gt;
void main(int argc, char* args[]) {
long arm_beg, arm_end, t1, sum=0,t2;
if (argc!=3) {
printf("Usage: gen_arm %26lt;beg_no%26gt; %26lt;end_no%26gt;");
return;
}
arm_beg= atol(args[1]);
arm_end= atol(args[2]);
if (arm_beg%26lt;=0 || (arm_end%26lt;arm_beg)) {
printf("Invalid arguments");
return;
}
while(arm_beg%26lt;=arm_end){
t1=arm_beg;
sum=0;
while(t1%26gt;=1){
t2=t1%10;
sum+=t2*t2*t2;
t1/=10;
}
if (sum==arm_beg) {
printf("\n%ld",arm_beg);
}
arm_beg++;
}
}
---------------------------- Source Code ------------------------------
Enjoy and all the best.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment