5月26日打卡

发布时间 2023-05-27 00:40:10作者: 石铁生

习题:

在函数中fn1()中定义一个静态变量n,fn1()中对n的值加1,在主函数中调用fn1()10,显示n的值。

#include<iostream>
using namespace std;
static int n = 0;
void fn1()
{
    n++;
}
int main()
{
    for (int i = 0; i < 10; i++)
    {
        fn1();
    }
    cout << n;
}

例6-1

数组的定义与使用

#include<iostream>
using namespace std;
int main()
{
    int a[10], b[10];
    for (int i = 0;i < 10; i++)
    {
        a[i] = i * 2 - 1;
        b[10 - i - 1] = a[i];
    }
    for (const auto& e : a)
        cout << e << " ";
    cout << endl;
    for (int i = 0; i < 10; i++)
        cout << b[i] << " ";
    cout << endl;
    return 0;
}