C C++ program to generate series of Armstrong numbers

C C++ program to generate series of Armstrong numbers

C Language के बारे में अधिक जानने के लिए देखें—Brief Introduction of C

C और C++ दोनों भाषाओं में महत्वपूर्ण अंतर क्या है जानने के लिए देखें—C vs C++

Looping और iterative statements के बारे में और अधिक जानने के लिए देखें— Looping statements in C

Flowchart to generate series of Armstrong numbers

Generate series of armstrong numberrs upto n flowchart

C program to generate series of Armstrong numbers

#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;
}

C++ program to generate series of Armstrong numbers

#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 of C C++ program to generate series of Armstrong numbers

Enter n: 200
1
153
Enter n: 500
1
153 
370
371
407

More iteration logic programs in C C++

  1. Generate series of natural numbers (while, for, do while)
  2. Generate series of natural numbers and their sum
  3. Generate series of odd numbers and find their sum
  4. Generate series of even numbers and find their sum
  5. Generate table of given number
  6. Find factorial of given number
  7. Find power of given number
  8. Generate multiplication table of given number
  9. HCF and LCM of two numbers
  10. Generating Fibonacci series
  11. Checking prime number
  12. Generating series of prime numbers
  13. Sum of digits of given number
  14. Reverse of digits of given number
  15. Checking palindrome number
  16. Checking Armstrong number
  17. Convert decimal to binary
  18. Convert binary to decimal
Share it to:

Published by

admin

I am a computer teacher, programmer and web developer