C Program to Print Armstrong Number Between n and m using For Loop
Write a Program to Print Armstrong Number Between n and m using For Loop
// C Program to Print Armstrong Number Between n and m using For Loop #include <stdio.h> #include <stdbool.h> bool isArmstrong(int n) { int temp = n, ans = 0; for(; n != 0; ) { int remainder = n % 10; ans = ans + (remainder * remainder * remainder); n = n / 10; } if(temp != ans) { return false; } return true; } int main() { int n,m; printf("Enter n :--> "); scanf("%d", &n); printf("Enter m :--> "); scanf("%d", &m); printf("Armstrong Numbers Between %d to %d :--> ", n, m); int i = n ,j = m; for(; i < j; i++ ) { if(isArmstrong(i)) { printf("%d ",i); } } return 0; }
Output:
Enter n :--> 300
Enter m :--> 400
Armstrong numbers between 300 to 400 :--> 370 371