adsense

Hii, welcome to my site. My name is Om prakash kartik. This blog helps you to learn programming languages concepts.

Write a program in C to check that a number entered by the user is Armstrong number.

 Write a program in C to check that a number entered by the user is Armstrong number.

   Definition of Armstrong number :- If sum of cubes of each of digit of the number is equal to the number itself, then the number is called an Armstrong number.
For example :- 153= (1*1*1)+(3*3*3)+(5*5*5).

#include<stdio.h>
#include<conio.h>
  void main()
    {
    int r,n,m,sum=0;
    clrscr();
    printf("Enter a number:-");
    scanf("%d",&n);
    m=n;
    while(n>0)
   {
      r=n%10; 
      sum=sum+r*r*r; 
      n=n/10; 
     }
   if(m==sum)
       printf("%d is armstrong no.",m);
  else
       printf("%d is not armstrong no.",m);
   getch();
  }

Output:




Post a Comment

0 Comments