C Language Day

 

1. Examples of poor expression

1 a=5;
2 c = (b=a+2) - (a=2);

c = (b = a + 2) - (a = 2); two time points p1 and p2 (in C language is called the standard Sequence Point) performs forward and executed. In this embodiment, the side effects subexpression (a = 2) between p1 and p2 are undefined (this side effect has occurred Sure, that is to say a value becomes 2). Then, the standard has this to say,

The second rule says value (old value) can only be used to calculate a new value before the point in time p1. In the present embodiment, the subexpression (b = a + 2) the new value of b is determined a (constant is 2, are not considered here), the specified value is a value or a new value before p1 is (see the first> paragraphs) uncertain. So there will be problems. For example, clang compiler will report a warning.

If written in a row have to be written as c = (b = a + 2, a = 2, ba); because the operator ",", "||" and "&&" corresponds to a point sequence (Sequence Point).

2. Write the code execution, the values ​​of t1 and t2, separated by a space:

1 int a=14;
2 int t1 = a++;
3 int t2 = ++a;

The correct answer: 1416

3. Write the following expressions result, a result of his party:

6 + 5 / 4 - 2
2 + 2 * (2 * 2 - 2) % 2 / 3
10 + 9 * ((8 + 7) % 6) + 5 * 4 % 3 * 2 + 3 
1 + 2 + (3 + 4) * ((5 * 6 % 7 / 8) - 9) * 10
correct answer:
5
2
44
-627

3. The three-digit reverse order:

Each read program into a three-digit positive, then the reverse order of the digital output. Note that, when the end containing the digital input 0 output 0 not with preamble. Such as input 700, the output should be 7.

Tip: Use 10% can be single-digit, use / 100 can get hundreds place .... The thus obtained three numbers together: one hundred * 100 + 10 * + ten bits, the result is obtained.

Note: In addition to the output requirements of the subject, can not output any other content, such as input prompts, when output and so can not be explained. This question requires a digital output in reverse order, the program can only output this figure, in addition to any content can not be output.

Input formats:

Each test is a positive integer of 3.

Output formats:

Number reverse order output.

Sample input:

123

Sample output:

321

1 #include<stdio.h>
2 int main()
3 {
4     int a;
5     scanf("%d",&a);
6     printf("%d",a%10*100+a/10%10*10+a/100);
7     return 0;
8 }

Cm in terms of feet 4 inches

If the value of the length of the foot and the foot inch inch inch is known, rice is the corresponding (foot + inch / 12) × 0.3048. Now, if the user input is in centimeters, then the corresponding length of imperial feet and inches is how much? Do not forget one foot equals 12 inches.

Input formats:

Input gives a positive integer in a row, in centimeters.

Output formats:

In this output line number corresponding to an integer value centimeters feet and inches inch length, separated by spaces.

Sample input:

170

Sample output:

5 6
 1 #include<stdio.h>
 2 int main()
 3 {
 4     int cm=0;
 5     scanf("%d",&cm);
 6     int foot = cm / 30.48;
 7     int inch = ((cm / 30.48) - foot)*12;
 8     printf("%d %d",foot,inch);
 9     return 0;
10  } 

5. Calculate Celsius

Given a Fahrenheit F., This problem requires programming, calculates the corresponding Celsius C. Calculated: C = 5 × (F-32) / 9. Title ensure that the input and the output are within the range of integers.

Input formats:

In a given input row Fahrenheit.

Output formats:

In a row in the format "Celsius = C" corresponding to the integer value of the output C of the temperature in degrees Celsius.

Sample input:

150
 

Sample output:

Celsius = 65
 1 #include<stdio.h>
 2 int main()
 3 {
 4     int F;
 5     int C=0;
 6     scanf("%d",&F);
 7     C=5*(F-32)/9;
 8     printf("Celsius = %d",C);
 9     return 0;
10  } 

6. Is not too fat

It is said that a person's standard weight should be its height (unit: cm) minus 100, multiplied by the number of kilograms of 0.9 resulting. Jin known value is twice the value of kilograms. Now given someone tall, you should calculate the standard weight is how much? (By the way quietly to do the math about it ......)

Input formats:

The first input line is given a positive integer H(100 <H ≤ 300), the height of a person.

Output formats:

In the row corresponding to the output standard weight, units Jin, retained after a decimal point.

Sample input:

169
 

Sample output:

124.2
 1 #include<stdio.h>
 2 int main()
 3 {
 4     int H;
 5     double W; 
 6     scanf("%d",&H);
 7     W=(H-100)*0.9*2;
 8     printf("%.1f",W);
 9     return 0;
10  } 

 7. seeking integer mean

This problem requires programming, and four integer calculated average value. Title ensure that the input and the output are within the range of integers.

Input formats:

Input are four integer in a row, separated by a space therebetween.

Output formats:

In a row in the format "Sum = and; Average = Average" and sequentially outputs the average value, wherein an average value of decimal place.

Sample input:

1 2 3 4
 

Sample output:

Sum = 10; Average = 2.5
 1 #include<stdio.h>
 2 int main()
 3 {
 4     int a,b,c,d;
 5     int Sum=0;
 6     double Average;
 7     scanf("%d %d %d %d",&a,&b,&c,&d);
 8     Sum = a+b+c+d;
 9     Average = Sum / 4.0;
10     printf("Sum = %d; Average = %.1f",Sum,Average);
11     return 0;
12  } 

8.















 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

End ------------ ------------ restore content

Guess you like

Origin www.cnblogs.com/cx710828xz/p/12443223.html