Menu BAR

FEEL FREE TO ASK ANY PROGRAM and please mention any error if you find it

1 Feb 2013

Armstrong number or not

Q.) Write a C program to check whether the number is ARMSTRONG NUMBER or NOT .

Sol)

#include<stdio.h>
#include<conio.h>

int main()
{
    int num,r,sum=0,temp ;
    
    printf("Enter a number: ") ;
    scanf("%d",&num) ;
    
    temp=num ;
    while(num!=0)
         {
               r=num%10;
               num=num/10;
               sum=sum+(r*r*r) ;
          }

     if(sum==temp)
                 print("%d is an ARMSTRONG NUMBER",temp) ;
      else
                 printf("%d is not an ARMSTRONG NUMBER", temp) ;
      return 0 ;
  }

No comments:

Post a Comment