C Programming : To check number is Armstrong or not.

Posted on:
tags: , ,

/* This is a 'C' program.
This program will check that given number is Armstrong or not.*/
#include<stdio.h>
#include<conio.h> //header files
void main()
{
int a,n,t,sum;//variables
clrscr();
printf("\n Enter a number [natural number]:");
scanf("%d",&n);
t=n;
sum=0;//for additive identity
while(n>0)//loop start. This loop calculate the armstrong of given number.
{
a=n%10;
sum=sum+a*a*a;
n=n/10;
} //loop end
if(t==sum)//This statement check the armstrong of given number
printf("\n\n The given number is Armstrong!!!");
else
printf("\n\n The given number is Not Armstrong!!!");
getch();
}//program end

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();
}
◘ >