💻 Hacer un código que ingrese una letra ya sea H o M y muestre su sexo según corresponda, hombre o mujer.
// CASO 1 : Usando funcion de cadena - MAYUSCULAS()
Algoritmo programacion_work
// Muestra el mensaje hombre o mujer
Definir sexo como Caracter;
Escribir Sin Saltar "INGRESE UNA LETRA [ H - M ] : ";
Leer sexo;
Si (MAYUSCULAS(sexo) == "H") Entonces
Escribir "HOMBRE";
SiNo
Si (MAYUSCULAS(sexo) == "M") Entonces
Escribir "MUJER";
SiNo
Escribir "ERROR...";
FinSi
FinSi
FinAlgoritmo
// CASO 2 : Usando condicional múltiple y anidada, para no usar la función que convierta la letra a MAYUSCULAS.
Algoritmo programacion_work
Definir sexo como Caracter;
Escribir Sin Saltar "INGRESE UNA LETRA [ H - M ] : ";
Leer sexo;
Si (sexo == "H" o sexo == "h") Entonces
Escribir "HOMBRE";
SiNo
Si (sexo == "M" o sexo == "m") Entonces
Escribir "MUJER";
SiNo
Escribir "ERROR...";
FinSi
FinSi
FinAlgoritmo
// CASO 1 : Usando función de cadena para convertir a mayúsculas - upper()
sexo = input("INGRESE SEXO [ H - M ] : ")
if sexo.upper() == "H":
print("HOMBRE")
elif sexo.upper() == "M":
print("MUJER")
else:
print("ERROR...")
// CASO 2 : Usando condicional múltiple y anidada
sexo = input("INGRESE SEXO [ H - M ] : ")
if sexo == "H" or sexo == "h":
print("HOMBRE")
elif sexo == "M" or sexo == "m":
print("MUJER")
else:
print("ERROR...")
#include<stdio.h>
#include<string.h>
#define MAX_STRLEN 256
int main() {
char sexo[MAX_STRLEN];
printf("01. MUESTRE SI ES HOMBRE O MUJER INGRESANDO UNA LETRA.\n\n");
printf("INGRESE SEXO [ H - M ] : ");
scanf("%s",sexo);
if(strcmp(sexo,"H") != 1){
printf("\nHOMBRE");
}else{
if(strcmp(sexo,"M") != 1){
printf("\nMUJER");
}else{
printf("\nERROR...");
}
}
return 0;
}
// CASO 1 : Usando función de cadena para convertir a mayúsculas - toupper()
#include<iostream>
using namespace std;
int main() {
string sexo;
cout << "01. MUESTRE SI ES HOMBRE O MUJER INGRESANDO UNA LETRA." << endl;
cout << "INGRESE SEXO [ H - M ] : ";
cin >> sexo;
sexo[0] = toupper(sexo[0]);
if (sexo == "H"){
cout << "HOMBRE" << endl;
}else{
if (sexo == "M"){
cout << "MUJER" << endl;
}else{
cout << "ERROR..." << endl;
}
}
return 0;
}
// CASO 2 : Usando condicional múltiple y anidada
#include<iostream>
using namespace std;
int main() {
string sexo;
cout << "INGRESE SEXO [ H - M ] : ";
cin >> sexo;
if (sexo == "H" || sexo == "h"){
cout << "HOMBRE" << endl;
}else{
if (sexo == "M" || sexo == "m"){
cout << "MUJER" << endl;
}else{
cout << "ERROR..." << endl;
}
}
return 0;
}
// CASO 1 : Función de cadena para convertir a mayúsculas - toUpperCase()
package programacion_work;
import java.util.Scanner;
public class mostrar_hombre_mujer {
public static void main(String[] args) {
String sexo;
Scanner ingreso=new Scanner(System.in);
System.out.print("INGRESE SEXO [ H - M ] : ");
sexo = ingreso.next();
if((sexo.toUpperCase()).equals("H")){
System.out.println("HOMBRE");
}else{
if((sexo.toUpperCase()).equals("M")){
System.out.println("MUJER");
}else{
System.out.println("ERROR...");
}
}
}
}
// CASO 2 : Usando condicional múltiple y anidada
package programacion_work;
import java.util.Scanner;
public class mostrar_hombre_mujer {
public static void main(String[] args) {
String sexo;
Scanner ingreso=new Scanner(System.in);
System.out.print("INGRESE SEXO [ H - M ] : ");
sexo = ingreso.next();
if(sexo.equals("H") || sexo.equals("h")){
System.out.println("HOMBRE");
}else{
if(sexo.equals("M") || sexo.equals("m")){
System.out.println("MUJER");
}else{
System.out.println("ERROR...");
}
}
}
}