ULISES DANIEL CAMPOS GUILLERMO
CATÁLOGO TEMA IV
PRACTICAS DE CLASE
ING. EN SISTEMAS COMPUTACIONALES
TECNM-MATAMOROS
1. Solicitar enteros para un vector de 10 elementos y visualizar el número menor y el mayor.
#include <iostream>
using namespace std;
//Solicitar enteros para un vector de 10 elementos y visualizar el número menor y el mayor.
//ULISES DANIEL CAMPOS GUILLERMO
main(){
int nums [10];
for (int i=0; i<10;i++){
cout<<"INGRESA UN NUMERO: ";
cin>>nums[i];
}
int max=nums [0], min=nums [0];
for (int i =0;i<10;i++){
if(nums[i]>=max){
max=nums[i];
}
if(nums[i]<=min){
min=nums [i];
}
}
cout<<"\n EL NUMERO MAYOR ES: "<<max;
cout<<"\n EL NUMERO MENOR ES: " <<min;
}
2. Solicitar n enteros para un vector y mostrar cuantos pares se ingresaron.
#include <iostream>
//Solicitar n enteros para un vector y mostrar cuantos pares se ingresaron.
//ULISES DANIEL CAMPOS GUILLERMO
using namespace std;
main (){
int tv,i,par=0;
cout<<"\n INGRESE LOS ELEMENTOS DEL VECTOR: ";
cin>>tv;
int v[tv];
for(i=0;i<tv;i++){
cout<<"["<<i+1<<"] INGRESE UN NUMERO: ";
cin>>v[i];
if(v[i]%2==0){
par++;
}
}
cout<<"\n LA CANTIDA DE NUMEROS PARES ES: "<<par;
}
3. Solicitar 10 enteros para un vector y mostrar cuantos son positivos, negativos y ceros.
#include <iostream>
using namespace std;
main (){
//Solicitar 10 enteros para un vector y mostrar cuantos son positivos, negativos y ceros.
//ULISES DANIEL CAMPOS GUILLERMO
int i, v[10], pos=0, neg=0, cero=0;
for(i=0;i<10;i++){
cout<<"["<<i+1<<"] INGRESE UN NUMERO: ";
cin>>v[i];
if(v[i]<0){
neg++;
}
if(v[i]>0){
pos++;
}
if(v[i]==0){
cero++;
}
}
cout<<"\n LA CANTIDA DE NUMEROS POSITIVOS ES: "<<pos;
cout<<"\n LA CANTIDA DE NUMEROS NEGATIVOS ES: "<<neg;
cout<<"\n LA CANTIDA DE NUMEROS CEROS ES: "<<cero;
}
4. Solicite enteros para llenar un vector de 5 elementos, visualice el vector en
forma horizontal y promedio.
#include <iostream>
#include <conio.h>
#include <iomanip>
//Solicite enteros para llenar un vector de 5 elementos, visualice el vector en forma
horizontal y promedio.
//ULISES DANIEL CAMPOS GUILLERMO
using namespace std;
main (){
int arreglo[5], i;
double p=0;
for(i=0;i<5;i++){
cout<<"["<<i+1<<"] INGRESA UN ELEMENTO PARA LLENAR EL VECTOR: ";
cin>>arreglo[i];
p=p+arreglo[i];
}
p=p/5;
cout<<"\nEL VECTOR ES: \n";
for(i=0;i<5;i++)
cout<<setw(5)<<arreglo[i];
cout<<"\n\nEL PROMEDIO ES: "<<p;
}
5. Solicitar datos para 2 Matrices de 3X3, almacenar la suma en una matriz resultante y visualizarla.
#include <iostream> cout<<"\nMATRIZ 1\n";
#include <conio.h> for(i=0; i<3;i++){
#include <iomanip> cout<<"\n";
for(j=0; j<3; j++){
//Solicitar datos para 2 Matrices de 3X3, almacenar la suma en una matriz resultante y visualizarla.
cout<<setw(4)<<M1[i][j];
//ULISES DANIEL CAMPOS GUILLERMO }
using namespace std; }
main (){
int M1[3][3], M2[3][3], suma[3][3], i=0, j=0; cout<<"\n\nMATRIZ 2\n";
for(i=0; i<3;i++){ for(i=0;i<3;i++){
cout<<"\n";
for(j=0; j<3; j++){
for(j=0; j<3; j++){
cout<<"INGRESA LOS VALORES PARA LA MATRIZ 1\t"; cout<<setw(4)<<M2[i][j];
cin>>M1[i][j]; }
} }
} cout<<"\n\n\nLA SUMA DE LAS DOS MATRICES ES: \n";
for(int x=0; x<3;x++){
cout<<"\n\n";
cout<<"\n";
for(i=0; i<3; i++){
for(int y=0; y<3; y++){
for(j=0; j<3; j++){ cout<<setw(4)<<(M1[x][y]+M2[x][y]);
cout<<"INGRESA LOS VALORES PARA LA MATRIZ 2\t"; }
cin>>M2[i][j]; }
} }
}
6. Realice y represente mediante un programa, que lea un arreglo de M filas y N columnas y que calcule la suma de los elementos de la diagonal principal.
#include <conio.h>
#include <iomanip>
using namespace std;
//ULISES DANIEL CAMPOS GUILLERMO
main (){
int f, c;
cout<<"INGRESA EL NUMERO DE FILAS\t";
cin>>f;
cout<<"INGRESA EL NUMERO DE COLUMNAS\t";
cin>>c;
int M1[f][c];
for(int i=0; i<f;i++){
for(int j=0; j<c; j++){
cout<<"INGRESA NUMEROS PARA LA MATRIZ \t";
cin>>M1[i][j];
}
}
cout<<"\n\n\nLA MATRIZ ES:\n";
for(int i=0; i<f;i++){
cout<<"\n";
for(int j=0; j<c; j++){
cout<<setw(4)<<(M1[i][j]);
}
}
int Suma=0;
for (int i=0;i<min(f,c);i++) {
Suma=Suma+M1[i][i];
}
cout<<"\nLA SUMA ES: "<<Suma;
}
7. Realice y represente mediante un programa, que lea un
arreglo de M filas y N columnas y que muestre ceros en la
diagonal principal. }
#include <iostream>
#include <conio.h> for (int i=0;i<min(f,c);i++) {
#include <iomanip> if(M1[i][i]>0){
//ULISES DANIEL CAMPOS GUILLERMO M1[i][i]=M1[i][i]-M1[i][i];
using namespace std; }
main (){ }
int f, c;
cout<<"\n\n\nLA MATRIZ ES:\n";
cout<<"INGRESA EL NUMERO DE FILAS\t"; for(int i=0; i<f;i++){
cin>>f; cout<<"\n";
cout<<"INGRESA EL NUMERO DE COLUMNAS\t"; for(int j=0; j<c; j++){
cin>>c; cout<<setw(4)<<(M1[i][j]);
}
int M1[f][c]; }
for(int i=0; i<f;i++){
for(int j=0; j<c; j++){ }
cout<<"INGRESA NUMEROS PARA LA MATRIZ \t";
cin>>M1[i][j];
}