Search This Blog
Welcome to 1printf(), your ultimate destination for C, C++, Linux, Data Structures, and Microcontroller programming! ๐ ๐นLearn advanced coding techniques in C& C++ ๐นMaster Linux internals & shell scripting ๐นDeep dive into Data Structures & Algorithms ๐นExplore Embedded Systems & Microcontrollers (8051,UART, RTOS) ๐นGet hands-on coding tutorials, project ideas,and interview preparation tips Whether you're a beginner or an experienced programmer, this channel will help you
Featured
- Get link
- X
- Other Apps
Armstrong Number Check in C
✅ Armstrong Number Check in C
#include<stdio.h>
int main( )
{
int num, remainder, temp, sum = 0;
printf("Enter the number:\n");
scanf("%d", &num);
temp = num;
while (num > 0)
{
remainder = num % 10;
sum = sum + (remainder * remainder * remainder);
num = num / 10;
}
if (temp == sum)
{
printf("%d is armstrong:\n", temp);
}
else
{
printf("%d is not armstrong:\n", temp);
}
}
๐ Explanation:
An Armstrong number (also known as a narcissistic number) is a number that is equal to the sum of the cubes of its digits.
- The user is prompted to enter an integer.
- Each digit is separated using modulus (
%) and divided out using division (/). - The cube of each digit is added to a
sum. - Finally, if
sum == original number, it is an Armstrong number.
Example: 153 → 1³ + 5³ + 3³ = 1 + 125 + 27 = 153 ✔️
๐ป Sample Output:
Enter the number: 153 153 is armstrong:
๐ Keywords:
Armstrong number in C, C Armstrong program, digit cube sum, Armstrong logic in C, C programming for beginners, Armstrong check using while loop, C interview coding question, temp and remainder in C
๐ Hashtags:
#CProgramming #ArmstrongNumber #BeginnerCPrograms #DigitExtraction #WhileLoopInC #CCodeForInterview #TechBlog #CodeWithMe
Popular Posts
C++ Program for Hybrid Inheritance (All Types Together)
- Get link
- X
- Other Apps
C++ Program for Function Overloading Example
- Get link
- X
- Other Apps
Comments
Post a Comment