program to check Armstrong number
In this program , we will now check weather a number is Armstrong number by taking input form the user .
Armstrong number:- A positive number is called an Armstrong number if the sum of the cubes if the digits is equal to the number itself.
In case of an Armstrong number of 3 digits, the sum of cubes of each digits is equal to the number itself. For example: 153:- 1*1*1 + 5*5*5+3*3*3
In case of an Armstrong number of 3 digits, the sum of cubes of each digits is equal to the number itself. For example: 153:- 1*1*1 + 5*5*5+3*3*3
//program to check armstrong
#include<stdio.h>
#include<conio.h>
void main()
{
int n,x,s=0,temp;
printf("enter the number:-");
scanf("%d",&n);
temp=n;
while(n!=0){
x=n%10;
s=s+(x*x*x);
n=n/10;
}
if(temp==s)
printf("\n number is armstrong");
else
printf("\n number is not armstrong");
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int n,x,s=0,temp;
printf("enter the number:-");
scanf("%d",&n);
temp=n;
while(n!=0){
x=n%10;
s=s+(x*x*x);
n=n/10;
}
if(temp==s)
printf("\n number is armstrong");
else
printf("\n number is not armstrong");
getch();
}
output:-
For more c-programming:-

No comments:
Post a Comment