Basic

Switch Case

Goto

Operators

if Statement

Nested if

While Loop

For Loop

Array

Patterns

Excersises


C Program to Check Whether Armstrong Number or Not


Armstrong number is a number which is equal to sum of cubes of its digits.For example, we take number 153.First spilt number into digits.

  • 1 => 1 * 1 * 1 =   1
  • 5 => 5 * 5 * 5 = 125
  • 3 => 3 * 3 * 3 =  27
  • Sum if cubes is 153. which is equal to given value 153. so 153 is an Armstrong Number.

Example : pgm.c

#include<stdio.h>
int main(){
  int n,a,b,c,d,r;
  printf("\nEnter 3 Digit No : ");
  scanf("%d",&n);
  a=n%10;  // Third Digit
  b=n/10;
  c=b%10;  // Second Digit
  d=b/10;  // First Digit
  r=(d*d*d)+(c*c*c)+(a*a*a);
  if(r==n){
    printf("\n%d is an Armstrong Number ",n);
  }else{
    printf("\n%d is Not an Armstrong Number ",n);
  }
  return 0;
}

Output:

Enter 3 Digit No : 153
153 is an Armstrong Number