📄 c++实验4.txt
字号:
#include <iostream.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#define LINE 5 /*定义行*/
#define N 6 /*定义列*/
void getdata ( int (*sp)[N])
{int random,i,j;
for (i=0;i<LINE;i++)
{for (j=0;j<N;j++)
{random=rand();
while (random<0 || random>100) random=rand();
*(*(sp+i)+j)=random;}}
}
void lineavg ( int s[][N],float *a,float *b)
{float tmp;
int i,j;
for (i=0;i<LINE;i++)
{tmp=0;
for (j=0;j<N;j++) tmp+=s[i][j];
tmp/=N; *(a+i)=tmp;}
for (i=0;i<N;i++)
{tmp=0;
for (j=0;j<LINE;j++) tmp+=s[j][i];
tmp/=LINE;*(b+i)=tmp;}
}
void main()
{
float a[LINE],b[N];
int r[LINE][N];
int i,j;
srand( (unsigned)time( NULL ) );
getdata(r);
lineavg(r,a,b);
for (i=0;i<LINE;i++)
{for (j=0;j<N;j++) cout<<" "<<*(*(r+i)+j);
cout<<endl;}
cout<<endl;
for (i=0;i<LINE;i++) cout<<a[i]<<" ";
cout<<endl;
for (i=0;i<N;i++) cout<<b[i]<<" ";
cout<<endl;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -