Categoría de Estructura Condicional Simple
💻 Hacer un programa dónde se ingrese un número entero de 3 cifras y muestre si es o no, un número capicúa. Se enciende como un número capicúa cuando al intercambiar los valores de sus extremos nos da el mismo valor. Ejemplo : 242, 131, 565, etc.
Un número capicúa o capicúa es aquel que al intercambiar sus valores nos da el mismo número; en este caso vamos a descomponer el número obteniendo la unidad, decena y centena para luego intercambiar sus valores y compararlos con el valor inicial.
ANÁLISIS DEL CÓDIGO
Un número capicúa es aquel que al intercambiar sus valores nos da el mismo número; vamos a descomponer el número y obtener la unidad, decena y centena
para luego intercambiar sus valores y compararlos con el valor inicial..
VARIABLES ENTRADA :
Num = Guarda un número
C1 = Obtiene el cociente de 3 cifras (Unidad)
R1 = Obtiene el residuo de 3 cifras ()
C2 = Obtiene el cociente de 2 cifras (Decena)
R2 = Obtiene el residuo de 2 cifras (Centena)
INGRESO : Se solicita un número.
PROCESO : Hace el calculo de descomponer el número en unidad, decena y centena. luego compara esa descomposición con el número inicial.
SALIDA : Si son iguales muestra – Número Capicúa – Sino – No es Capicúa.
Algoritmo programacion_work
Definir num, C1, R1, C2, R2, XNUM como Entero;
Escribir "MOSTRAR SI UN NÚMERO ES CAPICÚA.";
Escribir " ";
Escribir Sin Saltar "Ingrese Número de 3 cífras : ";
Leer num;
C1 <- (num - (num MOD 100)) / 100;
R1 <- num MOD 100;
C2 <- (R1 - (R1 MOD 10)) / 10;
R2 <- R1 MOD 10;
XNUM <- ((R2 * 100) + (C2 * 10) + C1);
Escribir " ";
Si num == XNUM Entonces
Escribir "NÚMERO CAPICÚA";
SiNo
Escribir "NO ES CAPICÚA";
FinSi
FinAlgoritmo
print("MOSTRAR SI ES UN NÚMERO DE 3 CÍFRAS ES CAPICÚA.")
XNUM=0
num = int(input("Ingrese Número : "))
C1 = (num-(num%100))/100
R1 = num%100
C2 = (R1-(R1%10))/10
R2 = R1%10
XNUM=((R2*100)+(C2*10)+C1)
if num==XNUM:
print("NÚMERO CAPICÚA")
else:
print("NO ES CAPICÚA")
#include<stdio.h>
int main() {
int c1, c2, num, r1, r2;
printf("MOSTRAR SI UN NUMERO ES CAPICUA.\n\n");
printf("Ingrese Numero : ");
scanf("%i",&num);
c1 = (num-(num%100))/100;
r1 = num%100;
c2 = (r1-(r1%10))/10;
r2 = r1%10;
if (num==((r2*100)+(c2*10)+c1)) {
printf("\nNUMERO CAPICUA\n");
} else {
printf("\nNUMERO NO CAPICUA\n");
}
return 0;
}
#include<iostream>
using namespace std;
int main() {
int num, C1=0, C2=0, R1=0, R2=0, XNUM=0;
cout << "MOSTRAR SI UN NUMERO ES CAPICUA.\n\n";
cout << "Ingrese Numero de 3 cifras : ";
cin << num;
C1 = (num-(num%100))/100;
R1 = num%100;
C2 = (R1-(R1%10))/10;
R2 = R1%10;
cout << endl;
XNUM = ((R2*100)+(C2*10)+C1);
if (num==XNUM) {
cout << "SI ES NUMERO CAPICUA" << endl;
} else {
cout << "EL NUMERO NO ES CAPICUA" << endl;
}
return 0;
}
using System;
using System.Collections.Generic;
using System.Text;
namespace programacion_work
{
class numero_capicua
{
static void Main(string[] args)
{
int c1, c2, num, r1, r2;
Console.WriteLine("MOSTRAR SI UN NUMERO ES CAPICUA.\n");
Console.Write("Ingrese Numero : ");
num = int.Parse(Console.ReadLine());
c1 = (num - (num % 100)) / 100;
r1 = num % 100;
c2 = (r1 - (r1 % 10)) / 10;
r2 = r1 % 10;
if (num == ((r2 * 100) + (c2 * 10) + c1))
{
Console.WriteLine("\nNUMERO CAPICUA");
}
else
{
Console.WriteLine("\nNUMERO NO CAPICUA");
}
Console.ReadLine();
}
}
}
package programacion_work;
import java.util.Scanner;
public class ver_capicua {
public static void main(String[] args) {
Scanner ingreso=new Scanner(System.in);
int num, C1,R1,C2,R2,XNUM=0;
System.out.print("MOSTRAR SI ES UN NÚMERO ES CAPICÚA.\n\n");
System.out.print("Ingrese número de 3 cifras : ");
num = Integer.parseInt(ingreso.next());
C1 = num / 100;
R1 = num - (C1 * 100);
C2 = R1 / 10;
R2 = R1 - (C2 * 10);
XNUM = ((((R2*10)+C2)*10)+C1);
if(num == XNUM){
System.out.println("ES CAPICÚA");
}else{
System.out.println("NO ES CAPICÚO");
}
}
}
private void jBtn_CalcularActionPerformed(java.awt.event.ActionEvent evt) {
int num, C1,R1,C2,R2;
num = Integer.parseInt(jTxt_Num.getText());
C1 = num / 100;
R1 = num - (C1 * 100);
C2 = R1 / 10;
R2 = R1 - (C2 * 10);
if(num == ((((R2*10)+C2)*10)+C1)){
JLbl_Msg.setText("NÚMERO CAPICÚO");
}else{
JLbl_Msg.setText("NÚMERO NO CAPICÚO");
}
}
Imports System.Console
Imports System.Math
Module numero_capicua
Dim Num, C1, C2, R1, R2 As Integer
Sub Main()
WriteLine("MOSTRAR SI UN NÚMERO ES CAPICÚA.")
WriteLine("")
Write("Ingrese Número de 3 Cifras : ")
Num = ReadLine()
WriteLine("")
C1 = Num \ 100
R1 = Num - (C1 * 100)
C2 = R1 \ 10
R2 = R1 - (C2 * 10)
If (Num = ((R2 * 100) + (C2 * 10) + C1)) Then
WriteLine("NÚMERO CAPICÚA")
Else
WriteLine("NÚMERO NO CAPICÚA")
End If
ReadLine()
End Sub
End Module
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim Num, C1, C2, R1, R2 As Integer
Num = Txt_Num.Text
C1 = Num \ 100
R1 = Num - (C1 * 100)
C2 = R1 \ 10
R2 = R1 - (C2 * 10)
If (Num = ((R2 * 100) + (C2 * 10) + C1)) Then
Lbl_msg.Text = "NÚMERO CAPICÚA"
Else
Lbl_msg.Text = "NÚMERO NO CAPICÚA"
End If
End Sub
Sub Capicua()
Dim Num, C1, R1, C2, R2, xNUM As Integer
Num = Range("D12").Value
C1 = (Num - (Num Mod 100)) / 100
R1 = Num Mod 100
C2 = (R1 - (R1 Mod 10)) / 10
R2 = R1 Mod 10
xNUM = ((R2 * 100) + (C2 * 10) + C1)
If (Num = xNUM) Then
Range("G12").Value = "NÚMERO CAPICÚA"
Else
Range("G12").Value = "NÚMERO NO CAPICÚA"
End If
End Sub
Sub Capicua2()
Dim Num, C1, R1, C2, R2, xNUM As Integer
Num = InputBox("INGRESE NÚMERO ")
C1 = (Num - (Num Mod 100)) / 100
R1 = Num Mod 100
C2 = (R1 - (R1 Mod 10)) / 10
R2 = R1 Mod 10
xNUM = ((R2 * 100) + (C2 * 10) + C1)
If (Num = xNUM) Then
MsgBox "NÚMERO CAPICÚA"
Else
MsgBox "NÚMERO NO CAPICÚA"
End If
End Sub
Private Sub btn_calcular_Click()
Dim Num, C1, R1, C2, R2, xNUM As Integer
Num = txt_num.Text
C1 = (Num - (Num Mod 100)) / 100
R1 = Num Mod 100
C2 = (R1 - (R1 Mod 10)) / 10
R2 = R1 Mod 10
xNUM = ((R2 * 100) + (C2 * 10) + C1)
If (Num = xNUM) Then
txt_result.Text = "NÚMERO CAPICÚA"
Else
txt_result.Text = "NÚMERO NO CAPICÚA"
End If
End Sub