7-1 求矩阵的局部极大值
#include<stdio.h>
int main()
{
int m, n, i, j;
int arr[100][100];
scanf("%d %d", &m, &n);
for (i = 1; i <= m; i++)
{
for (j = 1; j <= n; j++)
{
scanf("%d", &arr[i][j]);
}
}
int flag = 0;
for (i = 2; i <= m-1; i++)
{
for (j = 2; j <= n-1; j++)
{
if (arr[i][j] > arr[i - 1][j] && arr[i][j] > arr[i + 1][j] && arr[i][j] > arr[i][j - 1] && arr[i][j] > arr[i][j + 1])
{
printf("%d %d %d\n", arr[i][j], i, j);
flag = 1;
}
}
}
if (flag == 0)
{
printf("None %d %d", m, n);
}
return 0;
}
7-2 求矩阵各行元素之和
#include<stdio.h>
int main()
{
int m, n, i, j;
int arr[10][10];
scanf("%d %d", &m, &n);
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
scanf("%d", &arr[i][j]);
}
}
int sum = 0;
for (i = 0; i < m; i++)
{
for (j = 1; j < n; j++)
{
arr[1][0] += arr[i][j];
}
}
for (i = 0; i < m; i++)
printf("%d\n", arr[i][0]);
return 0;
}
7-3 判断上三角矩阵
文章来源:https://www.toymoban.com/news/detail-754562.html
#include<stdio.h>
int main()
{
int T, i, j, n,k;
int a[10][10];
scanf("%d", &T);
for (k = 0; k < T; k++)
{
scanf("%d", &n);
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
{
scanf("%d", &a[i][j]);
}
}
int flag = 1;
for (int x = 1; x < n; x++)
{
for (int y = 0; y < x; y++)
{
if (a[x][y] != 0)
{
flag = 0;
break;
}
}
if (flag == 0)
break;
}
if (flag == 1)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
7-4 点赞
文章来源地址https://www.toymoban.com/news/detail-754562.html
#include<stdio.h>
int main()
{
int n, m, i, j;
int num = 0, max = 0, maxpos = 1000;
scanf("%d", &n);
int flag[1001] = { 0 };
for (i = 0; i < n; i++)
{
scanf("%d", &m);
for (j = 0; j < m; j++)
{
scanf("%d", &num);
flag[num]++;
}
}
for (i = 1000; i > 0; i--)
{
if (flag[i] > max)
{
max = flag[i];
maxpos = i;
}
}
printf("%d %d", maxpos, max);
return 0;
}
到了这里,关于【C/PTA——8.数组2(课内实践)】的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!