Basic Programs

If Else based Programs

Loop Based Programs

Array Based Programs

String Programs

Function Programs

Pointers Programs

Structure & File Handling Programs

Data Structure Programs

Loop based Programs

C Program to check given number is armstrong or not

 #include <stdio.h>
#include <conio.h>
void main()
{
    int n=0, noofdigits=0, n1=0, rem=0, i=0, k=1, sum=0;
    printf("enter the no");
    scanf("%d",&n);
    
    n1=n;   // because after the loop the value of n lost to zero
     while(n>0)
       {
            noofdigits++;
            n=n/10;
        }
     n=n1;   // to regain the original value because after the loop value becomes zero.
      while(n>0)
        {
            rem=n%10;
            k=1;
            for(i=0; i<noofdigits; i++)
              {
                  k=k*rem;
               } 
            sum=sum+k;
            n=n/10;
        }
     
     if(sum==n1)
       printf("the number is armstrong");
     else
       printf("the number is not armstrong");
}

Output of the above program is as following.

Video/ C Introduction

Watch video in full size
Wordpress Social Share Plugin powered by Ultimatelysocial