Armstrong Number | Do/While Loop | Lecture #80 #numbersystem #armstrong #coding #logical #developer
This program is written in the C language to check whether a given number is an Armstrong number (for 3-digit numbers). π· Purpose of the Program The program takes an integer input from the user and determines whether it is an Armstrong number by calculating the sum of the cubes of its digits and comparing it with the original number. π· Variables Used num β Stores the number entered by the user. rem β Stores each digit of the number one by one. cube β Stores the cube of each extracted digit. sum β Stores the total sum of the cubes of digits (initialized to 0). save β Stores the original number for comparison after calculation. π· Working of the Program The program asks the user to enter a number. The entered number is stored in a variable. The original number is saved in another variable because the main number will change during processing. Using a loop, the program: Extracts the last digit of the number. Finds the cube of that digit. Adds the cube to a running total (sum). Removes the last digit from the number. This process continues until all digits are processed. After the loop ends, the program compares: The calculated sum of cubes The original number If both are equal, it prints that the number is an Armstrong number. Otherwise, it prints that the number is not an Armstrong number. π· Concept Used Modulus operator (%) to extract digits Division operator (/) to remove digits Loop (do-while) for repeated digit processing Conditional statement (if-else) for comparison π· Conclusion This program checks whether a number is an Armstrong number by verifying if the sum of the cubes of its digits is equal to the original number. It works correctly for 3-digit Armstrong numbers such as 153, 370, 371, and 407. #logical #coding #hindi #study #concept #love #cprogramming #fundamentalanalysis #beginners #developer
Download
0 formatsNo download links available.