#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
fstream file1("data.txt", ios::in), file2("example1.cpp", ios::out);
string data ;
string result;
file1 >> data;
for(int i = 0; i < data.size(); i++)
if(isalpha(data[i]))
result += data[i];
cout << result << " size :" << result.size() << endl;
file1.close();
file2 << result;
file2.close();
}
追问请编写一个函数void fun(int tt[M][N],int pp[N]),tt指向一个M行N列的二维数组,求出二维数组每列中最大元素,并依次放入pp所指一维数组中。二维数组中的元素值在主函数中随机产生(值域范围[1, 9])。
麻烦你帮我解决一下这个问题吧,一起算分给你阿,麻烦了
追答#include <iostream>
#include <cstdlib>
#define M 10
#define N 10
using namespace std;
void fun(int tt[M][N], int pp[N])
{
int i, j, max;
for(j = 0; j < N; j ++)
{
max = tt[0][j];
for(i = 1; i < M; i++)
if(tt[i][j] > max)
max = tt[i][j];
pp[j] = max;
}
}
void print(int pp[N])
{
int i;
for(i = 0; i < N ; i++)
cout << pp[i] << " ";
cout << endl;
}
int main()
{
int tt[M][N], pp[N];
int i, j;
for(i = 0; i < M; i++)
for(j = 0; j < N; j++)
tt[i][j] = rand() % 9 + 1;
fun(tt, pp);
print(pp);
}