C/C++ Programming Learning-Week 2 ⑥ Collect bottle caps to win prizes

Topic link

Title description

The Garlic Factory recently launched a "collect bottle caps to win big prizes" activity: if you have 10 bottle caps with "lucky" or 20 bottle caps with "encouragement" printed, you can redeem a mysterious prize.

Now give out the number of bottle caps with "Lucky" and "Encouragement" you have respectively, and judge whether you can redeem the prize.

Input format
One line, containing two non-negative integers not exceeding 100, which are the number of bottle caps printed with "lucky" and "encouragement", separated by a space.

Output format
One line. If the jackpot can be redeemed, output 1; otherwise, output 0.

Sample Input

11 19

Sample Output

1

Ideas

Determine whether the number of "lucky" is greater than 10 or whether the number of "encouragement" is greater than 20.

C language code:

#include<stdio.h>
int main()
{
    
    
    int lucky, encourage;	//定义两个变量,存储"幸运"和"鼓励"的数量
    scanf("%d %d",&lucky, &encourage);
    if(lucky >= 10 || encourage >= 20) printf("1");	//判断"幸运"的数量是否大于10或者"鼓励"的数量是否大于20,如果二者条件之一成立的话就输出1,否则输出0
    else printf("0");
    return 0;
}

C++ code:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    
    
	int a, b;
	while(cin >> a >> b)
		if(a >= 10 || b >= 20) cout << "1" << endl;
		else cout << "0" << endl;
	return 0;
}

Other exercises this week:

C language programming column

C/C++ Programming Learning-Week 2 ① Output Mario

C/C++ Programming Learning-Week 2② Print ASCII code

C/C++ Programming Learning-Week 2 ③ Output a three-digit number in reverse

C/C++ Programming Learning-Week 2 ④ Calculate the value of a polynomial

C/C++ Programming Learning-Week 2 ⑤ Calculation of the last term of the arithmetic sequence

C/C++ Programming Learning-Week 2 ⑥ Collect bottle caps to win prizes

C/C++ Programming Learning-Week 2 ⑦ Find the sum and mean of integers

C/C++ programming learning-week 2 ⑧ output character triangle

C/C++ Programming Learning-Week 2⑨ Judging Leap Year

C/C++ Programming Learning-Week 2⑩ Mr. Suantou goes to work

Guess you like

Origin blog.csdn.net/qq_44826711/article/details/112854226