Home Uncategorized Armstrong Number or Not in C

Armstrong Number or Not in C

SHARE

Here we written code to check whether the given number is Armstrong or not.

For improvement of your coding skills we give some tasks along this. If you solve this tasks and send to our email
(onlineexamshubteam@gmail.com) with your details. we will display your details(like Name, City, college, photo) in our site.

Task: Write a C program to generate Armstrong numbers from ‘m’ to ‘n’ natural numbers. For example user entered 250 & 500 then output will be : 370 371 407

Write a C Program to Find whether the given number Armstrong or not.

#include<stdio.h>
#include<math.h>
int digi(long int);
int main()
{
long int n,s=0;
int a,t,d; //’n’ for user defined integer,’s’ for store resultant ,’t’ for temporary, ‘a’ for calculations.
printf(“Enter a value : “);
scanf(“%ld”,&n); // Read the number.
t=n;
d=digi(n); //Returns No.of digits in given integer.
while(t>0) //If entered number is greater than zero then only loop will execute
{
a=t%10; //pick last digit from temporary variable.
s=s+pow(a,d); //adding cube ‘a’ to ‘s’.
t=t/10; //removing last digit from ‘t’
}
if(n==s)
printf(“Given number is Armstrong\n”);
else
printf(“Given number is not Armstrong\n”);
return 0;
}
int digi(long int t)
{
int dig=0;
while(t>0)
{
dig++;
t=t/10;
}
return dig;
}

Output:
i) Enter a value : 153
Given number is Armstrong.

ii) Enter a value : 516
Given number is not Armstrong.

Back to the programs.

Task Achievers

Till now no one is answered.