Program in c to find whether number is a Armstrong or strong number?
Answers
Answered by
0
Hi there!
Here's the answer :
°•°•°•°•°•<><><<>>><><>°•°•°•°•°•
'Armstrong number' is a number that is equal to the sum of cubes of its digits.
For example 0, 1, 153, 370, 371 and 407 are the Armstrong numbers.
Eg: 371 = (3*3*3)+(7*7*7)+(1*1*1)
°•°•°•°•°•<><><<>>><><>°•°•°•°•°•
/* C- program to check whether the given No. is an Armstrong Number */
#include<stdio.h>
#include<math.h>
int main()
{
…int n,r,sum=0,temp;
…print( "\n enter the number :" );
…scanf( "%d" ,&n);
…temp=n;
…while (n>0)
……{
………r=n%10;
………sum=sum+pow(r,3);
………n=n/10;
……}
…if (temp==sum)
………printf( "\n It is armstrong number " );
…else
………printf("\n It is not armstrong number" );
…return 0;
}
°•°•°•°•°•<><><<>>><><>°•°•°•°•°•
••• pow(x,n) function is included in 'math.h'm header file. so it must be included.
•• or use (r*r*r) instead of pow(r,3)
°•°•°•°•°•<><><<>>><><>°•°•°•°•°•
:)
Hope it helps
Here's the answer :
°•°•°•°•°•<><><<>>><><>°•°•°•°•°•
'Armstrong number' is a number that is equal to the sum of cubes of its digits.
For example 0, 1, 153, 370, 371 and 407 are the Armstrong numbers.
Eg: 371 = (3*3*3)+(7*7*7)+(1*1*1)
°•°•°•°•°•<><><<>>><><>°•°•°•°•°•
/* C- program to check whether the given No. is an Armstrong Number */
#include<stdio.h>
#include<math.h>
int main()
{
…int n,r,sum=0,temp;
…print( "\n enter the number :" );
…scanf( "%d" ,&n);
…temp=n;
…while (n>0)
……{
………r=n%10;
………sum=sum+pow(r,3);
………n=n/10;
……}
…if (temp==sum)
………printf( "\n It is armstrong number " );
…else
………printf("\n It is not armstrong number" );
…return 0;
}
°•°•°•°•°•<><><<>>><><>°•°•°•°•°•
••• pow(x,n) function is included in 'math.h'm header file. so it must be included.
•• or use (r*r*r) instead of pow(r,3)
°•°•°•°•°•<><><<>>><><>°•°•°•°•°•
:)
Hope it helps
Similar questions