Dr. A.P.J. Abdul Kalam Technical University, Lucknow
KCS101 / KCS201 Programming for Problem Solving - Using C Language
Lab Exercises
19. Write a program to print Armstrong numbers from 1 to 1000.
/*
File: Prgrm19.c
Author: Aditya Saini
Date: Sept 30, 2019
Description: Program to print Armstrong numbers from 1 to 1000.
*/
#include <stdio.h>
#include <math.h>
#include <math.h>
int Armstrong (int);
int main (void)
int main (void)
{
int number;
//Finding the Armstrong numbers and output the result.
printf ("Armstrong numbers from 1 to 1000: ");
//Finding the Armstrong numbers and output the result.
printf ("Armstrong numbers from 1 to 1000: ");
for (number = 1; number <= 1000; number++)
{
if (Armstrong (number))
printf ("%d ", number);
}
{
if (Armstrong (number))
printf ("%d ", number);
}
};
int Armstrong (int number)
{
int number_of_digits;
int ArmStrong;
int temp;
//Finding number of digits;
temp = number;
number_of_digits = 0;
while (temp != 0)
{
temp = temp / 10;
number_of_digits++;
}
//Finding if the number is Armstrong or not
ArmStrong = 0;
temp = number;
while (temp != 0)
{
ArmStrong = ArmStrong + pow (temp % 10, number_of_digits);
temp = temp / 10;
}
if (number == ArmStrong)
return 1;
else
return 0;
};
int Armstrong (int number)
{
int number_of_digits;
int ArmStrong;
int temp;
//Finding number of digits;
temp = number;
number_of_digits = 0;
while (temp != 0)
{
temp = temp / 10;
number_of_digits++;
}
//Finding if the number is Armstrong or not
ArmStrong = 0;
temp = number;
while (temp != 0)
{
ArmStrong = ArmStrong + pow (temp % 10, number_of_digits);
temp = temp / 10;
}
if (number == ArmStrong)
return 1;
else
return 0;
};
Output
Armstrong numbers from 1 to 1000: 1 2 3 4 5 6 7 8 9 10 153 370 371 407
very nice put up, i definitely love this web site, carry on it visual identity
ReplyDeleteThanks for the appreciation.
ReplyDeleteThank you for having the time to discuss this topic. I truly appreciate it. I’ll stick a link of this entry in my site. brand
ReplyDeleteThank you Albert Jhon. It is really helpful.
DeleteI have beeing scouring the google for this information and simply needed to thank you for the post. BTW, simply off topic, how can I get a duplicate of this theme? – Thanks ipad mockups
ReplyDeleteThank you James Jones for the appreciation. You can get this theme from
Deletehttps://pixel-template.blogspot.com/
I like this website very much so much fantastic information. macbook sketch
ReplyDeleteThank you Mark Weins.
DeleteHey there! Wonderful stuff, please do tell us when you post again something similar! android mockups
ReplyDeleteThank you sdexter. Soon you will see more posts.
DeleteAccording to my point of view , learning C programs is not easy , indeed , students have to face a lot of trouble in writing their language assignments but if you are worried you can select to Dissertation Writing Services
ReplyDelete