💻 Hacer un programa que permita mostrar si número ingresado es par o impar, usando el operador matemático de residuo.
¿Cómo determinar si un número es par?
¿Cómo determinar si un número es par?
Un número divisible por 2 dónde su residuo sea cero es un número par, sino es impar.
ANÁLISIS DEL CÓDIGO
VARIABLES A USAR :
Num = Guarda un número ingresado por teclado.
INGRESO : Ingresar un número entero.
PROCESO : Obtener residuo del número ingresado entre 2, si el residuo es igual a 0, mostra PAR sino IMPAR.
SALIDA : Mostrar si es PAR o IMPAR.
Algoritmo programacion_work
Definir num, residuo como Entero;
Escribir Sin Saltar "Ingrese Número : ";
Leer num;
residuo <- num - (Trunc(num / 2) * 2);
Si (residuo == 0) Entonces
Escribir "NÚMERO PAR";
SiNo
Escribir "NÚMERO IMPAR";
FinSi
FinAlgoritmo
def mostrarpar(num):
residuo = num - ((num//2) * 2)
if (residuo == 0):
print("NÚMERO PAR")
else:
print("NÚMERO IMPAR")
num = int(input("Ingrese Número : "))
mostrarpar(num)
#include<stdio.h>
int main() {
int num;
printf("16. MOSTRAR SI ES PAR O IMPAR.\n\n");
printf("Ingrese Numero : ");
scanf("%i",&num);
if ((num%2)==0) {
printf("\nNUMERO PAR\n");
} else {
printf("\nNUMERO IMPAR\n");
}
return 0;
}
#include<iostream>
using namespace std;
int main() {
int num;
cout << "16. MOSTRAR SI UN NUMERO ES PAR O IMPAR.\n\n";
cout << "Ingrese Numero : ";
cin << num;
cout << endl;
if ((num%2)==0) {
cout << "NUMERO PAR" << endl;
} else {
cout << "NUMERO IMPAR" << endl;
}
return 0;
}
using System;
using System.Collections.Generic;
using System.Text;
namespace programacion_work
{
class par_o_impar
{
static void Main(string[] args)
{
int num;
Console.WriteLine("16. MOSTRAR SI UN NUMERO ES PAR O IMPAR.\n");
Console.Write("Ingrese Numero : ");
num = int.Parse(Console.ReadLine());
if ((num % 2) == 0)
{
Console.WriteLine("\nNUMERO PAR");
}
else
{
Console.WriteLine("\nNUMERO IMPAR");
}
Console.ReadLine();
}
}
}
package programacion_work;
import java.util.Scanner;
public class par_impar {
public static void main(String[] args) {
Scanner ingreso=new Scanner(System.in);
int num;
System.out.print("16. MOSTRAR SI ES PAR O IMPAR.\n\n");
System.out.print("Ingrese Número : ");
num = Integer.parseInt(ingreso.next());
if((num % 2)== 0 ){
System.out.println("NÚMERO PAR");
}else{
System.out.println("NÚMERO IMPAR");
}
}
}
private void jBtn_CalcularActionPerformed(java.awt.event.ActionEvent evt) {
int num;
num = Integer.parseInt(jTxt_num.getText());
if( (num % 2)== 0 ){
jLbl_Msg.setText("PAR");
}else{
jLbl_Msg.setText("IMPAR");
}
}
Imports System.Console
Module numero_par_o_impar
Dim Num As Integer
Sub Main()
WriteLine("16. MOSTRAR SI ES PAR O IMPAR USANDO OPERADOR DE RESIDUO.")
WriteLine("")
Write("Ingrese Número : ")
Num = ReadLine()
WriteLine("")
If ((Num Mod 2) = 0) Then
WriteLine("NÚMERO PAR")
Else
WriteLine("NÚMERO IMPAR")
End If
ReadLine()
End Sub
End Module
Private Sub Btn_Calcular_Click(sender As Object, e As EventArgs) Handles Btn_Calcular.Click
Dim Num As Integer
Num = Txt_Num.Text
If ((Num Mod 2) = 0) Then
Lbl_msg.Text = "NÚMERO PAR"
Else
Lbl_msg.Text = "NÚMERO IMPAR"
End If
End Sub
Sub Par()
Dim Num As Integer
Num = Range("C12").Value
If ((Num Mod 2) = 0) Then
Range("G12").Value = "NÚMERO PAR"
Else
Range("G12").Value = "NÚMERO IMPAR"
End If
End Sub
Sub Par()
Dim Num As Integer
Num = Range("C12").Value
If ((Num Mod 2) = 0) Then
Range("G12").Value = "NÚMERO PAR"
Else
Range("G12").Value = "NÚMERO IMPAR"
End If
End Sub
Private Sub btn_calcular_Click()
Dim Num As Integer
Num = txt_num.Text
If ((Num Mod 2) = 0) Then
txt_result.Text = "NÚMERO PAR"
Else
txt_result.Text = "NÚMERO IMPAR"
End If
End Sub