Sei sulla pagina 1di 4

/*

//Operaciones con vectores


#include<iostream>
#include<stdlib.h>
#include<time.h>
# define mensaje "\n Otra Prueba[S][N]"
using namespace std;
void main(){
srand((unsigned)time(NULL));
int N,M,A[100],B[100],S[100],opcion;char rp;
//do{system("cls");
cout<<"[1] Suma A[]+B[]"<<endl
<<"[2] Diferencia A[]-B[]"<<endl
<<"[3] Producto A[]*B[] "<<endl
<<"[4] Cociente A[]/B[]"<<endl
<<"[5] Salir "<<endl;
cout<<"Ingrese su opcion ";
cin>>opcion;
switch(opcion){
case 1:
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<<']';
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;

default:cout<<"No es una opcion";


}
//cout<<mensaje;

//cin>>rp;
//}while(rp=='S');

system("pause");
}

//Vector con valores negativos


//Otra forma
#include<iostream>
#include<stdlib.h>
#include<time.h>
using namespace std;
void main(){
srand((unsigned)time(NULL));
int A[100],F,neg,pos,N;
cout<<"Ingrese el numero de elementos N= ";
cin>>N;
for(int i=0;i<N;i++){
A[i]=rand()%21;
F=rand()%2;
if(F==0)
neg=-1;
else
neg=1;

//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;
}

Potrebbero piacerti anche