C program to find an armstrong number.

 

01 #include<stdio.h>
02
03 int main()
04 {
05 int a,n,b=0,t;
06
07 printf("Enter the no");
08 scanf("%d",&n);
09 t=n;
10
11 while(n>0)
12 {
13 a=n%10;
14 b=b+a*a*a;
15 n=n/10;
16 }
17 if(b==t)
18 {
19 printf("Armstrong no");
20 }
21 else
22 {
23 printf("Not an armstrong no");
24 }
25
26 return 0;
27 }
 
 
OUTPUT :

(1st Run)

Enter the no 153
Armstrong no

(2nd Run)

Enter the no 123
Not an armstrong no

Related Post

Leave a Reply

Your email address will not be published. Required fields are marked *