Example (8.9) Printing Daffodils (1041), 8.91041

Source: Internet
Author: User

Example (8.9) Printing Daffodils (1041), 8.91041

Example (8.9) print Daffodils (1041)  
Source Computing overview 05
Description
Print out all the "Daffodils". The so-called "Daffodils" refers to a three-digit number. The cubes of the numbers are equal to the numbers themselves. For example, 153 is the number of daffodils, because 153 = 1x1x1 + 5x5 + 3x3.
About Input
No input.
About output
Output the number of all daffodils. Each row outputs a number of daffodils.
Example Input
None.
Example output
Don't tell everyone the answer :-)


12345678910111213141516171819202122232425262728
#include <stdio.h>int main(){int cube[10] = {0, 1, 8, 27, 64, 125, 216, 343, 512, 729};int a, b, c;for(a = 1; a < 10; ++a){for(b = 0; b < 10; ++b){int x = 100*a + 10*b - cube[a] - cube[b];if(x < 0){break;}for(c = 0; c < 10; ++c){if(cube[c] - c == x){printf("%d%d%d\n", a, b, c);}}}}return 0;}


Print the number of daffodils. Incorrect answer

C = I % 100;
If I = 365 then c = 65

Write a function to print the daffodils

# Include <stdio. h>
Void main ()
{
Int flower (int a, int B, int c );
Int a, B, c, d, e;
For (a = 1; a <10; a ++)
For (B = 0; B <10; B ++)
For (c = 0; c <10; c ++)
{
D = flower (a, B, c );
If (d = 1)
{
E = 100 * a + B * 10 + c;
Printf ("% d", e );
}
}
}
Int flower (int a, int B, int c)
{
Int I, j, k;
I = a * a + B * B + c * c; // The problem here should be the cubic of each number, that is, the cubic power, not the quadratic side.
J = 100 * a + 10 * B + c;
If (I = j) k = 1;
Else k = 0;
Return k;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.