Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

added armstrong number checker in c #232

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions C/armstrongNumber.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include <stdio.h>
#include <math.h>

int isArmstrong(int number) {
int originalNum, remainder, result = 0, n = 0;

originalNum = number;

while (originalNum != 0) {
originalNum /= 10;
++n;
}

originalNum = number;

while (originalNum != 0) {
remainder = originalNum % 10;
result += pow(remainder, n);
originalNum /= 10;
}

return (result == number);
}

int main() {
int number;

printf("Enter an integer: ");
scanf("%d", &number);

if (isArmstrong(number))
printf("%d is an Armstrong number.\n", number);
else
printf("%d is not an Armstrong number.\n", number);

return 0;
}