-->
当前位置:首页 > 题库

PROGRAMMING:Special tasks

Luz5年前 (2021-05-10)题库402
###Task description
The teacher assigned Yu Long a preview task (many C language textbooks do not introduce this knowledge point)
```
The return value of the scanf() function
Scanf() function and printf() function are often used. Do they have return values? Some textbooks say scanf() function
It is wrong to say that the and printf() functions have no return value. Both functions have return values, but we rarely use them
only. In C language, only functions with void function type have no return value, and other functions have return value.
Procedure list 09-03-07. C
//An example of the return value of the scanf() function.
int main(){
int a,b,c;
c=scanf("%d%d",&a,&b);
printf("a=%d,b=%d,c=%d",a,b,c);
}
Execute the program, several sets of input and output results are as follows( ↙ (enter)
Input: 23 54 89 ↙ Output: a = 23, B = 54, C = 2
Input: 23,54 ↙ Output: a = 23, B = 5068454, C = 1
Input: 23a54 ↙ Output: a = 23, B = 5068454, C = 1
Input: x23 54 ↙ Output: a = 356, B = 5068454, C = 0
Program analysis:
According to C language, the return value of scanf() is the number of successfully read data.
The first group of input data, the program successfully read in two data, scanf() function return value is 2; Group 2 and group 3 input data,
The program reads a data successfully, and the return value of scanf() function is 1; The fourth group of data is not read successfully, the scanf() function is invalid
The return value is 0.
```
```
The teacher also assigned the following questions:
Programming input several integers, up to 4, at least 1, output their sum, average. If statement, switch statement and
Loop statements, because at this time these statements have not been learned by Yu Long.
```
###Input format:
There is only one line, and the number of integers separated by several spaces in one line may be at most four and at least one.
###Output format:
The output sum has an average value with 2 decimal places.
###Input example:
```in
1 2 3 4
```
###Output example:
```out
SUM=10,AVG=2.50
```
###Input example:
```in
1 2 3
```
###Output example:
```out
SUM=6,AVG=2.00
```







answer:If there is no answer, please comment