Saturday, August 20, 2011

Program to check wheather a given number is armstrong or not

//Program to check wheather a given number is armstrong or not.
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
 int n,temp=0,a,m,c;
 char ch;
 clrscr();
 printf("Program to wheather a given number is armstrong or not");
 while(1)
 {
 printf("\nPlease enter a 3 digit number");
 scanf("%d",&n);
 a=n;
 c=0;
 while(n>0)
 {
   m=n%10;
   n=n/10;
   temp=temp+pow(m,3);
    c=c+1;
 }
 if(c!=3)
 {
  printf("\n You have entered a wrong number! Please enter a coorect information");
  continue;
 }
 if(temp==a)
 {
  printf("\n The number %d is armstrong",a);
 }
 else
 {
  printf("\n The number %d is not armstrong",a);
 }
 printf("\nWheather you want to check another number if yes then press \"Y\" and if no then press \"N\": ");
 ch=getche();
 if(ch=='Y'||ch=='y')
  continue;
 else
  break;
}
getch();
}

Previous Next Home
0 Comments
Comments

Leave a Comment

:)) ;)) ;;) :D ;) :p :(( :) :( :X =(( :-o :-/ :-* :| 8-} :)] ~x( :-t b-( :-L x( =))

Twitter Delicious Facebook Favorites More