Технология программирования
C++
Главная »
2016 » Март » 11 » M6 23a
|
#include <iostream>
#include <ctime>
using namespace std;
int main()
{
setlocale(LC_ALL,"rus_rus.1251");
srand(time(0));
const double pi=3.1415926535897;
const int n=25;
const int m=10;
double a[n][m];
double b[n];
//матрица
for (int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
a[i][j]=(rand()%60)/pi-10;
}
}
//вывод матрицы
cout.setf(ios::fixed);
cout.width(7);
cout.precision(2);
cout<<"Матрица A:"<<endl;
for (int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
cout<<a[i][j]<<" ";
}
cout<<endl;
}
bool flag;
double c;
//обработка матрицы
for (int i=0;i<n;i++)
{
flag=false;
for(int j=0;j<m;j++)
{
if (a[i][j]>0)
{
flag=true;
c=a[i][j];
break;
}
}
if (flag==false)
b[i]=1;
else b[i]=c;
}
//вывод массива
cout.setf(ios::fixed);
cout.width(7);
cout.precision(2);
cout<<"Массив B:"<<endl;
for (int i=0;i<n;i++)
{
cout<<b[i]<<endl;
}
system("pause");
return 0;
}
|
Просмотров: 306 |
Добавил: denjes
| Рейтинг: 0.0/0 |