In this tutorial, we will learn how to write a program that check given number is Armstrong or not.
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int num,x,j,temp,sum=0;;
printf("\n Enter a number to know it is armstrong or not:\n ");
scanf("%d",&num);
temp=num;
while(num>0)
{
x=num%10;
sum+=x*x*x;
num=num/10;
}
if(sum==temp)
{
printf("\n Given number %d is an armstrong number.\n",temp);
}
else
{
printf("\n Given number %d is not an armstrong number.\n",temp);
}
getch();
}
In first output, enter value of number is 153
Given number is Armstrong.
In second output, enter value of number is 258
Given number is not Armstrong.
C Program Code
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int num,x,j,temp,sum=0;;
printf("\n Enter a number to know it is armstrong or not:\n ");
scanf("%d",&num);
temp=num;
while(num>0)
{
x=num%10;
sum+=x*x*x;
num=num/10;
}
if(sum==temp)
{
printf("\n Given number %d is an armstrong number.\n",temp);
}
else
{
printf("\n Given number %d is not an armstrong number.\n",temp);
}
getch();
}
OUTPUT 1:
OUTPUT 2:
In first output, enter value of number is 153
Given number is Armstrong.
In second output, enter value of number is 258
Given number is not Armstrong.
Please share this post and blog link with your friends.For more programs use this blog.
If you have any problem, please comment in comment box, subscribe this blog for notifications of new post on your email and follow this blog.
Created by-- HARSH CHAUHAN
No comments:
Post a Comment