2018年11月

#include<iostream>
using namespace std;
int main()
{
    char x[5];
    char *p;
    cout << "请输入一个字符串(5位):\n";
    cin >> x;
    cout << "字符串反转后为:";
    for (p = &x[5];p >= x; p--)
    {
        cout << *p;
    }
    system("pause");
    return 0;
}

/********************************************************************
*  功能:实现将一个字符串连接到另一个字符串尾部,并输出结果  *
*                                                                                              *
********************************************************************/
#include<iostream>
using namespace std;
int main()
{
    char x[50], y[50];               //定义两个字符数组
    int a, x1, x2;
    cout << "请输入字符串X:\n";      //从键盘为两个字符数组赋值
    cin >> x;
    cout << "请输入字符串Y:\n";
    cin >> y;
    x1 = strlen(x);          //取字符串x的长度(不包括'\0')
    x2 = strlen(y);
    for (a = 0; y[a] != '\0'; a++)
    {
        x[a + x1] = y[a];           //将字符串y赋值到x
    }
    x[x1 + x2] = '\0';              //字符串缺少必要的结尾符'\0'会出现“烫”字错误
    cout <<"连接后的字符串X为:"<< x << "\n";          //输出连接后的字符串
    system("pause");
    return 0;
}

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