用c++生成一个5*5的随机数矩阵,输出最大,最小值

如题所述

#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;

int main()
{
 srand(unsigned (time(NULL)));   ///初始化随机种子 
 int array[5][5];
 int max,min;
 int i,j;
 for(i=0;i<5;i++)
  for(j=0;j<5;j++)
   array[i][j]=rand();   ///随机数 

 cout<<"随机生成的5*5的数列为"<<endl;
 cout<<endl;
 max=min=array[0][0];
 for(i=0;i<5;i++)
 {
  for(int j=0;j<5;j++)
  {
   cout<<array[i][j]<<"\t";
   if(array[i][j]> max)
       max = array[i][j];
   if(array[i][j] < min)
      min = array[i][j];
  }
  cout<<endl;
 }

 cout<<"max="<<max<<",min="<<min<<endl;
 cin.get();
 return 0;
}

温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答