Write a program to print out all armstrong numbers between 1 to 500 . If sum of cube of each digit of the number is equal to the number itself then the number is called Armstrong number for example 153 = (1*1*1)+(5*5*5)+(3*3*3).

Write a program to print out all Armstrong numbers between 1 to 500 . If sum of cube of each digit of the number is equal to the number itself then the number is called Armstrong number for example  153=(1*1*1)+(5*5*5)+(3*3*3).

#include<stdio.h>

#include<conio.h>

#include<math.h>

int main()

{

int num,temp,rem=0,sum=0,i;

float cube;

temp =1;

for(i=1;i<500;i++)

{
while(num!=0)

{

rem=num%10;

cube=pow(rem,3);//or we can write (rem*rem*rem)

sum =sum+cube;

num=num/10;//here the value of  num =0

}

if(sum==temp)

priintf("%d\n",temp);

//set default values to the variables

rem=0;

sum=0;

cube=0;

//increment temp and  num value according to i

//for the first loop i=1

temp=i+1;

num=i+1;

}

}

OR

#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
int num,temp,rem=0,sum=0,i;
float cube;
temp =1;
for(i=1;i<500;i++)
{
while(num!=0)
{
rem=num%10;
cube=pow(rem,3);
//or we can write (rem*rem*rem)
sum =sum+cube;
num=num/10;//here the value of  num =0
}
if(sum==temp)
printf("%d\n",temp);
//set default values to the variables
rem=0;
sum=0;
cube=0;
//increment temp and  num value according to i
//for the first loop i=1
temp=i+1;
num=i+1;
}
}





 RELATED PROGRAM--

1.write a program to the ASCII values and their equivalent character using a while loop the ASCII values vary from 0to 255.

2.Write a program using reference variables a argument to swap the value of a pair of a integers of C++.

Comments

Popular posts from this blog

If lengths of three sides of a tringle are input through the keyboard write a program to find the area of tringle.

the length and breadth of a rectangle and radius of a circle are input through the keyboard. write a program to calculate the area and perimeter of the rectangle, and the area and circumference of the circle

paper of size A0 has dimensions 1189 mmx 841 mm .Each subsequent size A(n) is defined as A(n-1) cut in half parallel to its shorter sides .Thus paper of size A1 would have dimensions 841 mm X 594 mm .Write a program to calculate the print paper sizes A0,A1,A2,.........A8.