This blog consists of C and C++ programs. C and C++ programming is the basics to learn any programming language. Most of the programs are provided with their respective outputs. This blog also contains Data Structures programs using Object-Oriented Programming (C++). Some of the best books for learning C and C++ programming are also mentioned.

Thursday 27 June 2013

Program to check whether the given number is Armstrong Number or not

Armstrong Number:
An Armstrong number (after Michael F. Armstrong) or a narcissistic number (also known as a pluperfect digital invariant (PPDI), or a plus perfect number) is a number that is the sum of its own digits each raised to the power of the number of digits.

Program:
#include<stdio.h>
void main()
{
int n,rem=0,sum=0,a;
clrscr();
printf("Enter the number:");
scanf("%d",&n);
a=n;
while(n>0)
{
rem=n%10;
sum=sum+rem*rem*rem;
n=n/10;
}
if(a==sum)
printf("%d is an Armstrong number",a);
else
printf("%d is not an Armstrong number",a);
getch();
}

No comments:

Post a Comment