Armstrong number

C program to find number is Armstrong or not  :

code

  #include<stdio.h>

#include<conio.h>

   void main()

{

    int num,rem,sum=0,cube=1,temp;

   clrscr();

   printf(“\nEnter a number :”);

   scanf(“%d”, &num);

   temp=num;

    while(temp!=0)

{

     rem=temp % 10;

    cube=(rem * rem * rem);

     sum =sum+cube;

     temp= temp / 10;

}

    if(num == sum)

{

      printf(“\n%d is armstrong number”,num);

 }

  else

{

     printf(“\n%d is not armstrong  number”);

}

   getch();

}


output

Enter number :

153

153 is armstrong number

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s