标签:
#include<stdio.h> int sum(int b[ ][4],int m,int n); int main() { int a[4][4]={{1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,16}}; int m,n; printf ("请输入行 列:"); scanf("%d %d",&m,&n); printf("sum=%d\n",sum(a,m,n)); return 0; } int sum(int b[ ][4],int m,int n) { int i,j,s=0; for (i=0;i<m;i++) { for (j=0;j<n;j++) { s+=b[i][j]; } } return s; }运行结果:
#include<stdio.h> void input(double s[][4],int n); void output(double s[ ][4],int n); double max(double s[ ][4], int n, int i); double min(double s[ ][4], int n, int i); double avg(double s[ ][4], int n, int i); int main() { int i, num; double score[100][4]; char course[4][10]= {"高等数学","英语","c++","总分"}; printf ("请输入学生人数:"); scanf ("%d", &num); input (score, num); output (score, num); for (i=0;i<4;i++) { printf ("%s的最高成绩是%.2f,", course[i], max(score, num, i)); printf ("最低成绩是%.2f,", min(score, num, i)); printf ("平均成绩是%.2f,", avg(score, num, i)); printf ("\n"); } return 0; } void input(double s[ ][4], int n) { int i,j,t; for(i=0;i<n;i++) { printf ("请输入第%d位同学的成绩(高数,英语,c++):\n", i); t=0; for(j=0;j<3;j++) { printf ("第%d门成绩:", j); scanf("%lf", &s[i][j]); t+=s[i][j]; } s[i][3]=t; printf ("\n"); } } void output(double s[ ][4], int n) { int i,j; printf ("学号\t高数\t英语\tc++\t总分\n"); for (i=0;i<n;i++) { printf ("%d",i); for (j=0;j<4;j++) { printf ("\t%.2f", s[i][j]); } printf ("\n"); } printf ("\n"); } double max(double s[ ][4], int n, int i) { double a=0.0; int j; for (j=0;j<n;j++) { if (s[j][i]>a) { a = s[j][i]; } } return a; } double min(double s[ ][4], int n, int i) { double a=300.0; int j; for (j=0;j<n;j++) { if (s[j][i]<a) { a=s[j][i]; } } return a; } double avg(double s[ ][4], int n, int i) { double a = 0, t = 0; int j; for (j=0;j<n;j++) { a += s[j][i]; } t = a / n; return t; }运行结果:
#include<stdio.h> #include<time.h> #include<stdlib.h> void setdata(int a[8][8]); void out(int a[8][8]); void outDiagonal(int a[8][8]); void mine(int a[8][8], int x, int y); void change(int a[8][8]); int main() { int a[8][8], x, y; setdata(a); printf ("随机初始化完成\n"); printf ("随机输出8x8:\n"); out(a); printf ("输出对角线元素:\n"); outDiagonal(a); printf("输入一个位置:"); scanf ("%d %d", &x, &y); printf ("输出%d周围的元素:\n", a[x][y]); mine(a, x, y); printf ("输出改变规则后的棋盘:\n"); change(a); out(a); return 0; } //初始化数据 void setdata(int a[8][8]) { int i, j; srand(time(NULL)); for (i=0; i<8; i++) { for (j=0; j<8; j++) { a[i][j] = rand()%50+1; } } return; } //按行输出 void out(int a[8][8]) { int i, j; for (i=0; i<8; i++) { for (j=0; j<8; j++) { printf ("%d\t", a[i][j]); } printf ("\n"); } printf ("\n\n"); return; } //输出对角线的元素 void outDiagonal(int a[8][8]) { int i; printf ("从左上到右下为:"); for (i=0; i<8; i++) { printf ("%d\t", a[i][i]); } printf ("从右上到左下为:"); for (i=7; i>=0; i--) { printf ("%d\t", a[7-i][i]); } printf ("\n\n"); return; } //按扫雷游戏输出周围数字 void mine(int a[8][8], int x, int y) { int i, j, sum=0; for (i = x - 1; i <= x + 1; i++) { for (j = y - 1; j <= y + 1; j++) { if ((i >= 0) && (i <= 7) && (j >= 0) && (j <= 7) && !((i == x) && (j == y))) { sum += a[i][j]; printf ("%d\t", a[i][j]); } } } printf ("\n和为:%d", sum); printf ("\n\n"); return; } //题目规则 void change(int a[8][8]) { int i, j, t; for (i=1; i<8; i++) { for (j=0; j<8; j++) { t = j + 1; if (t > 7) { t = 0; } a[i][j] = a[i-1][j] + a[i-1][t]; } } printf ("\n"); return; }运行结果:
标签:
原文地址:http://blog.csdn.net/benjavan4641/article/details/51330585