Dr. A.P.J. Abdul Kalam Technical University, Lucknow
KCS151 / KCS251 Programming for Problem Solving - Using C Language
Lab Exercises
12. Write a program to print out all the Armstrong numbers between 100 and 500.
/*
File: Prgrm12.c
Author: Aditya Saini
Date: Jan 16, 2021
Description: Program to print all the Armstrong numbers between 100 and 500.
*/
#include <stdio.h>
#include <math.h>
int main (void)
{
int i, j;
int ArmStrong;
int temp;
printf ("Armstrong numbers between 100 and 500: ");
for (i = 100; i <= 500; i++)
{
//Checking if i is an Armstrong number or not
ArmStrong = 0;
for (temp = i; temp != 0; temp /= 10)
ArmStrong = ArmStrong + pow (temp %10, 3);
if (i == ArmStrong)
printf ("%d ", i);
}
};
Output
Armstrong numbers from 100 to 500: 153 370 371 407
No comments:
Post a Comment
Please do not post spam links.