top of page
Wave
Cactus%20Plant_edited.jpg

ARMSTRONG  NUMBER

#include<stdio.h>
#include<math.h>
int main()
{
    int n,z,r,s,i;
    printf("Enter the number: ");
    scanf("%d",&n);
    z=n;
    i=0;
    while(z!=0)
    {
        i++;
        z=z/10;
    }
    z=n;
    s=0;
    while(z!=0)    
    {
        r=z%10;
        s=s+pow(r,i);
        z=z/10;   
    }
    if(s==n)
        printf("\nThe enter number %d is an armstrong number\n",n);
    else
        printf("\nThe enter number %d is not an armstrong number\n",n);
    return 1;
}

Cactus%20Plant_edited.jpg

ARMSTRONG  NUMBER RANGE

#include<stdio.h>
#include<math.h>
int main()
{
    int n,z,r,s,i,a,b;
    printf("Enter the lower limit of the range: ");
    scanf("%d",&a);
    printf("\nEnter the upper limit of the range: ");
    scanf("%d",&b);
    printf("\nArmstrong numbers are: \n\n");
    for(n=a;n<=b;n++)
    {
        z=n;
        i=0;
        while(z!=0)
        {
            i++;
            z=z/10;
        }
        z=n;
        s=0;
        while(z!=0)    
        {
            r=z%10;
            s=s+pow(r,i);
            z=z/10;
        }
        if(s==n)
        printf("%d ",n);
    }
    return 1;
}

Subscribe Form

Thanks for submitting!

  • Facebook
  • YouTube
  • Instagram
  • Twitter

©2020 by Abhisek Midya ( A18 )

bottom of page