#include <stdio.h>
#include <math.h>
int main(void){
int n;
printf("Enter a three digit numbrer : ");
scanf("%d",&n);
int num=n;
int sum=0;
while(n != 0){
sum = sum + pow((n%10),3);
n=n/10;
}
if(num==sum){
printf(" %d is an Armstrong number ",num);
}else{
printf(" %d is NOT an Armstrong number ",num);
}
#include <stdio.h>
#include <math.h>
int main(void){
int n,num,sum,i;
for(i=1;i<1000;i++){
n=i;
sum=0; // At starting of loop it is intialized to 0
while(n != 0){
sum = sum + pow((n%10),3);
n=n/10;
} // end of while loop
if(i ==sum){
printf(" %d is an Armstrong number \n",i);
}
}// end of for loop
return 0;
}
Output
1 is an Armstrong number
153 is an Armstrong number
370 is an Armstrong number
371 is an Armstrong number
407 is an Armstrong number
#include <stdio.h>
#include <math.h>
int main(void){
int n,num,sum,no_digits=0,j=0;
printf("Enter a number : ");
scanf("%d",&num);
n=num;
sum=0; // At starting of loop it is intialized to 0
for(j=num;j != 0;++no_digits){
j=j/10;
}
printf("\n No of digits : %d \n",no_digits);
while(n != 0){
sum = sum + pow((n%10),no_digits);
n=n/10;
} // end of while loop
if(num ==sum){
printf(" %d is an Armstrong number \n",num);
}else{
printf(" %d is NOT an Armstrong number \n",num);
}
return 0;
}
List all armstrong numbers upto 10000 ( or n ) . As we are using one for loop , upper limit can be increased.
#include <stdio.h>
#include <math.h>
int main(void){
int n,num=0,sum,no_digits=0,j=0;
for(num=10;num<10000;num++){ // increse the upper limit.
n=num;
sum=0; // At starting of loop it is intialized to 0
no_digits=0;
for(j=num;j != 0;++no_digits){
j=j/10;
}
//printf("\n No of digits : %d \n",no_digits);
while(n != 0){
sum = sum + pow((n%10),no_digits);
n=n/10;
} // end of while loop
if(num ==sum){
printf("\n %d is an Armstrong number \n",num);
}
} // end of for loop with i
return 0;
}
Output is here
153 is an Armstrong number
370 is an Armstrong number
371 is an Armstrong number
407 is an Armstrong number
1634 is an Armstrong number
8208 is an Armstrong number
9474 is an Armstrong number
30-04-2022 | |
#include <stdio.h> #include <conio.h> int main() { int grade=74; if (grade>74) { printf(“Passed”); } else if (grade<75 && grade>69) { printf(“Conditional Pass”); } else (grade<70) { printf(“Failed!”); } getch(); return 0; } |