/* Check Armstrong Number */
#include<stdio.h>
int main()
{
int n, sum = 0, t, r;
printf("Please enter a number: ");
scanf("%d",&n);
for(t=n;t>0;t=t/10)
{
r = t%10;
sum = sum + r*r*r;
}
if ( n == sum )
printf("%d is an armstrong number.",n);
else
printf("%d is not an armstrong number.",n);
return 0;
}
Related Links:
Print Armstrong Numbers Upto N
http://cbasicprogram.blogspot.in/2012/05/print-armstrong-numbers-upto-n.html
#include<stdio.h>
int main()
{
int n, sum = 0, t, r;
printf("Please enter a number: ");
scanf("%d",&n);
for(t=n;t>0;t=t/10)
{
r = t%10;
sum = sum + r*r*r;
}
if ( n == sum )
printf("%d is an armstrong number.",n);
else
printf("%d is not an armstrong number.",n);
return 0;
}
Related Links:
Print Armstrong Numbers Upto N
http://cbasicprogram.blogspot.in/2012/05/print-armstrong-numbers-upto-n.html
it's wrong
ReplyDeletefor which number you have tested it ??
Deleteabe its correct
Delete#include
ReplyDeleteusing namespace std;
int main()
{
int an= 371;
int t=0,t1=an, sum=0;
while(an>0){
t = an%10;
sum = sum + t*t*t;
t = 0;
an = an/10;
}
if(t1 == sum){
cout<<"armstrong number";
}else{
cout<<"not armstrong number";
}
return 0;
}
//using C#
ReplyDeleteint num, sum = 0;
num = Convert.ToInt32(Console.ReadLine());
for (int i = num; i > 0;)
{
sum += (i % 10) * (i % 10) * (i % 10);
i = i / 10;
}
if(sum==num)
{
Console.WriteLine("No is armstrong");
}
else
{
Console.WriteLine("No is not armstrong ");
}
Console.ReadLine();
}