C LAB‎ > ‎(Sem1) Introduction to C‎ > ‎

WAP to check if number is an Angstrom number or not.

posted Nov 6, 2010, 1:20 AM by Neil Mathew   [ updated Nov 6, 2010, 1:23 AM ]

SOURCE CODE:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <stdio.h>
 
 main()
{
 
int num;    //number inputted by user
int n;     //temporary storage
int A=0; //stores the sum of the cube of the digits
int digit; //stores the individual digits
 
printf(" Enter the number to check if it's Angstrom or not: ");
scanf("%d", &num);
 
n=num;
 
do
{
digit=n%10;
A+=(digit*digit*digit);
n=n/10;
}
while(n>0);
 
if(A==num)
{
printf("\n The number is an Angstrom number. ");
}
else
{
printf("\n The number is not an Angstrom number. ");
}
 
}

OUTPUT:

 Enter the number to check if it's Angstrom or not: 121

 The number is not an Angstrom number. 
 Enter the number to check if it's Angstrom or not: 153

 The number is an Angstrom number. 


Comments