C C++ program to check armstrong number

 

Flowchart

Check whether given number is armstrong or not flowchart

 

Coding in C

#include<stdio.h>
int main()
{
int num,rem,sum=0,org;
printf(“Enter a number: “);
scanf(“%d”,&num);
org=num;
while(num!=0)
{
rem=num%10;
sum=sum+rem*rem*rem;
num=num/10;
}
if(sum==org)
{
printf(“Armstrong”);
}
else
{
printf(“Not an Armstrong”);
}
return 0;
}

 

Coding in C++

#include<iostream>
using namespace std;
int main()
{
int num,rem,sum=0,org;
cout<<“Enter a number: “;
cin>>num;
org=num;
while(num!=0)
{
rem=num%10;
sum=sum+rem*rem*rem;
num=num/10;
}
if(sum==org)
{
cout<<“Armstrong”;
}
else
{
cout<<“Not an armstrong”;
}
return 0;
}

 

Output

Check whether given number is armstrong or not output

 

Published by

admin

I am a computer teacher, programmer and web developer