Wednesday, August 17, 2011

QUES 11 ARMSTRONG NO


C LANGUAGE BOOK






Example 153

 here first digit =1,
        second digit =5
        third digit=3
if  (1*1*1)+(5*5*5)+(3*3*3) == 153
then number is armstrong no
else
number is not armstrong no

1+125+27=153 hence 153 is armstong no.

 WAP TO PRINT ARMSTRONG NO. FROM 1 TO 500

 #include<stdio.h>                      
 #include<conio.h>                      
 void main()                             
 {
   int i,p1,p2,p3,s;
   clrscr();
   for(i=1;i<=500;i++)
   {
    p1= (i/100);                       //calculating first digit
    p2= ((i/10)-(10*p1));              //calculating second digit
    p3= ((i)-((100*p1)+(10*p2)));      //calculating third digit
    s=((p1*p1*p1)+(p2*p2*p2)+(p3*p3*p3));

   if(s==i)
    printf("\n armstrong no.is %d" ,s);

   }
   getch();
 }                                        






C LANGUAGE BOOK

No comments:

Post a Comment