##第四周基本练习
本周作业为数组的基本练习
本课程的所有内容已经更新完毕,点击我的博客即可查看
#include "iostream"
using namespace std;
int main()
{
int n,a[100];
cin >> n;
int i;
for (i = 0; i < n; i++)
{
cin >> a[i];
}
for (i = n - 1; i > 0; i--)
{
cout << a[i] << " ";
}
cout << a[i];
return 0;
}
#include "iostream"
using namespace std;
int main()
{
int a,max;
cin >> a;
max = a;
while (a != -9999)
{
cin >> a;
if (max < a)
{
max = a;
}
}
cout << max;
return 0;
}
#include "iostream"
using namespace std;
int main()
{
int a[] = { -1, 15, -40, -180, 99, -122, -124, 27, 192, 128, -165, 95, 161, -138, -183, 51, 107, 39, -184, 113, -63, 9, 107, 188, -11, -13, 151, -52, 7, 6 };
int i, j,n,max,min,sum=0;
double ave;
cin >> i >> j;
if (i < j && (i >= 0 && j <= 30))
{
max = a[i];
min = a[i];
for (n = i; n < j; n++)
{
sum = sum + a[n];
if (a[n] > max)
{
max = a[n];
}
if (a[n] < min)
{
min = a[n];
}
}
ave = sum / (j - i + 0.0);
cout << max << " " << min << " " << sum << " " << ave << endl;
}
else
{
cout << 0 << " " << 0 << " " << 0 << " " << 0 << endl;
}
return 0;
}
#include "iostream"
using namespace std;
int main()
{
int n, m,a[20][20],i,j,max[20];
cin >> n >> m;
for (i = 0; i < n;i++)
{
for (j = 0; j < m; j++)
{
cin >> a[i][j];
}
}
for (i = 0; i < n; i++)
{
max[i] = a[i][0];
for (j = 0; j < m; j++)
{
if (a[i][j]>max[i])
{
max[i] = a[i][j];
}
}
cout << max[i] << endl;
}
return 0;
}
#include "iostream"
using namespace std;
int main()
{
int n, m, a[20][20], i, j, max[20];
cin >> n >> m;
for (i = 0; i < n; i++)
{
for (j = 0; j < m; j++)
{
cin >> a[i][j];
}
}
for (i = 0; i < m; i++)
{
max[i] = a[0][i];
for (j = 0; j < n; j++)
{
if (a[j][i]>max[i])
{
max[i] = a[j][i];
}
}
}
for (i = 0; i < m-1; i++)
{
cout << max[i] << " ";
}
cout << max[i];
return 0;
}
#include "iostream"
using namespace std;
int main()
{
int n, a[100], b[100], c[100];
cin >> n;
int i;
for (i = 0; i < n; i++)
{
cin >> a[i];
}
for (i = 0; i < n; i++)
{
cin >> b[i];
c[i] = a[i] + b[i];
}
for (i = 0; i < n-1; i++)
{
cout << c[i] <<" ";
}
cout << c[i] << endl;
return 0;
}
#include "iostream"
using namespace std;
int main()
{
int n, a[100], b[100], mul=0;
cin >> n;
int i;
for (i = 0; i < n; i++)
{
cin >> a[i];
}
for (i = 0; i < n; i++)
{
cin >> b[i];
mul = mul + a[i] * b[i];
}
cout << mul << endl;
return 0;
}
#include "iostream"
#include
using namespace std;
int main()
{
int n, i;
double dis, a[100],sum = 0;
cin >> n;
for (i = 0; i < n; i++)
{
cin >> a[i];
sum = sum + a[i] * a[i];
}
dis = sqrt(sum);
cout << dis << endl;
return 0;
}
#include "iostream"
#include
using namespace std;
int main()
{
int n, i;
double dis, a[100],b[100],sum = 0;
cin >> n;
for (i = 0; i < n; i++)
{
cin >> a[i];
}
for (i = 0; i < n; i++)
{
cin >> b[i];
sum = sum + (b[i] - a[i])*(b[i] - a[i]);
}
dis = sqrt(sum);
cout << dis << endl;
return 0;
}
#include "iostream"
using namespace std;
int main()
{
int n,m,i,j;
double a[100][100],b[100][100],c[100][100];
cin >> n >> m ;
if (n > 0 || m > 0)
{
for (i = 0; i < n; i++)
{
for (j = 0; j < m; j++)
{
cin >> a[i][j];
}
}
for (i = 0; i < n; i++)
{
for (j = 0; j < m; j++)
{
cin >> b[i][j];
c[i][j] = a[i][j] + b[i][j];
}
}
for (i = 0; i < n; i++)
{
for (j = 0; j < m-1; j++)
{
cout << c[i][j]<<" ";
}
cout << c[i][j] << endl;
}
}
return 0;
}
#include "iostream"
#include
using namespace std;
int main()
{
char sen[100];
int len;
cin.getline(sen, 100);
len = strlen(sen);
cout << len << endl;
return 0;
}
#include "iostream"
#include "cstring"
using namespace std;
int main()
{
char sen[200];
int n=0,i=0;
cin.getline(sen, 200);
while (sen[i] != '\0')
{
if (sen[i] >= 'A'&&sen[i] <= 'Z')
n++;
i++;
}
cout << n << endl;
return 0;
}
#include "iostream"
#include "cstring"
using namespace std;
int main()
{
char sen_1[100],sen_2[100];
int i = 0;
cin.getline(sen_1, 200);
while (sen_1[i] != '\0')
{
sen_2[i] = sen_1[i];
i++;
}
sen_2[i] = sen_1[i];
i = 0;
while (sen_2[i] != '\0')
{
cout << sen_2[i];
i++;
}
return 0;
}
#include "iostream"
#include "cstring"
using namespace std;
int main()
{
char s[100],tmp[100];
int i = 0,n=0;
cin.getline(s, 100);
while (s[i] != '\0')
{
tmp[i] = s[i];
i++;
n++;
}
for (i = 0; i < n;i++)
{
s[i] = tmp[n - i-1];
cout << s[i];
}
return 0;
}
#include "iostream"
#include "cmath"
using namespace std;
struct Point
{
double x, y;
};
int main()
{
Point a, b;
double dis;
cin >> a.x >> a.y;
cin >> b.x >> b.y;
dis = sqrt((a.x - b.x)*(a.x - b.x) + (a.y - b.y)*(a.y - b.y));
cout << dis<
以上为第四次基本练习。