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