Informatics Olympiad 1.3: The control structure of the program (1)

The first part of C++ language

Chapter III Program Control Structure

The first section if selection structure

1039 Judgment number is positive or negative
​#include <iostream>
using namespace std;

int main() {
    int n;
    cin >> n;

    if (n > 0) {
        cout << "positive" << endl;
    }
    else if (n == 0) {
        cout << "zero" << endl;
    }
    else {
        cout << "negative" << endl;
    }

    return 0;
}
1040 Output absolute value
#include <cstdio>
using namespace std;

int main() {
    float a;
    scanf("%f",&a);

    if (a < 0) {
        printf("%.2f\n", -1 * a);
    }
    else {
        printf("%.2f\n", a);
    }

    return 0;
}
1041 Parity Judgment
#include <iostream>
using namespace std;

int main() {
    int n;
    cin >> n;

    if (n%2 == 0) {
        cout << "even" << endl;
    }
    else {
        cout << "odd" << endl;
    }

    return 0;
}
1042 Parity ASCII value judgment
#include <iostream>
using namespace std;

int main() {
    char c;
    cin >> c;

    if (c%2 == 1) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }

    return 0;
}
1043 integer size comparison
#include <iostream>
using namespace std;

int main() {
    int x, y;
    cin >> x >> y;

    if (x > y) {
        cout << '>' << endl;
    }
    else if (x == y) {
        cout << '='<< endl;
    }
    else {
        cout << '<' << endl;
    }

    return 0;
}
1044 Determine whether it is a two-digit number
#include <iostream>
using namespace std;

int main() {
    int n;
    cin >> n;

    if (n >=10 && n <= 99) {
        cout << 1 << endl;
    }
    else {
        cout << 0 << endl;
    }

    return 0;
}
1045 Collect bottle caps to win big prizes
#include <iostream>
using namespace std;

int main() {
    int a, b;
    cin >> a >> b;

    if (a>=10 || b >=20) {
        cout << 1 << endl;
    }
    else {
        cout << 0 << endl;
    }

    return 0;
}
1046 Determine whether a number is divisible by 3 and 5 at the same time
#include <iostream>
using namespace std;

int main() {
    int n;
    cin >> n;

    if (n%3 == 0 && n%5 ==0) {
        cout << "YES" << endl;
}
    else {
        cout << "NO" << endl;
    }

    return 0;
}
1047 Determine whether it can be divisible by 3, 5, 7
#include <iostream>
using namespace std;

int main() {
    int n;
    cin >> n;

    if (n%3!=0 && n%5!=0 && n%7!=0) {
        cout << 'n' << endl;
    }
    else {
        if (n%3 == 0) {
            cout << "3 ";
        }
        if (n%5 == 0) {
            cout << "5 ";
        }
        if (n%7 == 0) {
            cout << "7 ";
        }
    }

    return 0;
}
1048 A student who failed a course
#include <iostream>
using namespace std;

int main() {
    int a, b;
    cin >> a >> b;

    if ((a>=60) == (b>=60)) {
        cout << 0 << endl;
    }
    else {
        cout << 1 << endl;
    }

    return 0;
}

If your child is in the fourth grade or above, is interested in computer programming and has spare capacity in cultural lessons, please contact customer service (WeChat ID: xiaolan7321) to participate in informatics learning. We are professional informatics competition coaches. We use online small class teaching methods. The goal is to help primary and middle school students who love programming to achieve excellent results in informatics competitions at home and abroad.

Teaching features:

  • Online small class teaching, lay a good code foundation. Avoid the problem that students in large classes are either "can't keep up" or "not enough to eat".

  • Rich teaching experience, familiar with students' knowledge structure and learning ability, and arrange the schedule reasonably.

  • Practice with competitions, and continuously improve students' abilities through examinations and competitions.

Guess you like

Origin blog.csdn.net/davidliule/article/details/106139478