c++作业

#include<iostream>
using namespace std;
int Count(double a[], int n)
{
    double sum = 0, av = 0;
    int num = 0;
    for (int i = 0; i < n; i++)
    {
        sum += a[i];
    }
    av = sum / n;
    for (int i = 0; i < n; i++)
    {
        if (a[i] >= av)
            num += 1;
    }
    return num;
}
int main()
{
    int n, num; double a[100] = {};
    cout << "请输入元素的个数:";
    cin >> n;
    cout << "请输入你的数:" << endl;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    num = Count(a, n);
    cout << "在你输入的数中大于等于平均数的个数为:" << num;

    return 0;
}
#include<iostream>
using namespace std;
int comm(int n, int k)
{
    if (k > n)
        return 0;
    else if (n == k || k == 0)
        return 1;
    else
        return comm(n - 1, k - 1) + comm(n - 1, k);
    
}
int main()
{
    cout << comm(5, 2);
    return 0;
}
#include<iostream>
using namespace std;
int main()
{
    int  n ,a[100];
    cout << "请输入元素的个数:";
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    cout << "你输入的数组为:" << endl;
    for (int i = 0; i < n; i++)
    {
        cout << a[i] << "  ";
    }
    cout << endl;
    cout << "向后移动一位后的数组为:";
    for (int i = n; i >0; i--)
    {
        a[i] = a[i-1];
    }
    a[0] = a[n ];
    for (int i = 0; i < n; i++)
    {
        cout << a[i] << "  ";
    }
    return 0;
}
#include<iostream>
using namespace std;
int totaldays(int y, int m, int d)//闰年的判断
{
    int x=0;
    
    if ((y % 400 == 0 || y % 4 == 0 && y % 100 != 0))//闰年和非闰年的天数不一样,在这里判断了一下
    {
        int a[12] = { 0,31,29,31,30,31,30,31,31,30,31,30 };
        for (int i = 0; i < m; i++)
        {
            x =x+ a[i];
        }
        return x + d;
    }
    else
    {
        int a[12] = {0, 31,28,31,30,31,30,31,31,30,31,30 };
        for (int i = 0; i < m; i++)
        {
            x =x+ a[i];
        }
        return x + d;
    }
}
int main()
{
    int y, m, d,x;
    cout << "请输入日期:";
        cin >> y; cin >> m; cin >> d;
        x = totaldays(y, m, d);
        cout << y << "年" << m << "月" << d << "日该年的第" << x << "天";

    return 0;
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值