Thursday, 2 December 2010

write a function for armstrong number or not?

//armstrong number
//sum of each digit of the cubes equal to given number
#include<stdio.h>
#include<conio.h>
int arm(int n)
{
 int sum=0,a,rem;
 a=n;
 while(n>0)
 {
  rem=n%10;
  sum=sum+rem*rem*rem;
  n=n/10;
 }
 return(a==sum);
}
void main()
{
 int n,arm(int);
 clrscr();
 printf("etner n value\n");
 scanf("%d",&n);
 if(arm(n))
  printf("armstrong number\n");
 else
  printf("not a armstrong number\n");
 getch();
}

No comments:

Post a Comment