1 //二维数组每行输出平均值 2 //2017.3.7 3 #include <stdio.h> 4 #include <stdlib.h> 5 6 void Rand(int arr[][100], int n); 7 void OutputAvg(int arr[][100], int n); 8 int main() 9 { 10 int arr[100][100]; 11 int n = 10; 12 int sum = 0; 13 //随机初始化数组 14 Rand(arr, n); 15 OutputAvg(arr, n); 16 17 //处理函数 求出每一行的和 18 for (int i = 0; i < n; i++) 19 { 20 for (int j = 0; j < n; j++) 21 { 22 sum = sum + arr[i][j];//求出每一行的值 23 24 } 25 printf("第%d行的平均值为%d\n", i + 1, sum); 26 } 27 system("pause"); 28 return 1; 29 } 30 31 void Rand(int arr[][100], int n) 32 { 33 for (int i = 0; i < n; i++) 34 { 35 for (int j = 0; j < n; j++) 36 { 37 arr[i][j] = rand() % 100 + 11; 38 } 39 } 40 } 41 42 void OutputAvg(int arr[][100], int n) 43 { 44 for (int i = 0; i < n; i++) 45 { 46 for (int j = 0; j < n; j++) 47 { 48 printf("%-5d", arr[i][j]); 49 } 50 printf("\n"); 51 } 52 }
时间: 2024-12-28 01:49:05