Home >Backend Development >C#.Net Tutorial >How to output the number of roses in C language? (code example)

How to output the number of roses in C language? (code example)

青灯夜游
青灯夜游Original
2019-03-06 15:24:3066067browse

The rose number, also known as the "four-leaf rose number", refers to the number where the sum of the fourth powers of the numbers on each of the four-digit digits is equal to itself. The rose code in C language is [int main()int i, j, t;for(i=1000; i

How to output the number of roses in C language? (code example)

The rose number, also known as the "four-leaf rose number", refers to a number in which the sum of the fourth powers of the numbers on each four-digit number is equal to itself.

For example: 1634 is a rose number

1*1*1*1=1
6*6*6*6=1296
3*3*3*3=81
4*4*4*4=256
1+1296+81+256=1634

There are three rose numbers, namely: 1634, 8208, 9474.

The following is a code example to see how C language outputs the rose number.

Code example:

#include<stdio.h>
int main()
{
    int i, j, t;
    for(i=1000; i<10000; i++)
    {
        t = 0;
        for(j=i; j; j/=10)
            t += (j%10)*(j%10)*(j%10)*(j%10);
        if(t == i)
            printf("%d\n", i);
    }
}

Output:

How to output the number of roses in C language? (code example)

Recommended related C language video tutorial: "C Language Tutorial

The above is the entire content of this article, I hope it can be helpful to everyone’s study. For more exciting content, you can pay attention to the relevant tutorial columns of the PHP Chinese website! ! !

The above is the detailed content of How to output the number of roses in C language? (code example). For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn