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
C Program to Check Armstrong Number (Any Digits)
✅ C Program to Check Armstrong Number (Any Digits)
#include <stdio.h>
int main()
{
int num, temp, remainder, sum = 0, n = 0;
printf("Enter the number:\n");
scanf("%d", &num);
temp = num;
// count digits
int digits = num;
while(digits != 0) {
digits /= 10;
n++;
}
temp = num;
while(num > 0) {
remainder = num % 10;
// calculate remainder^n manually
int power = 1;
for(int i = 0; i < n; i++) {
power *= remainder;
}
sum += power;
num /= 10;
}
if(temp == sum)
printf("%d is an Armstrong number\n", temp);
else
printf("%d is not an Armstrong number\n", temp);
return 0;
}
๐ Explanation:
This program checks if a number is an Armstrong number without using the pow() function from math.h.
Instead, it calculates the power of each digit manually with a for loop.
- First count the total digits of the number.
- Extract each digit using modulus (
%). - Compute
digit^nby multiplying in a loop. - Add all powered digits.
- Compare with the original number → if equal, it’s an Armstrong number.
๐งพ Sample Output:
Enter the number: 9474 9474 is an Armstrong number Enter the number: 123 123 is not an Armstrong number
๐ Keywords:
Armstrong number without pow, C program Armstrong check manually, Armstrong number code with loop, interview C programs, Armstrong logic in C
๐ Hashtags:
#CProgramming #ArmstrongNumber #WithoutPow #CodingForBeginners #InterviewPrep
๐ Search Description:
This C program checks whether a number is an Armstrong number without using pow(). Instead, digit powers are calculated manually with a loop.
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