文章

C++ Primer 4.7节练习 4.21-4.24

4.21

#include<iostream>
#include<vector>
using namespace std;


int main() {
    vector<int> i {1,2,3,4,5,6,7,8,9};
    for(auto e = i.begin();e != i.end();++e)
        cout << ((*e % 2 == 1) ? *e * 2 :*e) << endl;
    return 0;
}

4.22

#include<iostream>
#include<vector>
using namespace std;


int main() {
    int grade;
    while (cin >> grade)
        cout << ((grade >= 90) ? "high Pass" : (90 > grade && grade >= 75) ? "Pass" : (75 > grade && grade >= 60) ? "Low Pass" : "fail") << endl;
    return 0;
}
#include<iostream>
#include<vector>
using namespace std;


int main() {
    int grade;
    while (cin >> grade) {
        if (grade >= 90)
            cout << "High Pass" << endl;
        if (grade >= 60 && grade < 75)
            cout << "Low Pass" << endl;
        if (grade >= 75 && grade < 90)
            cout << "Pass" << endl;
        if(grade<60)
            cout << "fail" << endl;
    }

    return 0;
}
原文来自:C++ Primer 4.7节练习 4.21-4.24,尊重自己,尊重每一个人;转发请注明来源!
0 0

发表评论