分类 C++ 下的文章

#include<iostream>
using namespace std;
int main()
{
    int a[5] = { 1,2,3,4,5 };
    int *p = 0;
    cout << "下标运算a[i]:" << "\n";
    for (int x = 0; x < 5; x++)
    {
        cout << a[x];
    }
    cout << "\n指针运算(*p):" << "\n";
    for (p = a; p < &a[5]; p++)
    {
        cout << *p;
    }
    system("pause");
    return 0;
}

#include<iostream>
using namespace std;
int main()
{
    int i, z = 0, min, max;
    int a[8] = { 12,23,34,45,56,67,78,89 };
    max = a[0];
    min = a[0];
    for (i = 0; i < 8; i++)
    {
        if (min > a[i])
            min = a[i];
        else
            if (max < a[i])
                max = a[i];
    }
    cout << "该数组中最大值为:"<<max<<"\n最小值为:"<<min;
    system("pause");
    return 0;
}

#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;
}