This C++ code checks for Armstrong numbers in a given range. It takes a starting value i and an ending value n as inputs and iterates through the range to find Armstrong numbers. Armstrong numbers are numbers that are equal to the sum of their digits raised to the power of the number of digits.
The code uses division and modulus operators to extract the digits of each number in the range. It then raises each digit to the power of 3 (since it is checking for 3-digit Armstrong numbers), and adds them up to see if they equal the original number. The code prints out each Armstrong number it finds, and keeps a count of the total number of Armstrong numbers it finds.
#include<iostream> using namespace std; int main() { int i,n,h,arms=0,a,b,c,d,e; cout<<"\nEnter the starting value:"; cin>>i; cout<<"\nEnter the Ending value:"; cin>>n; cout<<"\nArmstrong numbers:"; for(i;i<=n;i++) { a=i/10;//12 b=i%10;//8 c=a/10;//1 d=a%10;//2 b=b*b*b; c=c*c*c; d=d*d*d; e=b+c+d; if(i==e) { cout<<"\n"<<i; arms++; } } cout<<"\nTotal number of armstrong values:"<<arms; return 0; }To download raw file Click Here
Enter the starting value:1 Enter the Ending value:10 Armstrong numbers: 1 Total number of armstrong values:1
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions