current position:Home>How to sum two-dimensional arrays and the average.

How to sum two-dimensional arrays and the average.

2022-01-27 02:30:06 CSDN Q & A




Refer to the answer 1:
```c#include <stdio.h>#include <stdlib.h>int main(){    int a[4][4]={
   4,5,6,7}};    int sum=0;    int average;    for(int i=0;i<4;i++)    {        for(int j=0;j<4;j++)        {            sum=sum+a[i][j];        }    }    average=sum/16;    printf("Sum:%d\n",sum);    printf("Average:%d\n",average);    return 0;}


Refer to the answer 2:

Refer to the answer 3:

if(a[i][j] > max){
max = a[i][j]

aver = sum / 20 Put it in for Outside of the loop
And it's best to use floating-point type to represent , Otherwise there will be errors

Refer to the answer 4:

Refer to the answer 5:

There is no problem with summation , The average should be put in for Circular outer head

Refer to the answer 6:

copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.

Random recommended