Pages

Custom Search
Showing posts with label armstrong range. Show all posts
Showing posts with label armstrong range. Show all posts

Tuesday, October 11, 2011

Program to generate armstrong numbers in a given range.


//Generate armstrong number in a given range.
Leave space between the upper and the lower range.

#include<stdio.h>
#include<conio.h>

void range_arm();                    //Function declaration

int main()
{
        int sn, en;
        printf("\nEnter range of numbers: ");
        scanf("%d %d", &sn, &en);
        range_arm(sn, en);                   //Function call
        getch();
}
void range_arm(int sn, int en)
{
        int t, cube, scube=0, d, i, c=0;

        for(i=sn;i<=en;i++)
        {
                scube=0;
                t=i;
                while(t>0)
                {
                        d=t%10;
                        cube=d*d*d;
                        scube=scube+cube;
                        t=t/10;
                }
                 if(scube==i)
                {
                        printf("%d\t", i);
                        c++;
                }
        }
        if(c==0)
        {
                printf("\nNo armstrong numbers in the given range");
        }
        printf("\n");
}

SAMPLE OUTPUT:


Custom Search