CellPhone 发布的文章

#include<iostream>
using namespace std;
int main()
{
    const int maxNum = 6;
    int n, a[maxNum], i, j;
    cout << "请为数组元素赋值(6个整数):\n";
    for (n = 0; n < maxNum; n++)
    {
        cin >> a[n];
        if (a[n] == 7)
            break;
    }
    for (i = 0; i < n - 1; i++)
        for (j = i + 1; j < n; j++)
            if (a[i] > a[j])
            {
                int t;
                t = a[i];
                a[i] = a[j];
                a[j] = t;
            }
    cout << "升序排序后数组元素分别为:\n";
    for (i = 0; i < n; i++)
        cout << a[i] << "\t";
    system("pause");
    return 0;
}

#include<iostream>
using namespace std;
int main()
{
    const int num = 5;
    int i, a[num], x;
    cout << "请为数组元素赋值(5个整数):";
    for (i = 0; i < num; i++)
    {
        cin >> a[i];
    }
    for (x = 0; x < num; x++)
    {
        if ((a[x] % 5) ==0)
            a[x] = 0;
    }
    cout << "替换后的元素分别为:";
    for (i = 0; i<num; i++)
        cout << a[i] << "\t";
    system ("pause");
    return 0;
}

#include<iostream>
using namespace std;
int area(int x, int y)
{
    int a;
    a = x * y;
    return a;
}
int main()
{
    int length, width;
    cout << "请输入长方形的长度和宽度:";
    cin >> length >> width;
    cout << "该长方形的面积为:" << area(length, width) << "\n";
    return 0;
}

#include<iostream>
using namespace std;
int area(int x, int y)
{
    int a;
    a = x * y;
    return a;
}
int main()
{
    int length, width;
    cout << "请输入长方形的长度和宽度:";
    cin >> length >> width;
    cout << "该长方形的面积为:" << area(length, width) << "\n";
    return 0;
}

#include<iostream>
using namespace std;
int f(int x)
{
    int y;
    for (y = 2; y < x; y++)
    {
        if (x%y == 0)
            return 0;
    }
    return 1;
}
int main()
{
    int z;
    cout << "请输入一个数:";
    cin >> z;
    if (f(z))
        cout << z << "是素数\n";
    else
        cout << z << "不是素数\n";
    system("pause");
    return 0;
}