Monday, June 25, 2012

Number is Armstrong or not?

Program to check that the number is Armstrong or not ?

1:  void armstrong() {  
2:      int arm,qou,rem,n;  
3:      for(n = 1 ; n <= 999 ; n++) {  
4:             qou = (n/100);  
5:             arm = (qou*qou*qou);  
6:             rem = (n%100);  
7:             qou = (rem/10);  
8:             rem = (rem%10);  
9:             arm = arm+(qou*qou*qou)+(rem*rem*rem);  
10:             if(n == arm) {  
11:                  printf("%d is armstrong\n",n);  
12:             }  
13:      }  
14:  }  
15:  Output :-  
16:  1 is armstrong  
17:  153 is armstrong  
18:  370 is armstrong  
19:  371 is armstrong  
20:  407 is armstrong  

Call this function from your main
Like :-



1:  void main() { 
2:        armstrong();  
3:  }  
Post a Comment