Auto commit

This commit is contained in:
smallkun 2025-02-28 09:53:19 +08:00
parent 23fb17e13c
commit b66b096327
2 changed files with 111 additions and 0 deletions

View File

@ -0,0 +1,54 @@
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
/*
1 2 3 |6
4 5 6 |15
7 8 9 |24
-------------
12 15 18
*/
void getSum(int array[100][100], int n, int m){
int i, j, sum;
for(i=0;i<n;i++){
sum = 0;
for(j=0;j<m;j++){
printf("%-5d ", array[i][j]);
sum += array[i][j];
}
printf("| %-5d\n", sum);
}
for(j=0;j<m;j++){
printf("------");
}
printf("\n");
for(j=0;j<m;j++){//列的下标
sum =0;
for(i=0;i<n;i++){//行的下标
sum += array[i][j];
}
printf("%-5d ", sum);
}
printf("\n");
}
int main(){
int n, m, i, j;//n为行数 m为列数
int array[100][100] = {0};
printf("请输入行数和列数:");
scanf("%d %d", &n, &m);
srand((unsigned)time(NULL));
for(i=0;i<n;i++){
for(j=0;j<m;j++){
array[i][j] = rand()%100;
}
}
getSum(array, n, m);
return 0;
}

View File

@ -604,6 +604,63 @@ int main(){
![image-20250227231121624](https://yp.smallkun.cn/markdown/image-20250227231121624.png!compress)
```c
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
/*
1 2 3 |6
4 5 6 |15
7 8 9 |24
-------------
12 15 18
*/
void getSum(int array[100][100], int n, int m){
int i, j, sum;
for(i=0;i<n;i++){
sum = 0;
for(j=0;j<m;j++){
printf("%-5d ", array[i][j]);
sum += array[i][j];
}
printf("| %-5d\n", sum);
}
for(j=0;j<m;j++){
printf("------");
}
printf("\n");
for(j=0;j<m;j++){//列的下标
sum =0;
for(i=0;i<n;i++){//行的下标
sum += array[i][j];
}
printf("%-5d ", sum);
}
printf("\n");
}
int main(){
int n, m, i, j;//n为行数 m为列数
int array[100][100] = {0};
printf("请输入行数和列数:");
scanf("%d %d", &n, &m);
srand((unsigned)time(NULL));
for(i=0;i<n;i++){
for(j=0;j<m;j++){
array[i][j] = rand()%100;
}
}
getSum(array, n, m);
return 0;
}
```
### 函数-2