Introduction to C Language Programming Problem-No.13

Title: Print out all the "narcissus numbers". The so-called "narcissus numbers" refers to a three-digit number whose cubic sum of digits
is equal to the number itself. For example: 153 is a "narcissus number", because 153 = 1 cube + 5 cube + 3 cube.
1. Program analysis: use for loop to control 100-999 numbers, each number is decomposed into singles, tens and hundreds.
2. Program source code:

#include <stdio.h>
#include "math.h"
main()
{
    int i, j, k, n;
    printf("'water flower'number is:");
    for (n = 100; n < 1000; n++)
    {
        i = n / 100;     /*分解出百位*/
        j = n / 10 % 10; /*分解出十位*/
        k = n % 10;      /*分解出个位*/
        if (i * 100 + j * 10 + k == i * i * i + j * j * j + k * k * k)
        {
            printf("%-5d", n);
        }
    }
    printf("\n");
}

Published 678 original articles · praised 343 · 70,000 views

Guess you like

Origin blog.csdn.net/weixin_43627118/article/details/105462587