This is a C++ program that finds Armstrong numbers between a given starting and ending value. Armstrong numbers are numbers whose sum of cubes of digits is equal to the number itself. Let's go through the program step-by-step:
Overall, the program correctly identifies Armstrong numbers in the given range and prints them to the console. However, the variable h is not used anywhere in the program, and it's unclear why it was declared. Additionally, the variable e is used to store the sum of the cubes of the digits, but it's not a very descriptive name. It would be better to use a variable name that reflects the purpose of the variable.
#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:"; while(i<=n) { 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++; } i++; } cout<<"\nTotal number of armstrong values:"<<arms; return 0; }To download raw file Click Here
Enter the starting value:1 Enter the Ending value:20 Armstrong numbers: 1 Total number of armstrong values:1
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions