Tuesday, 9 December 2014

Program for armstrong number
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
//////////////////////////
void arms(int n)
{
int temp,rem,sum=0;
temp=n;
while(n>0)
{
rem=n%10;
sum=sum+(rem*rem*rem);
n=n/10;
}
printf("sum:%d\n",sum);
if(sum==temp)
printf("armstrong number...\n");
else
printf("not an armstrong number..\n");
}


main(int argc,char **argv)
{
int n,sum=0,rem,temp,i;
//if(argc!=2)
//printf("enter correct number of arguments...\n");
for(i=1;i<argc;i++)
{
n=atoi(argv[i]);
arms(n);
}
}
OutPut:
madan@madan-Lenovo-G570:~/madan$ vi arm.c
madan@madan-Lenovo-G570:~/madan$ cc arm.c
madan@madan-Lenovo-G570:~/madan$ ./a.out 153
sum:153
armstrong number...
madan@madan-Lenovo-G570:~/madan$ ./a.out 153
sum:153
armstrong number...
madan@madan-Lenovo-G570:~/madan$ ./a.out 123
sum:36
not an armstrong number..