Now you can Subscribe using RSS

Submit your Email

04 April 2017

C program To find given Number is Armstrong or Not

LAKS Tutorials
Write a C program to find given number is Armstrong or Not.

Armstrong Number Means: Number must and should an integer and sum of the cubes of its individual digits is equal to the number it self. Example:153=(1*1*1)(5*5*5)(3*3*3)

Method 1:Find Armstrong number in c programming by using for loop

#include<stdio.h>
 int main()
{
 int num,sum=0,temp,rem;
 printf("\n enter any value to find given number is Armstrong or not\t");
 scanf("%d",&num);
 for(temp=num;num!=0)
{
rem=num%10;
 sum=sum+(rem*rem*rem);
num=num/10;
 }
if(sum==temp)
 {
printf("/n%d is an armstrong number",temp);
}
else
{
 printf(""/n%d is not an armstrong number",temp);
}
return 0;
}
Output
Enter a Number 132
132 is not an armstrong number

Method 2:Find Armstrong number in c programming by using for while loop

#include<stdio.h>
int main()
 {
int num,sum=0,temp,rem;
printf("\n enter any value to find given number is Armstrong or not\t");
 scanf("%d",&num);
while(num!=0)
{
rem=num%10;
 sum=sum+(rem*rem*rem);
num=num/10;
}
if(sum==temp)
 {
printf("/n%d is an armstrong number",temp);
 }
else
{
printf(""/n%d is not an armstrong number",temp);
}
return 0;
 }
Output
Enter a Number 153
153 is an armstrong number

LAKS Tutorials / Author & Editor

RAM.P is Founder of the LAKS TUTORIAL.The Main AIM of the author is providing basics to the beginners of the program to imrove their knwoledge

0 comments:

Post a Comment

Coprights @ 2016, Blogger Templates Designed By Templateism | Templatelib