C C++ program to generate series of armstrong numbers

 

Flowchart

Generate series of armstrong numberrs upto n flowchart

 

Coding in C

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

 

Coding in C++

#include<iostream>
using namespace std;
int main()
{
int num=1,rem,sum,org,n;
cout<<“Enter n: “;
cin>>n;
while(num<=n)
{
org=num;
sum=0;
while(num!=0)
{
rem=num%10;
sum=sum+rem*rem*rem;
num=num/10;
}
if(sum==org)
{
cout<<sum<<“\n”;
}
num=org+1;
}
return 0;
}

 

Output

Generate series of armstrong numberrs upto n output

 

Published by

admin

I am a computer teacher, programmer and web developer