
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Armstrong Numbers between two integers?
An integer is called an Armstrong number of order n if it's every digit separate out and cubed and summed up then the sum will be same as the number i.e. abcd... = a3 + b3 + c3 + d3 + ...
In case of an Armstrong number of 3 digits, the sum of cubes of each digit is equal to the number itself. For example:
153 = 13 + 53 + 33 // 153 is an Armstrong number.
Input: Enter two numbers(intervals):999 9999 Output: Armstrong numbers between 999 and 9999 are: 1634 8208 9474
Explanation
1634 = 13+63+33+43 = 1+216+27+64 = 1634
The approach implemented below is simple. We traverse through all numbers in the given range. For every number, we first count the number of digits in it. Let the number of digits in the current number be n. Them we find the sum of the cube of all digits. If the sum is equal to I, we print the number.
Example
#include <stdio.h> #include <math.h> int main() { int low = 100; int high = 400; printf("The amstrong numbers between %d and %d is \n",low,high); for (int i = low+1; i < high; ++i) { int x = i; int n = 0; while (x != 0) { x /= 10; ++n; } int pow_sum = 0; x = i; while (x != 0) { int digit = x % 10; pow_sum += pow(digit, n); x /= 10; } if (pow_sum == i) printf("%d ", i); } printf("\n"); return 0; }
- Related Questions & Answers
- Java Program to Check Armstrong Number between Two Integers
- Java program to print the Armstrong numbers between two numbers
- Armstrong numbers between a range - JavaScript
- C++ Program to Display Armstrong Number Between Two Intervals
- Java Program to Display Armstrong Number Between Two Intervals
- C Program for Armstrong Numbers
- Comparing integers by taking two numbers in JavaScript
- Java Program to Display Armstrong Numbers Between Intervals Using Function
- Random whole number between two integers JavaScript
- How to generate armstrong numbers in Python?
- How to print Narcissistic(Armstrong) Numbers with Python?
- Maximum Product of Two Numbers in a List of Integers in JavaScript
- Finding Armstrong numbers in a given range in JavaScript
- Divide Two Integers in C++
- How to generate random numbers between two numbers in JavaScript?
Advertisements