1-1 Average: Enter 3 integers, output their average, retain 3 decimal places
#include <stdio.h>int main () { int a,b,c; scanf ("%d%d%d",&a,&b,&c); double D= (double) (a+b+c); printf ("%.3lf\n", d/3.0); return 0 ;}
1-2 temperature: input Fahrenheit temperature F, output the corresponding degree C, reserved 3 decimal places. Tip: C=5 (f-32)/9
#include <stdio.h>int main () { double F; double C; scanf ( %lf , &f); c = 5 * (F-32 )/9.0 ; printf ( %.3lf\n " ,c); return 0 ;}
1-3 continuous and: input positive integer n, output 1+2+3+...+n value. Tip: The goal is to solve the problem rather than practice programming
#include <stdio.h>int main () { int n; scanf ("%d",&N); printf ("%d\n", (n (1+n))/2); return 0 ;}
1-4 sine and cosine: input positive integer n (n<360), output sine cosine of n degrees. Tip: Use Mathematical functions
#include <stdio.h>#include<math.h>#definePI ACOs (-1.0)intMain () {intN; scanf ("%d",&N); printf ("%lf\n", Sin ((pi*n)/ the)); printf ("%lf\n", cos ((pi*n)/ the)); return 0;}
1-5 discount: One clothes 95 yuan, if the consumption is full 300 yuan, can play 85 percent. Enter the number of clothes purchased, output the amount to be paid (unit), retain two decimal places
#include <stdio.h>intMain () {intN; DoubleA; scanf ("%d",&N); A=n*95.0; if(a< -) printf ("%.2lf\n", a); Elseprintf ("%.2lf\n", A *0.85); return 0;}
1-6 triangle: Input triangle 3 Edge length value (all positive integer), determine whether it can be right triangle 3 edge length. If so, the output is yes, cannot output no, and if it cannot form a triangle, the output is not a triangle
#include <stdio.h>intMain () {intA,b,c,max; scanf ("%d%d%d",&a,&b,&c); Max= A>b?a:b; Max= Max>c?Max:c; if(Max > a+b+c-max) {printf ("Not a triangle\n"); return 0; } if(a*a = = B*b+c*c | | b*b = A*A+C*C | | c*c = a*a+b*b) printf ("yes\n"); Elseprintf ("no\n"); return 0;}
1-7 years: Enter the year, determine whether it is run year, if yes, output yes, no, output No. Tip: Simply dividing by 4 is not enough
#include <stdio.h>intMain () {intN; scanf ("%d",&N); if(n%4==0&& n% -!=0|| n% -==0) printf ("yes\n"); Elseprintf ("no\n"); return 0;}
2-1 Daffodils Number: The number of all daffodils in the output 100~999, if 3-digit ABC satisfies abc=a3+b3+c3 is called Narcissus number, for example 153 = 13+53+33, so 153 is the number of daffodils
#include <stdio.h>intMain () {intA,b,c; for(intI= -; i<=999; i++) {a=i/ -; b=i/Ten%Ten; C=i%Ten; if(i==a*a*a+b*b*b+c*c*c) printf ("%d\n", i); } return 0;}
2-2 Han Xin Soldiers of: It is said that Han Xin intelligence, never directly clears the number of their troops, as long as the soldiers have three in a row, five people a row, seven people a row of the transformation formation, and he only a glance at the end of the queue of the number of people will know the total number. The input includes multiple sets of data, each set of data containing 3 non-negative integer a,b,c (a<3,b<5,c<7) output total number of the minimum (or report no solution), the total number of known is not less than 10, not more than 100.
#include <stdio.h>intMain () {intI,a,b,c; scanf ("%d%d%d",&a,&b,&c); for(i=Ten; i<= -; i++) { if(i%3==a && i%5==b && i%7==c)
{printf ("Case 1:%d\n", i);
Break
} } if(i==101) printf ("Case 2:no answer\n"); return 0;}
2-3 Inverted triangle: Enter a positive integer n<=20, outputting an n-layer inverted triangle.
2-4 the and of the subsequence: Enter two positive integer n<m<106, Output 1/n2+1/(n+1) 2+...+1/m2, retain 5 decimal places. Input contains multiple sets of data, end marked as n=m=0 hint: there's a trap.
2-5 Fractional Decimal: Enter a positive integer a,b,c the decimal form of the output A/b, accurate to the C bit after the decimal point. a,b<=106,c<=100. Input contains multiple sets of data with end tag a=b=c=0
2-6 arrangement: With three-way,..., 9 to make up 3 three-digit Abc,def,ghi each number is used exactly once, requiring abc:def:ghi=1:2:3. Output all solutions in the "ABC def GHI" format, one solution per line. Tip: Don't be too clever
"Algorithmic Competition Introduction Classic Second Edition" exercise answer 1, 2 chapters