简单的c语言练习题帮忙做一下

2023-12-21 00:50:53
有1个网友回答
网友(1):

3:
/*
* file:max-arrey.c
* ----------------
* This program is looked for the
* max number in 16 numbers and print the
* the max and the row.
* --------------------------------------
*/
#include
void main()
{
int a[16];
int i;
int row;
int max;
printf("please input 16 numbers:\n");
for (i=0;i<16;i++)
{
scanf("%d",&a[i]);
}
max=a[0];
for (i=0;i<16;i++)
{
if (a[i]>max)
{
max=a[i];
row=i;
}
}
printf("max=%d,row=%d\n",max,row);
getch();
}/*
* file: add-arrey.c
* -----------------
* The program is used to add the arrey 对角线元素之和
* print the result
* ---------------------------------------------------
*/
#include
void main()
{
int i,j;
int t=0,tn=0;
int a[5][5];
int sum;
printf("entry a arrey:\n");
for (i=0;i<5;i++)
{
for (j=0;j<5;j++)
{
scanf("%d",&a[i][j]);
}
}
for (i=0;i<5;i++)
{
for (j=0;j<5;j++)
{
if (i==j)
{
t=t+a[i][j];
}
if (i+j==6)
{
tn=tn+a[i][j];
}
sum=t+tn+a[2][2];
}
}
printf("the result is %d\n",sum);
getch();
}