Home >Backend Development >C#.Net Tutorial >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 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
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:
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!