ALGORITMO PARA SABER SI UNA PERSONA ES HOMBRE O MUJER

Categoría de Estructura Condicional Anidada


Algoritmo para saber si es masculino o femenino en PSeInt

💻 Hacer un código que ingrese una letra ya sea H o M y muestre su sexo según corresponda, hombre o mujer.


Algoritmo en pseint que muestre el sexo PSeInt Estricto : DESCARGA EL CÓDIGO

algoritmo que calcule el IGV

Algoritmo en pseint - short youtube

// 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
Algoritmo en pseint que muestre el sexo

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

código en python que muestra si es hombre o mujer Python :

// 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...")

código en Lenguaje C que muestra si Chile fue al Mundial Lenguaje C :

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

código en Dev C++ que indique el sexo de una persona Dev C++ :

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

Programar en Java NetBeans y mostrar si es masculino o femenino Java NetBeans :

// 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...");
            }
        }    
    }      
}



Facebook de www.programacion.work. Canal de Youtube de www.programacion.work. Twitter de www.programacion.work. TikTok de www.programacion.work.


Política de cookies

Política de Privacidad

Aviso Legal y Términos De Uso