C Program to Check Armstrong Number

Learn via video course
FREE
View all courses
C++ Course: Learn the Essentials
C++ Course: Learn the Essentials
by Prateek Narang
1000
5
Start Learning
C++ Course: Learn the Essentials
C++ Course: Learn the Essentials
by Prateek Narang
1000
5
Start Learning
Topics Covered

Overview

In numerical number theory, the Armstrong number definition is the number in any given number base, which forms the total of the same number when each of its digits is raised to the power of the number of digits in the number.

Prerequisites

Check Armstrong Number of three digits

Transform Your Career

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program

Algorithm (for a 3-digit Number)

Step 1: Start.

Step 2: Read an integer input number.

Step 3: Initialize the variables current_digit, sum = 0, and num = number.

Step 4: Repeat Steps 5 to 7 until num > 0.

Step 5: current_digit = (num % 10).

Step 6: sum = sum + (current_digit * current_digit * current_digit).

Step 7: num = num / 10.

Step 8: Check if sum == number. If true, print "It is an Armstrong Number." Otherwise, print "It is not an Armstrong Number."

Step 9: END

Program for Three-Digit Armstrong Number in C

Here's a C program to check whether a given three-digit number is an Armstrong number:

Output:

Check Armstrong Number of N digits

Turn Learning into Career Growth

1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary
1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary

Algorithm (for N-digit Number)

Step 1: Start.

Step 2: Read an integer input number.

Step 3: Initialize the variables current_digit, sum = 0, digits = 0, and num = number.

Step 4: Calculate the number of digits in the input integer number and store it in the variable number_of_digits.

Step 5: Repeat Steps 5 to 7 until num > 0.

Step 6: current_digit = (num % 10).

Step 7: sum = sum + pow(current_digit, number_of_digits).

Step 8: num = num / 10.

Step 9: Check if sum == number. If true, print "It is an Armstrong Number." Otherwise, print "It is not an Armstrong Number."

Step 10: END

Program for N-Digit Armstrong Number in C

Here's a generalized C program to check whether a given N-digit number is an Armstrong number:

Output:

Scaler Placement Report and Statistics

₹23L
AVG CTC
SCALER PLACEMENT PROOF

Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.

11,000+placements
650+companies
Verified data

Armstrong Number Using Functions

Refactoring code to use functions can enhance its modularity, readability, and reusability. In this section, we'll demonstrate how to check for an Armstrong number using functions in C.

Scaler Placement Report and Statistics

₹23L
AVG CTC
SCALER PLACEMENT PROOF

Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.

11,000+placements
650+companies
Verified data

Functions in Use

1. Function to Calculate Number of Digits:

  • Purpose: Calculates the number of digits in the given number.
  • Input: Integer (number).
  • Output: Integer (number of digits).

2. Function to Check Armstrong Number:

  • Purpose: Checks if a number is an Armstrong number.
  • Input: Integer (number).
  • Output: Integer (1 if Armstrong, 0 otherwise).

Main Program

  • The main program takes an integer input.
  • Calls the isArmstrong function to check if the number is an Armstrong number.
  • Displays the result based on the output from the isArmstrong function.

Conclusion

  • We have discussed what Armstrong numbers are, and then we have seen a C program to check for a three-digit number, whether it is Armstrong or not.
  • We have learned about a more generalized version of it for N-digit numbers.
Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more