c program to check whether given number is armstrong number or not using for loop

#include<stdio.h>
#include<conio.h>
void main()
{
  int num, n, rem;
  int cube=0, sum=0;
  printf("n Enter a number: ");
  scanf("%d",&num);
  n = num;
  for(;n>0;n=n/10)
  {
    rem = n%10;
    cube = rem*rem*rem;
    sum = sum + cube;
  }
  if(num==sum)
  {
    printf("n %d is armstrong number",num);
  }
  else
  {
    printf("n %d not armstrong number",num);
  }
  getch();
}

Ouput:

Enter a number: 407
407 is armstrong number

 

Leave a Reply

error: Content is protected !!
%d bloggers like this: