Armstrong Number In C

What is Armstrong Number ?

An Armstrong number is a number that is the sum of its own digits each raised to the power of the number of digits.


EX :

1. 153 is an Armstrong number.

 --> 1³ + 5³ + 3³ = 153


2. 371 is an Armstrong number 

--> 3³ + 7³ + 1³ = 371


3. 1634 is an Armstrong number

--> 1⁴ + 6⁴ + 3⁴ + 4⁴ = 1634


//Code for Armstrong Number In C:


#include<stdio.h>

#include<math.h>

int main()

{

 int n,no,c=0,s=0,d;

 printf("enter no\n");

 scanf("%d", &n);

 no=n;

 while(n>0){

  n=n/10;

  c++;

 }

 n=no;

 while(n>0)

 {

  d=n%10;

  s=s+pow(d,c);

  n=n/10;

 }

 if(no==s)

 {

  printf("Armstrong No");

 }

 else

 {

  printf("Not Armstrong");

 }

}


Comments

Popular posts from this blog

What Is Trading? Beginners Guide.

Oasis Infobyte Virtual Internship

Safari Cookies Not Working with Express.js App