Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C Program to Display Armstrong Number Between Two Intervals #55

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
52 changes: 52 additions & 0 deletions Armstrong number.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include <stdio.h>
#include<math.h>

int check_armstrong(int);

int main()
{
int num_1,num_2;
printf("Enter first number : ");
scanf("%d",&num_1);
printf("Enter second number : ");
scanf("%d",&num_2);
printf("\nThe armstrong numbers in the interval %d to %d are as follows: \n",num_1,num_2);
for(int i=num_1;i<=num_2;i++)
{
if(check_armstrong(i)==1)
{ //checking whether the num is armstrong or
printf("%d\n",i); //if it is then printing its value.
}
}

}

int check_armstrong(int p)
{
int temp,flag;
temp=p;
flag=p;
int rem=0,total=0,count=0;
while(p) //this while loop is for counting the total number of digits in the number
{
rem=p%10;
p=p/10;
count++;
}
rem=0;
while(temp) //this while loop is for calculating the sum of digits raised to the total
{ //count of digits in the number as power
rem=temp%10;
total+=pow(rem,count);
temp=temp/10;
}
if(total==flag)
{
return 1;
}
else
{
return 0;
}
return 0;
}