Beruflich Dokumente
Kultur Dokumente
for(int i=0;i<N;i++)
cout<<S[i]<<' ';
cout<<']';
cout<<endl;break;
case 2:
N=rand()%11;
M=rand()%11;
cout<<"\nLos valores generados=\n"<<"N= "<<N<<endl
<<"M= "<<M<<endl;
if(N==0){
cout<<"No existe Vector ";
system("pause");
exit(1);
}
else if(M==0){
cout<<"No existe vector ";
system("pause");
exit(1);
}
else if(N!=M){
cout<<"No existe operaciones de vectores"<<endl;
system("pause");
exit(1);
}
else
for(int i=0;i<N;i++){
A[i]=rand()%21;
cout<<A[i]<<' ';
}
cout<<endl;
for(int i=0;i<M;i++){
B[i]=rand()%21;
cout<<B[i]<<' ';
}
cout<<endl;
for(int i=0;i<N;i++)
S[i]=A[i]-B[i];
cout<<endl<<"\nLa suma= ["<<endl;
for(int i=0;i<N;i++)
cout<<S[i]<<' ';
cout<<']';break;
case 5: exit(1);break;
//cin>>rp;
//}while(rp=='S');
system("pause");
}
//for(int i=0;i<N;i++)
A[i]=A[i]*neg;
}
cout<<'[';
for(int i=0;i<N;i++)
cout<<A[i]<<' ';
cout<<']'<<endl;
system("pause");
}
*/
//Matriz con valores positivos y negativos
//Otra forma
#include<iostream>
#include<stdlib.h>
#include<time.h>
#include<iomanip>
using namespace std;
int main(){
srand((unsigned)time(NULL));
int fil,col,Ma[100][100],neg,F;
cout<<"Ingrese el numero de filas fil= ";
cin>>fil;
cout<<"Ingrese el numero de filas col= ";
cin>>col;
for(int i=0;i<fil;i++){
for(int j=0;j<col;j++){
Ma[i][j]=rand()%51;
F=rand()%2;
if(F==0)
neg=-1;
else
neg=1;
Ma[i][j]=Ma[i][j]*neg;
}
}
for(int i=0;i<fil;i++){
for(int j=0;j<col;j++){
cout<<setw(3)<<Ma[i][j]<<' ';}
cout<<endl;
}
system("pause");
return 0;
}