Читайте также:
|
|
#include <iostream>
using namespace std;
void main()
{ const int N=25;
float k=0,m,n; float y[N]; cout<<"vvedite znachenia"<<endl;
for (int i = 0; i<N; i++) {cin>>y[i];}
float x=0; cout<<"vvedite znachenia x"<<endl;
cin>>x k=abs(x-(y[0]+y[1])/2);
for(int i=0;i<N;i++)
{for(int j=1;j<N;j++)
{if(k>abs(x-(y[i]+y[j])/2)){k=abs(x-(y[i]+y[j])/2); m=i;n=j; } } }
cout<<"m="<<m<<"n="<<n<<endl;}
23) Given a real number n. Get a real square matrix, where i = 1, n, j = 1, n and
include<iostream.h>
int main()
{int i=1,j=1,n;
double a[100][100],m;
cin>>n;
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
{m=i+j;m=1/m;a[i][j]=m;}
for(i=1;i<=n;i++)
{for(j=1;j<=n;j++)
cout<<a[i][j]<<" ";cout<<endl;}
system("pause"); return 0;}
Given a real square matrix of order 12. Replace with zeros elements on the diagonal and above it.
#include<iostream.h>
void main()
{ int i,j; int a[100][100];
for(i=0;i<12;i++)
for(j=0;j<12;j++)
a[i][j]=rand()%10;
for(i=0;i<12;i++)
{ for(j=0;j<12;j++)
cout<<a[i][j]<<" "; cout<<endl; }
for(i=0;i<12;i++)
{ for(j=0;j<12;j++)
{ if(j>=i) a[i][j]=0; } }
for(i=0;i<12;i++)
{ for(j=0;j<12;j++) cout<<a[i][j]<<" "; cout<<endl; } system("pause"); }
Given a real square matrix of order mxn. Determine the numbers b1,.., bm, which are equal to the sum of the elements of the corresponding row.
#include<iostream.h>
int main()
{ int i,j,m,n,k=0; int a[100][100],b[100];
cin>>m;
for(i=0;i<m;i++) for(j=0;j<m;j++) a[i][j]=rand()%10;
for(i=0;i<m;i++) { for(j=0;j<m;j++) cout<<a[i][j]<<" "; cout<<endl; }
for(k=0;k<m;k++)
b[k]=0; k=0;
for(i=0;i<m;i++)
{ for(j=0;j<m;j++) { k+=a[i][j]; if(j==m-1)
{ cout<<k<<endl; k=0; } } }
system("pause"); return 0;}
Given a real square matrix of order mxn. Determine the numbers b1,.., bm, which are equal to the product of the elements of the corresponding row.
#include<iostream.h>
int main()
{ int i,j,m,n,k=1;
int a[100][100],b[100];
cin>>m;
for(i=0;i<m;i++)
for(j=0;j<m;j++)
a[i][j]=rand()%10;
for(i=0;i<m;i++)
{ for(j=0;j<m;j++)
cout<<a[i][j]<<" ";
cout<<endl; }
k=1;
for(i=0;i<m;i++)
{ for(j=0;j<m;j++)
{ k*=a[i][j];
if(j==m-1)
{ cout<<k<<endl; k=1; } } }
system("pause");
return 0;}
Дата добавления: 2015-11-16; просмотров: 64 | Нарушение авторских прав
<== предыдущая страница | | | следующая страница ==> |
Given a positive integer n, the integers a1, ..., an. Find the number and the sum of the members of the sequence that are divisible by 3 and not divisible by 5. | | | Объектно-ориентированное программирование |