1. REALIZAR UN PROGRAMA EN EL QUE EL USUARIO INGRESE LA CANTIDAD DE FILAS Y COLUMNAS PARA LA MATRIZ. LUEGO INGRESAR UN NUMERO QUE SE BUSCARA EN LA MATRIZ Y SI ESTA, ENTONCES MOSTRARA UN MENSAJE QUE DIGA SI 'EXISTE' Y LA POSICIÓN DE AQUEL NÚMERO.
#include<conio.h>
#include<iostream.h>
#include<string>
void main(){
int f,c, A[50][50],num,f1=-1,c1=-1,cont=-1;
string rpta="";
//variables para la posicion de la matriz
int x=5, y=8;
cout<<"Ingrese el num. de filas: ";
cin>>f;
cout<<"Ingrese el num. de columnas";
cin>>c;
for(int i=0; i<f; i++){
for(int j=0; j<c; j++){
gotoxy(x,y);cin>>A[i][j];
x+=5;
}
x=5,y+=2;
}
cout<<"\nNumero a buscar: ";
cin>>num;
//proceso en donde buscamos a 'num' y obtenemos la posicion.
for(int i=0; i<f; i++){
for(int j=0; j<c; j++){
if(A[i][j]==num){
rpta="Existe";
f1=i;
c1=j;
cont=1;
}
}
if(cont==1){
break;
}
}
cout<<"\nEl numero: "<<rpta;
cout<<"\nPosicion: "<<"["<<f1<<"]"<<"["<<c1<<"]";
getch();
}
EXPLICATION: Para este ejercicio solo hay que comparar por medio de un 'if' dentro de la matriz.
2. REALIZAR UN PROGRAMA QUE PERMITA INGRESAR EL ORDEN DE UNA MATRIZ Y DADOS LOS NÚMEROS INGRESADOS PARA LA MATRIZ, OBTENER LA CANTIDAD DE NUMERO PARES E IMPARES.
#include<iostream.h>
#include<conio.h>
void main(){
int f,c,A[50][50];
int par=0, imp=0;
//variables para la posicion de la matriz
int x=5, y=6;
cout<<"Ingrese num de filas: ";
cin>>f;
cout<<"Ingrese num. de columnas: ";
cin>>c;
for(int i=0; i<f; i++){
for(int j=0; j<c; j++){
gotoxy(x,y);cin>>A[i][j];
x+=5;
}
x=5,y+=2;
}
//Analizando los numeros que son pares e impares
for(int i=0; i<f; i++){
for(int j=0; j<c; j++){
if(A[i][j]%2==0){
par++;
}
else
imp++;
}
}
cout<<"\nNumeros pares: "<<par;
cout<<"\nNumeros impares: "<<imp;
getch();
}
EXPLICATION: Para identificar un número par, solo tenemos que hallar el resto de un número, si es 0 entonces el número es par, de lo contrario si el resto del número con 2 es diferente de 0 entonces es número impar.
No hay comentarios:
Publicar un comentario