Last active
February 19, 2023 19:06
-
-
Save suryansh011/b99552fa707e9331aa983b3c411d048f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* | |
* Title: Finding the Armstrong Number | |
* By: Suryansh Singh Shishodia | |
* Github: https://github.com/elekktron | |
* | |
*/ | |
#include <stdio.h> | |
#include <math.h> | |
int main() { | |
int num,temp,digit,armstrong,x,y=0; | |
printf("Enter the number to find the Armstrong Numbers upto: "); | |
scanf("%d",&num); | |
printf("The following numbers upto %d are the Armstrong numbers:\n",num); | |
temp = num; | |
if (num==0) | |
x = 1; | |
//Finding the armstrong number | |
while(y != num){ | |
armstrong = 0; | |
x=0; | |
y++; | |
temp = y; | |
//Calculating number of digits | |
while (temp!=0){ | |
temp = temp/10; | |
x++; | |
} | |
temp = y; | |
while(temp != 0){ | |
digit = temp%10; | |
armstrong = armstrong + pow(digit,x); | |
temp = temp/10; | |
} | |
if(y == armstrong) { | |
printf("%d\n",armstrong); | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yo I want to connect with you... Do you by any chance go by the name
Hercules
earlier? Also Pokemon perhaps?? I want to tell you something that you might wanna know !