Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <conio.h>
- #include <math.h>
- #include <stdlib.h>
- void main()
- {
- long int i, up, down, num, bnum, count, sum, digit, expo, flag = 0;
- system("cls");
- printf("This is a simple program to print Aarmstrong Number.\n\n");
- printf("Enter The upper range : ");
- scanf("%ld",&up);
- printf("Enter The lower range : ");
- scanf("%ld", &down);
- system("cls");
- printf("Armstrong-Numbers in ascending order.\n\n");
- for (i = down; i <= up; i++)
- {
- num = i;
- bnum = i;
- count = 1;
- while (bnum / 10 != 0)
- {
- bnum = bnum / 10;
- count++;
- }
- sum = 0;
- while (num > 0)
- {
- digit = num % 10;
- expo = pow(digit,count);
- sum = sum + expo;
- num = num / 10;
- }
- if (sum == i)
- {
- printf("%ld\n", i);
- flag++;
- }
- }
- if (flag == 0)
- {
- system("cls");
- printf("There is no Armstrong-Number in this range.");
- }
- else
- {
- printf("\nThere is total '%ld' Armstrong-Number in this range.", flag);
- }
- printf("\n\n\n");
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement