Friday, June 20, 2014

C PROGRAM TO FIND GIVEN NUMBER IS ARMSTRONG OR NOT

#include<stdio.h>
#include<conio.h>
void main()
{
int c,n,d,on,s=0;
 clrscr();
 printf("\nEnter Three Digit Number ");
 scanf("%d",&n);  //567
 on=n;
 while(n!=0)
 {
 d=n%10; //153%10 d=3   15%10 d=5      1%10 d=1
 c=d*d*d; //3*3*3 c=27  //5*5*5 c=125  1*1*1 c=1
 s=s+c;   //0+27 s=27   27+125 s=152   152+1 s=153
 n=n/10; //153/10 n=15   15/10 n=1     1/10  n=0
 }
printf("\nSum of Cube of Digit = %d",s);

 if(s==on)

 {
   printf("\nArmstrong");
 }
 else
 {
  printf("\nNot Armstrong");
 }
getch();
}

No comments:

Post a Comment

JAC Board Computer || IIT 2025 || Introductory Information Technology || Class 10 || Practical Examination 2025

Marks Division HOE 30 Marks IT Application Report File 20 Marks Viva - Voce 10 Marks 1) Write an HTML code to generate a web p...