C Programming : To check number is Armstrong or not.

Posted on:
tags: , ,

/* This is a 'C' program.
This program will check that given number is Armstrong or not.*/
#include<stdio.h>
#include<conio.h> //header files
void main()
{
int a,n,t,sum;//variables
clrscr();
printf("\n Enter a number [natural number]:");
scanf("%d",&n);
t=n;
sum=0;//for additive identity
while(n>0)//loop start. This loop calculate the armstrong of given number.
{
a=n%10;
sum=sum+a*a*a;
n=n/10;
} //loop end
if(t==sum)//This statement check the armstrong of given number
printf("\n\n The given number is Armstrong!!!");
else
printf("\n\n The given number is Not Armstrong!!!");
getch();
}//program end

No comments:

Post a Comment

< >