Saturday, September 1, 2012

Armstrong number program using C language

Armstrong number: A number is called armstrong number when the sum of quebs of individual digits of a number is equal to the number itself. To write the program we need to seperate the individual digits we can do this by first modular division and division by 10. Consider the example 153 the individual digits are 1,5,3 sum of quebs of individual digits are 153 and the number itself is 153.

Program
#include<stdio.h>
main()
{
int n,r,t,s=0;
printf("\n Enter the number");
scanf("%d",&n);
t=n;
while(n>0)
{
r=n%10;
s=s+(r*r*r);
n=n/10;
}
if(s==t)
printf("\n %d is armstrong number",t);
else
printf("\n %d is not armstrong number",t);
getch();
}

No comments:

Post a Comment

DC motor control with Pulse Width Modulation Part 1

DC Motor intro DC motor is a device which converts electrical energy into kinetic energy. It converts the DC power into movement. The typica...