Categories: C

Miscellaneous Program(Armstrong Number)

An Armstrong number is an n-digit number whose sum of digits raised to the nth power equals the number itself.

Take, for example, the Armstrong number 153, which is a three-digit number; 1^3 + 5^3 + 3^3 equals 1 + 125 + 27, which equals 153.

A program to find Armstrong numbers between 1 and 500 is provided below.

#include<stdio.h>
#include<math.h>

int main()
{
    
    int n,sum,i,t,a;
    printf("\nThe Armstrong numbers in between 1 to 500 are : \n");

    for(i = 1; i <= 500; i++)
    {
        t = i;  // as we need to retain the original number
        sum = 0;
        while(t != 0)
        {
            a = t%10;
            sum += a*a*a;
            t = t/10;
        }

        if(sum == i)
        printf("\n\t%d", i);
    }

   
    return 0;
}

Output:

The Armstrong numbers in between 1 to 500 are : 

 1
 153
 370
 371
 407

Note: also read about the Miscellaneous Program(reverse the case of input string)

Follow Me

If you like my post please follow me to read my latest post on programming and technology.

https://www.instagram.com/coderz.py/

https://www.facebook.com/coderz.py

Share
Published by
Rabecca Fatima

Recent Posts

Generate Parenthesis | Intuition + Code | Recursion Tree | Backtracking | Java

Problem Statement: Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. Example…

2 months ago

Square Root of Integer

Given an integer A. Compute and return the square root of A. If A is…

1 year ago

Build Array From Permutation

Given a zero-based permutation nums (0-indexed), build an array ans of the same length where…

1 year ago

DSA: Heap

A heap is a specialized tree-based data structure that satisfies the heap property. It is…

1 year ago

DSA: Trie

What is a Trie in DSA? A trie, often known as a prefix tree, is…

2 years ago

Trees: Lowest Common Ancestor

What is the Lowest Common Ancestor? In a tree, the lowest common ancestor (LCA) of…

2 years ago