C Program – Armstrong numbers between given numbers

By | 2017-08-28T20:52:56+00:00 August 28th, 2017|c-program|0 Comments

C Program  to print Armstrong numbers between the given two numbers.

Armstrong numbers :


#include<stdio.h> 
int main(void) 
{ 
    int x,y,n,num,cube,d,sum;
    printf("Enter x and y values to print Armstrong numbers: \n"); 
    scanf("%d%d",&x,&y); 
    printf("Armstrong numbers are :\n"); 
 
    for(num=x; num<=y; num++)     
    { 
        n=num; 
        sum=0; 
        while(n>0)     
        { 
            d=n%10; 
            n/=10; 
            cube=d*d*d; 
            sum=sum+cube; 
        } 
        if(num==sum)     
            printf("%d\n",num); 
    } 
    return 0; 
}

[box type=”success” align=”alignleft” class=”” width=”100%”]
Enter x and y values to print Armstrong numbers:
50
1500
Armstrong numbers are :
153
370
371
407

[/box]

Happy Learning 🙂

About the Author:

Hi Folks, you have reach this so far, that shows you like what you are learning. Then why don't you support us to improve for bettor tutorials by leaving your valuable comments and why not you keep in touch with us for latest updates on your favorite blog @ facebook , twitter , Or Google+ ,

Leave A Comment