代码20140215

#include <iostream>
using namespace std;
int main()
{
    int a, b, c, temp, max;
    cout << "please enter three integer numbers:";
    cin >> a >> b >> c;
    temp = (a>b) ? a : b;                 /*  将a和b中的大者存入temp中 */
    max = (temp>c) ? temp : c;            /*  将a和b中的大者与c比较,最大者存入max */
    cout << "max=" << max << endl;
    return 0;
}

#include <iostream>
using namespace std;
int main()
{
    int x, y;
    cout << "enter x:";
    cin >> x;
    if (x<1)
    {
        y = x;
        cout << "x=" << x << ", y=x=" << y;
    }
    else if (x<10)                     // 1≤x<10 
    {
        y = 2 * x - 1;
        cout << "x=" << x << ", y=2*x-1=" << y;
    }
    else                           // x≥10 
    {
        y = 3 * x - 11;
        cout << "x=" << x << ", y=3*x-11=" << y;
    }
    cout << endl;
    return 0;
}

#include <iostream>
using namespace std;
int main()
{
    float score;
    char grade;
    cout << "please enter score of student:";
    cin >> score;
    while (score>100 || score<0)
    {
        cout << "data error,enter data again.";
        cin >> score;
    }
    switch (int(score / 10))
    {
    case 10:
    case 9: grade = 'A'; break;
    case 8: grade = 'B'; break;
    case 7: grade = 'C'; break;
    case 6: grade = 'D'; break;
    default:grade = 'E';
    }
    cout << "score is " << score << ", grade is " << grade << endl;
    return 0;
}

#include <iostream>
using namespace std;
int main()
{
    long int num;
    int indiv, ten, hundred, thousand, ten_thousand, place;
    /*分别代表个位,十位,百位,千位,万位和位数*/
    cout << "enter an integer(0~99999):";
    cin >> num;
    if (num>9999)
        place = 5;
    else  if (num>999)
        place = 4;
    else  if (num>99)
        place = 3;
    else  if (num>9)
        place = 2;
    else place = 1;
    cout << "place=" << place << endl;
    //计算各位数字
    ten_thousand = num / 10000;
    thousand = (int) (num - ten_thousand * 10000) / 1000;
    hundred = (int) (num - ten_thousand * 10000 - thousand * 1000) / 100;
    ten = (int) (num - ten_thousand * 10000 - thousand * 1000 - hundred * 100) / 10;
    indiv = (int) (num - ten_thousand * 10000 - thousand * 1000 - hundred * 100 - ten * 10);
    cout << "original order:";
    switch (place)
    {
    case 5:cout << ten_thousand << "," << thousand << "," << hundred << "," << ten << "," << indiv << endl;
        cout << "reverse order:";
        cout << indiv << ten << hundred << thousand << ten_thousand << endl;
        break;
    case 4:cout << thousand << "," << hundred << "," << ten << "," << indiv << endl;
        cout << "reverse order:";
        cout << indiv << ten << hundred << thousand << endl;
        break;
    case 3:cout << hundred << "," << ten << "," << indiv << endl;
        cout << "reverse order:";
        cout << indiv << ten << hundred << endl;
        break;
    case 2:cout << ten << "," << indiv << endl;
        cout << "reverse order:";
        cout << indiv << ten << endl;
        break;
    case 1:cout << indiv << endl;
        cout << "reverse order:";
        cout << indiv << endl;
        break;
    }
    system("pause");
    return 0;
}

#include <iostream>
using namespace std;
int main()
{
    long i;                       //i为利润
    float  bonus, bon1, bon2, bon4, bon6, bon10;
    bon1 = 100000 * 0.1;             //利润为10万元时的奖金
    bon2 = bon1 + 100000 * 0.075;      //利润为20万元时的奖金
    bon4 = bon2 + 100000 * 0.05;       //利润为40万元时的奖金
    bon6 = bon4 + 100000 * 0.03;       //利润为60万元时的奖金
    bon10 = bon6 + 400000 * 0.015;     //利润为100万元时的奖金
    cout << "enter i:";
    cin >> i;
    if (i <= 100000)
        bonus = i*0.1;                     //利润在10万元以内按10%提成奖金
    else if (i <= 200000)
        bonus = bon1 + (i - 100000)*0.075;    //利润在10万元至20万时的奖金
    else if (i <= 400000)
        bonus = bon2 + (i - 200000)*0.05;     //利润在20万元至40万时的奖金
    else if (i <= 600000)
        bonus = bon4 + (i - 400000)*0.03;     //利润在40万元至60万时的奖金
    else if (i <= 1000000)
        bonus = bon6 + (i - 600000)*0.015;    //利润在60万元至100万时的奖金
    else
        bonus = bon10 + (i - 1000000)*0.01;   //利润在100万元以上时的奖金
    cout << "bonus=" << bonus << endl;
    return 0;
}

#include <iostream>
using namespace std;
int main()
{
    long i;
    float bonus, bon1, bon2, bon4, bon6, bon10;
    int c;
    bon1 = 100000 * 0.1;
    bon2 = bon1 + 100000 * 0.075;
    bon4 = bon2 + 200000 * 0.05;
    bon6 = bon4 + 200000 * 0.03;
    bon10 = bon6 + 400000 * 0.015;
    cout << "enter i:";
    cin >> i;
    c = i / 100000;
    if (c>10)  c = 10;
    switch (c)
    {
    case 0: bonus = i*0.1; break;
    case 1: bonus = bon1 + (i - 100000)*0.075; break;
    case 2:
    case 3: bonus = bon2 + (i - 200000)*0.05; break;
    case 4:
    case 5: bonus = bon4 + (i - 400000)*0.03; break;
    case 6:
    case 7:
    case 8:
    case 9: bonus = bon6 + (i - 600000)*0.015; break;
    case 10: bonus = bon10 + (i - 1000000)*0.01;
    }
    cout << "bonus=" << bonus << endl;
    return 0;
}

#include <iostream>
using namespace std;
int main()
{
    int t, a, b, c, d;
    cout << "enter four numbers:";
    cin >> a >> b >> c >> d;
    cout << "a=" << a << ", b=" << b << ", c=" << c << ",d=" << d << endl;
    if (a>b)
    {
        t = a; a = b; b = t;
    }
    if (a>c)
    {
        t = a; a = c; c = t;
    }
    if (a>d)
    {
        t = a; a = d; d = t;
    }
    if (b>c)
    {
        t = b; b = c; c = t;
    }
    if (b>d)
    {
        t = b; b = d; d = t;
    }
    if (c>d)
    {
        t = c; c = d; d = t;
    }
    cout << "the sorted sequence:" << endl;
    cout << a << ", " << b << ", " << c << ", " << d << endl;
    return 0;
}


#include <iostream>
using namespace std;
int main()
{
    int p, r, n, m, temp;
    cout << "please enter two positive integer numbers n,m:";
    cin >> n >> m;
    if (n<m)
    {
        temp = n;
        n = m;
        m = temp;                //把大数放在n中, 小数放在m中
    }
    p = n*m;                     //先将n和m的乘积保存在p中, 以便求最小公倍数时用
    while (m != 0)               //求n和m的最大公约数
    {
        r = n%m;
        n = m;
        m = r;
    }
    cout << "HCF=" << n << endl;
    cout << "LCD=" << p / n << endl;        // p是原来两个整数的乘积
    system("pause");
    return 0;
}

 

posted @ 2014-02-15 16:13  yuanqi  阅读(328)  评论(2编辑  收藏  举报