C programming - Armstrong number

Posted on:
tags: , ,
C programming - Armstrong number
#include<stdio.h>
#include<conio.h>
void main(){
int a,t,y,q;// taking variables.
clrscr();//to clear the screen  .
printf("\t\t\t***This is Armstrong Program***\n\n\n\n");
printf("\tEnter a dirsire number:");
scanf("%d",&a); //taking the number as input.
t=0;
t=a;//now the value of variable t and a are same.
q=0; y=0;
while(a>0){   //from here the main work start for calculating the armstrong number.
y=a%10;
q=q+(y*y*y);
a=a/10;
}
if(t==q)  //comparing the value of the variables t and q
printf("\n\nYupp !! This is a ARMSTRONG NUMBERR :)");
else
printf("\n\nSoRRy!! This is not a ARMSTRONG NUMBER :(");
getch();
}

No comments:

Post a Comment

< >