0
No.5 Lab 5_матрицы
Posted by ေမၿမဳိ့သား
on
7:17 AM
in
C++ No.5 for 2nd year
Qus==>> В данной
целочисленной матрице 5x7 заменить каждый элемент строки на среднее
арифметическое значение этой строки.
#include "stdafx.h"
#include<iostream>
#include<conio.h>
#include<iomanip>
#include<stdlib.h>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int i,j;
const int row=5,col=7;
int soe[row][col];
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
soe[i][j]=rand()%50+5;
cout<<setw(5)<<soe[i][j];
//sum=sum+soe[i][j];
}
cout<<"\n\n\n";
}
//cout<<"\n\n MATRIX ALL's SUM===>>"<<sum;
int moe[20];
int sum=0;
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
sum=sum+soe[i][j];
moe[i]=sum;
}
cout<<"EVERY ROW====>>>";
getch();
return 0;
}
#include "stdafx.h"
#include<iostream>
#include<conio.h>
#include<iomanip>
#include<stdlib.h>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int i,j;
const int row=5,col=7;
int soe[row][col];
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
soe[i][j]=rand()%50+5;
cout<<setw(5)<<soe[i][j];
//sum=sum+soe[i][j];
}
cout<<"\n\n\n";
}
//cout<<"\n\n MATRIX ALL's SUM===>>"<<sum;
int moe[20];
int sum=0;
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
sum=sum+soe[i][j];
moe[i]=sum;
}
cout<<"EVERY ROW====>>>";
getch();
return 0;
}
Post a Comment