💻 Hacer un algoritmo donde se ingrese un número, si tiene una cifra muestre lo mínimo que le falta para ser de 2 cifras; de lo contrario muestre lo mínimo que le falta para ser un número de 3 cifras. Considerar que el usuario ingresa números de hasta dos cifras.
Para resolver este ejercicio tenemos que hacer una condición anidada, se debe preguntar que el número ingresado no sea mayor de tres cifras y consultar si es de una cifra, si se da el caso completamos el valor restando diez menos el valor ingresado para que sea de dos cifras o lo requerido para completar que sea de tres cifras.
ANÁLISIS DEL CÓDIGO
VARIABLES ENTRADA :
num = Guarda un monto ingresado por teclado.
INGRESO : Ingresa un número (num).
PROCESO : Si es mayor a 99 muestra error, si es menor a 10 se calcula lo que falta para 2 cifras, de lo contrario lo que falta para 3 cifras.
SALIDA : Mostrar el valor faltante para 2 o 3 cifras.
Algoritmo programacion_work
Definir num como Entero;
Escribir "INGRESA UN NÚMERO, MUESTRA LO RESTANTE PARA 2 o 3 CIFRAS.";
Escribir " ";
Escribir Sin Saltar "NUMERO : ";
Leer num;
Si num > 99 Entonces
Escribir "ERROR... EL NUMERO SUPERA LAS 2 CIFRAS";
SiNo
Si num < 10 Entonces
Escribir "LE FALTA ", 10-num ," PARA 2 CIFRAS";
SiNo
Escribir "LE FALTA ", 100-num ," PARA 3 CIFRAS";
FinSi
FinSi
FinAlgoritmo
print("INGRESA UN NÚMERO Y MUESTRA LO QUE FALTA PARA 2 o 3 CIFRAS.")
num = int(input("INGRESE NÚMERO : "))
if num > 99:
print("Error el número supera las 2 cífras.")
elif num < 10:
print("LE FALTA ", 10-num, " PARA 2 CIFRAS.")
else:
print("LE FALTA ", 100-num, " PARA 3 CIFRAS.")
#include<stdio.h>
int main() {
int num, cifras;
printf("11. MUESTRE LO FALTANTE PARA 2 o 3 CIFRAS.\n\n");
printf("Ingrese Numero : ");
scanf("%i",&num);
if (num > 99) {
printf("\nERROR... EL NUMERO SUPERA LAS 2 CIFRAS");
}else{
if (num < 10) {
printf("\nLE FALTA %d PARA 2 CIFRAS", 10-num);
}else{
printf("\nLE FALTA %d PARA 3 CIFRAS", 100-num);
}
}
return 0;
}
#include<iostream>
using namespace std;
int main() {
int num, cifras;
cout << "11. MUESTRE LO FALTANTE PARA 2 o 3 CIFRAS.\n\n";
cout << "Ingrese Numero : ";
cin >> num;
cout << endl;
if (num > 99) {
cout << "ERROR... EL NUMERO SUPERA LAS 2 CIFRAS" << endl;
}else{
if (num < 10) {
cout << "LE FALTA " << 10-num << " PARA 2 CIFRAS" << endl;
}else{
cout << "LE FALTA " << 100-num << " PARA 3 CIFRAS"<< endl;
}
}
return 0;
}
using System;
using System.Collections.Generic;
using System.Text;
namespace programacion_work
{
class para_2_o_3_cifras
{
static void Main(string[] args)
{
int num;
Console.WriteLine("13. MUESTRE LO FALTANTE PARA 2 o 3 CIFRAS.\n");
Console.Write("Ingrese Numero : ");
num = int.Parse(Console.ReadLine());
if (num > 99)
{
Console.WriteLine("\nERROR... EL NUMERO SUPERA LAS 2 CIFRAS");
}
else
{
if (num < 10)
{
Console.WriteLine("\nLE FALTA " + (10 - num) + " PARA 2 CIFRAS");
}
else
{
Console.WriteLine("\nLE FALTA " + (100 - num) + " PARA 3 CIFRAS");
}
}
Console.ReadLine();
}
}
}
package programacion_work;
import java.util.Scanner;
public class para_2_o_3_cifras {
public static void main(String[] args) {
Scanner ingreso=new Scanner(System.in);
int num;
System.out.print("11. MOSTRAR EL VALOR FALTANTE PARA 2 o 3 CIFRAS.\n\n");
System.out.print("Ingrese Número : ");
num = Integer.parseInt(ingreso.next());
if(num > 99){
System.out.println("Error... EL NÚMERO SUPERA lAS 2 CIFRAS.");
}else{
if (num < 10) {
System.out.println("LE FALTA " + (10-num) + " PARA 2 CIFRAS");
}else{
System.out.println("LE FALTA " + (100-num) + " PARA 3 CIFRAS");
}
}
}
}
private void jBtn_CalcularActionPerformed(java.awt.event.ActionEvent evt) {
int num;
num = Integer.parseInt(jTxt_num.getText());
if(num > 99){
jLbl_Msg.setText("Error... EL NÚMERO SUPERA LAS 2 CIFRAS.");
}else{
if (num < 10) {
jLbl_Msg.setText("LE FALTA " + String.valueOf(10-num) + " PARA 2 CIFRAS");
}else{
jLbl_Msg.setText("LE FALTA " + String.valueOf(100-num) + " PARA 3 CIFRAS");
}
}
}
Imports System.Console
Module para_2_o_3_cifras
Dim num As Integer
Sub Main()
WriteLine("13. INGRESE UN MONTO Y MUESTRE LO FALTANTE PARA 2 o 3 CIFRAS.")
WriteLine("")
Write("Ingrese Monto : ")
num = ReadLine()
WriteLine("")
If (num > 99) Then
WriteLine("ERROR... EL NUMERO SUPERA LAS 2 CIFRAS")
Else
If (num < 10) Then
WriteLine("LE FALTA " & (10 - num) & " PARA 2 CIFRAS")
Else
WriteLine("LE FALTA " & (100 - num) & " PARA 3 CIFRAS")
End If
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_Monto.Text
If (num > 99) Then
Lbl_msg.Text = "ERROR... EL NUMERO SUPERA LAS 2 CIFRAS"
Else
If (num < 10) Then
Lbl_msg.Text = "LE FALTA " & (10 - num) & " PARA 2 CIFRAS"
Else
Lbl_msg.Text = "LE FALTA " & (100 - num) & " PARA 3 CIFRAS"
End If
End If
End Sub
Sub cifras()
Dim num As Integer
num = Range("C12").Value
If (num > 99) Then
Range("G12").Value = "ERROR"
Else
If (num < 10) Then
Range("G12").Value = "LE FALTA " & 10 - num & " PARA 2 CIFRAS"
Else
Range("G12").Value = "LE FALTA " & 100 - num & " PARA 3 CIFRAS"
End If
End If
End Sub
Sub cifras2()
Dim num As Integer
num = InputBox("INGRESE NÚMERO ")
If (num > 99) Then
MsgBox "ERROR"
Else
If (num < 10) Then
MsgBox "LE FALTA " & 10 - num & " PARA 2 CIFRAS"
Else
MsgBox "LE FALTA " & 100 - num & " PARA 3 CIFRAS"
End If
End If
End Sub
Private Sub btn_calcular_Click()
Dim num As Integer
num = txt_num.Text
If (num > 99) Then
txt_result.Text = "ERROR"
Else
If (num < 10) Then
txt_result.Text = "LE FALTA " & 10 - num & " PARA 2 CIFRAS"
Else
txt_result.Text = "LE FALTA " & 100 - num & " PARA 3 CIFRAS"
End If
End If
End Sub