C language brush questions ------ (1)

C language brush questions

Websites for bloggers to brush questions:Question Bank - Lanqiao Cloud Course (lanqiao.cn)

Friends can try it! ! !

First question

Topic: Statistics

topic description: Xiaolan organized an exam for the students. The total score of the paper is 100 points, and each student's score is an integer from 0 to 100.

A score of at least 60 is called a pass. A score of at least 85 is considered excellent.

Please calculate the pass rate and excellent rate, expressed as a percentage, and the part before the percentage sign is rounded to an integer.

enter description

The first line of input contains an integer n (1≤n≤10^4), indicating the number of people taking the test.

Next n lines, each line contains an integer from 0 to 100, representing a student's score.

output description

Output two lines, each with a percentage, indicating the passing rate and the excellent rate respectively. The part before the percent sign is rounded to an integer.

Input and output samples

example

enter

7
80
92
56
74
88
100
0

output

71%
43%

train of thought: First input the total number of people, put their scores in an array, and then use the for loop to count the number of scores of 60-85, and then count the scores above 85, and calculate two The proportion of classes, note that when expressing % in c language, when writing code, use two %% instead.


Demo:

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>
int main()
{
    
    
	int peopleNumber = 0;
	int arr[10] = {
    
     0 };
	float pass = 0.0;
	int count = 0;
	int count2 = 0;
	float outstanding = 0.0;
	printf("请输入人数:\n");
	scanf("%d", &peopleNumber);
	for (int i = 0; i < peopleNumber; i++)
	{
    
    
		scanf("%d", &arr[i]);
	}
	for (int j = 0; j < peopleNumber; j++)
	{
    
    
		if (arr[j] >= 60)
		{
    
    
			count++;
		}
		if (arr[j] >= 85)
		{
    
    
			count2++;
		}
	}
	pass = (count *100)/( peopleNumber*1.0);
	outstanding = (count2*100) / (peopleNumber*1.0);
	printf("%.0f%%\n", pass);
	printf("%.0f%%\n", outstanding);
	return 0;
}

Second question

Topic: Beverage Redemption

topic description: Leyangyang Beverage Factory is holding a promotional offer. For Leyangyang C-type drinks, 3 bottle caps can be exchanged for another C-type drink, and can be recycled forever (but temporary loans or credits are not allowed).

Please calculate, if Xiao Ming does not waste bottle caps and participates in activities as much as possible, then, for the n bottles of drinks he bought initially, how many bottles of drinks he can drink in total in the end.

enter description

Enter an integer n (0< n <1000), indicating the number of drinks to start buying.

output description

Output an integer indicating the number of drinks actually obtained

Input and output samples

example

enter

100

output

149

train of thought: Just use one cycle, because every three bottle caps are changed to one bottle, we use 1—the initial total number of bottles to %3, if the result is equal to 0, it means that it is a multiple of 3, then the total number of bottles Count + 1 until the loop condition i<=n.


Demo:

#include <stdio.h>
#include <stdlib.h>
int main()
{
    
    
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        if(i%3==0)
            n++;
    printf("%d",n);
    return 0;
}

Guess you like

Origin blog.csdn.net/m0_74968164/article/details/132128767