⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 c++实验4.txt

📁 数据结构课堂实验 集中了数据结构,线性表,连表,栈,队列,二叉树,图,排序算法,查找算法的实现
💻 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 + -