Untitled

mail@pastecode.io avatar
unknown
plain_text
16 days ago
694 B
6
Indexable
Never
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main()
{
    int n, m, k1, k2, sum;
    printf("imput a number n: ");
    scanf("%d", &n);
    printf("imput a number m: ");
    scanf("%d", &m);
    k1 = log10(n);
    k2 = log10(m);

    int k3;

    for(int i = k1; i <= k2; i++){
        for(int j = pow(10, i); j < pow(10, i+1); j++){
            int k = j;
            sum = 0;
            while(k > 0){
                int digit = k%10;
                sum += pow(digit, i+1);
                k /= 10;
            }
            if(sum == j && j >= n && j <= m){
                printf("%d ", j);
            }
        }
    }

    return 0;
}
Leave a Comment