C program to check given number is Armstrong or not

 

 C program to check given number is Armstrong or not



/****************************************************

 C program to check given number is Armstrong or not

 ***************************************************/

 #include<stdio.h>

 #include<conio.h>

 void main()

 {

     int n,armstrong=0,rem,temp;

    printf("Enter number to check it is Armstrong or not\n");

     scanf("%d",&n);

     temp=n;

     while(n!=0)

     {

         rem=n%10;

         armstrong=(rem*rem*rem)+armstrong;

         n=n/10;

     }

     if(temp==armstrong)

     {

     printf("Given number %d  is armstrong number\n",temp);

     }

     else

     {

     printf("Given number %d  is not armstrong number\n",temp);

     }

     printf("End of program");

 }

 

Enter number to check it is Armstrong or not

123

Given number 123  is not armstrong number

End of program


Enter number to check it is Armstrong or not

153

Given number 153  is armstrong number

End of program


टिप्पणी पोस्ट करा

0 टिप्पण्या