2018年10月

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

#include<iostream>
using namespace std;
void main()
{
    int A(int n);//递归求阶乘
    cout << "请输入N值:";
    int i, N, sum = 0;
    cin >> N;
    if (N > 0)
    {
        for (i = N; i >= 1; i--)
        {
            sum += A(i);
        }
        cout << "结果:" << sum << endl;
    }
    else
        cout << "N必须为正整数!\n";
    system("pause");
}
int A(int n)
{
    if (n > 1)
        return A(n - 1)*n;
    if (n == 1)
        return 1;
}

#include<iostream>
using namespace std;
int main()
{
    int x, y=1, sum = 0;
    for (x = 1; x <= 6; x++)
    {
        y *= x;
        sum += y;
    }
    cout << sum << '\n';
    system("pause");
    return 0;
}