Exercises 2-1 Number of daffodils
All output daffodils number 100 to 999. If the 3-digit satisfy ABC ABC = A ^ 3 + B ^ 3 + C ^ 3, which is called the number of daffodils. E.g. 153 + 5 = 1 ^ 3 ^ 3 ^ 3 + 3, the number is 153 daffodils.
#include<stdio.h> int main(){ for(int i = 1;i<=9;i++){ for(int j = 0 ;j <=9;j++){ for(int k = 0;k <= 9;k++){ int r = i * 100 + j * 10 + k; if(r == i*i*i + j*j*j + k*k*k) printf("%d\n",r); } } } return 0; }
Exercise 2-2 Han soldiers
According to legend, Han intellect, and never directly counting the number of its own troops, as long as soldiers have to make three in a row, five in a row, seven in a row to transform formation, but every time he swept Only one team of Pai Mei to know the total number. Input data comprises a plurality of sets, each set of data contains three non-negative integers a, b, c, represents the number of each row of tail formation (a <3, b 5, c <<7), the minimum value of the total number of output (or report no solution). The total number of not less than 10 are known, no more than 100. Input file to the end.
Sample input:
2. 6. 1
2. 1. 3
Sample Output:
Case. 1: 41 is
Case 2: No answer
Exercise 2-3 inverted triangle
Enter a positive integer n≤20, inverted triangle output a n-layer. For example, n = 5 the following output:
#########
#######
#####
###
#
#include<stdio.h> int main(){ int n; scanf("%d",&n); for(int i =0;i < n;i++){ for(int j = 0;j < i;j++) printf(" "); for(int k = 0;k < 2 *(n-i) -1;k++) printf("#"); printf("\n"); } return 0; }
Problem 2-4 and subsequence
Enter two positive integers n <m <106, outputs , to five decimal places. Comprising a plurality of sets of input data end tag for n = m = 0. NOTE: This problem has pitfalls.
Sample input:
2. 4
65536 655360
0 0
Sample Output:
Case. 1: .42361
Case 2: 0.00001
Decimal fractions of Problem 2-5
Input A positive integer, b, c, the output of a / b, in decimal form, c 'after the decimal point. a, b≤10 ^ 6, c≤100. Comprising a plurality of sets of input data end tag for a = b = c = 0.
Sample input:
. 1. 6. 4
0 0 0
Sample Output:
Case. 1: 0.1667
Exercises 2-6 arrangement
With 1,2,3, ..., 9 consisting of 3 three-digit abc, def and GHI, each number is used just once, it requires abc: def: ghi = 1: 2: 3. Output "abc def ghi" according to the format of all solutions, a solution of each row. Tip: do not have too much brains.
Here are some Questions.
Question 1. Suppose you want to output 2,4,6,8, ..., 2n, one per line, can not pass the program 2-1 small changes to achieve it? For convenience, the procedure is now reproduced below:
#include<stdio.h> int main() { int n; scanf("%d", &n); for(int i = 1; i <= n; i++) printf("%d\n", i); return 0; }
Task 1: Modify the line 7, line 6 is not modified.
Task 2: Modify Line 6, does not modify the line 7.
Question 2. What is the result of the program the following? "! =" Operator indicates "not equal to." Tip: experiment on the computer, do not answer subjective feeling.
#include<stdio.h> int main() { double i; for(i = 0; i != 10; i += 0.1) printf("%.1f\n", i); return 0; }