Pregunta: Escriba un programa que reciba un número como entrada y lo imprima en tamaño grande en una misma línea como se muestra a continuación en la imagen.
Ejemplos:
Input : 0194 Output : ##### # ##### # # # ## # # # # # # # # # # # # # # ##### ##### # # # # # # # # # # ##### ##### # # Explanation: Each digit of the number has been printed in hash format Input : 0123456789 Output : ##### # ##### ##### # ##### ##### ##### ##### ##### # # ## # # # # # # # # # # # # # # # # # # # # # # # # # # # # ##### ##### ##### ##### ##### #### ##### ##### # # # # # # # # # # # # # # # # # # # # # # # # # # ##### ##### ##### ##### # ##### ##### # ##### #
Usamos una array de caracteres bidimensional para almacenar esas strings hash para cada dígito. El ciclo for lee cada dígito e if-else verifica el dígito e imprime cada fila de cada dígito de arrays de caracteres 2D en una misma línea. Luego, continúa con la siguiente línea y trabaja de la misma manera hasta que se imprime todo el diseño.
C
// C program to print a number in large size #include<stdio.h> #include<string.h> #include<stdlib.h> #define H 7 // one extra room in the char array is required for storing '\0' #define W 8 void hashprint(char num[]) { int i, j, k; // declaring char 2D arrays and initializing // with hash-printed digits char zero[H][W]={" ##### ", // H=0 " # # ", // H=1 " # # ", // H=2 " # # ", // H=3 " # # ", // H=4 " # # ", // H=5 " ##### "},// H=6 one[H][W]={" # ", " ## ", " # ", " # ", " # ", " # ", " ##### "}, two[H][W]={" ##### ", " # ", " # ", " ##### ", " # ", " # ", " ##### "}, three[H][W]={" ##### ", " # ", " # ", " ##### ", " # ", " # ", " ##### "}, four[H][W]={" # ", " # # ", " # # ", " ##### ", " # ", " # ", " # "}, five[H][W]={" ##### ", " # ", " # ", " ##### ", " # ", " # ", " ##### "}, six[H][W]={" ##### ", " # ", " # ", " ##### ", " # # ", " # # ", " ##### "}, seven[H][W]={" ##### ", " # ", " # ", " #### ", " # ", " # ", " # "}, eight[H][W]={" ##### ", " # # ", " # # ", " ##### ", " # # ", " # # ", " ##### "}, nine[H][W]={" ##### ", " # # ", " # # ", " ##### ", " # ", " # ", " # "}; if (strlen(num) > 10) printf("\nYou must enter a number upto 10 digits.\nTry again!\n"); else { printf("\n"); k=1; j=0; //controls H of each digit while (k <= 7) //controls height { for (i=0; i<strlen(num); i++) //reads each digit { if (num[i] == '0') printf("%s", zero[j]); else if (num[i] == '1') printf("%s", one[j]); else if (num[i] == '2') printf("%s", two[j]); else if (num[i] == '3') printf("%s", three[j]); else if (num[i] == '4') printf("%s", four[j]); else if (num[i] == '5') printf("%s", five[j]); else if (num[i] == '6') printf("%s", six[j]); else if (num[i] == '7') printf("%s", seven[j]); else if (num[i] == '8') printf("%s", eight[j]); else if (num[i] == '9') printf("%s", nine[j]); } printf("\n"); k++; j++; } } } //Driver program to test above function int main() { // passing 0194 as string to function hashprint // you can pass whatever string you wish to hashprint("0194"); return 0; }
Java
// JAVA Code for Program that receives a number // and prints it out in large size class GFG { public static void hashprint(String num) { int i, j, k; // declaring char 2D arrays and initializing // with hash-printed digits String zero[]={" ##### ", // H=0 " # # ", // H=1 " # # ", // H=2 " # # ", // H=3 " # # ", // H=4 " # # ", // H=5 " ##### "};// H=6 String one[]={" # ", " ## ", " # ", " # ", " # ", " # ", " ##### "}; String two[]={" ##### ", " # ", " # ", " ##### ", " # ", " # ", " ##### "}; String three[]={" ##### ", " # ", " # ", " ##### ", " # ", " # ", " ##### "}; String four[]={" # ", " # # ", " # # ", " ##### ", " # ", " # ", " # "}; String five[]={" ##### ", " # ", " # ", " ##### ", " # ", " # ", " ##### "}; String six[]={" ##### ", " # ", " # ", " ##### ", " # # ", " # # ", " ##### "}; String seven[]={" ##### ", " # ", " # ", " #### ", " # ", " # ", " # "}; String eight[]={" ##### ", " # # ", " # # ", " ##### ", " # # ", " # # ", " ##### "}; String nine[]={" ##### ", " # # ", " # # ", " ##### ", " # ", " # ", " # "}; if (num.length() > 10) System.out.println("\nYou must enter a number "+ "upto 10 digits.\nTry again!\n"); else { System.out.println(""); k = 1; j = 0; //controls H of each digit while (k <= 7) //controls height { for (i = 0; i < num.length(); i ++) //reads each digit { if (num.charAt(i) == '0') System.out.print(zero[j]); else if (num.charAt(i) == '1') System.out.print(one[j]); else if (num.charAt(i) == '2') System.out.print(two[j]); else if (num.charAt(i) == '3') System.out.print(three[j]); else if (num.charAt(i) == '4') System.out.print(four[j]); else if (num.charAt(i) == '5') System.out.print(five[j]); else if (num.charAt(i) == '6') System.out.print(six[j]); else if (num.charAt(i) == '7') System.out.print(seven[j]); else if (num.charAt(i) == '8') System.out.print(eight[j]); else if (num.charAt(i) == '9') System.out.print(nine[j]); } System.out.println(""); k ++; j ++; } } } /* Driver program to test above function */ public static void main(String[] args) { // passing 0194 as string to function hashprint // you can pass whatever string you wish to hashprint("0194"); } } // This code is contributed by Arnav Kr. Mandal.
Python3
# Python program to print a number in large size H = 7 # one extra room in the char array is required for storing '\0' W = 8 def hashprint(num): # declaring char 2D arrays and initializing # with hash-printed digits zero = [" ##### ", # H=0 " # # ", # H=1 " # # ", # H=2 " # # ", # H=3 " # # ", # H=4 " # # ", # H=5 " ##### "]# H=6 one = [" # ", " ## ", " # ", " # ", " # ", " # ", " ##### "] two = [" ##### ", " # ", " # ", " ##### ", " # ", " # ", " ##### "] three = [" ##### ", " # ", " # ", " ##### ", " # ", " # ", " ##### "] four = [" # ", " # # ", " # # ", " ##### ", " # ", " # ", " # "] five = [" ##### ", " # ", " # ", " ##### ", " # ", " # ", " ##### "] six = [" ##### ", " # ", " # ", " ##### ", " # # ", " # # ", " ##### "] seven = [" ##### ", " # ", " # ", " #### ", " # ", " # ", " # "] eight = [" ##### ", " # # ", " # # ", " ##### ", " # # ", " # # ", " ##### "] nine = [" ##### ", " # # ", " # # ", " ##### ", " # ", " # ", " # "] if (len(num) > 10): print() print("You must enter a number upto 10 digits.") print("Try again!") else: print() k=1 j=0 #controls H of each digit while (k <= 7): #controls height for i in range(len(num)): #reads each digit if(num[i] == '0'): print(zero[j],end = "") elif (num[i] == '1'): print(one[j],end = "") elif (num[i] == '2'): print(two[j],end = "") elif (num[i] == '3'): print(three[j],end = "") elif (num[i] == '4'): print(four[j],end = "") elif (num[i] == '5'): print(five[j],end = "") elif (num[i] == '6'): print(six[j],end = "") elif (num[i] == '7'): print(seven[j],end = "") elif (num[i] == '8'): print(eight[j],end = "") elif (num[i] == '9'): print(nine[j],end = "") print() k += 1 j += 1 # Driver program to test above function # passing 0194 as string to function hashprint # you can pass whatever string you wish to hashprint("0194") # This code is contributed by shinjanpatra
C#
// C# Code for Program that // receives a number and prints // it out in large size using System; class GFG { public static void hashprint(string num) { int i, j, k; // declaring char 2D arrays // and initializing with // hash-printed digits String []zero={" ##### ", // H=0 " # # ", // H=1 " # # ", // H=2 " # # ", // H=3 " # # ", // H=4 " # # ", // H=5 " ##### "};// H=6 String []one={" # ", " ## ", " # ", " # ", " # ", " # ", " ##### "}; String []two={" ##### ", " # ", " # ", " ##### ", " # ", " # ", " ##### "}; String []three={" ##### ", " # ", " # ", " ##### ", " # ", " # ", " ##### "}; String []four={" # ", " # # ", " # # ", " ##### ", " # ", " # ", " # "}; String []five={" ##### ", " # ", " # ", " ##### ", " # ", " # ", " ##### "}; String []six={" ##### ", " # ", " # ", " ##### ", " # # ", " # # ", " ##### "}; String []seven={" ##### ", " # ", " # ", " #### ", " # ", " # ", " # "}; String []eight={" ##### ", " # # ", " # # ", " ##### ", " # # ", " # # ", " ##### "}; String []nine={" ##### ", " # # ", " # # ", " ##### ", " # ", " # ", " # "}; if (num.Length > 10) Console.WriteLine("\nYou must enter a number "+ "upto 10 digits.\nTry again!\n"); else { Console.WriteLine(""); k = 1; j = 0; //controls H of each digit while ($k <= 7) //controls height { //reads each digit for ($i = 0; $i < strlen($num); $i++) { if (num[i] == '0') Console.Write(zero[j]); else if (num[i] == '1') Console.Write(one[j]); else if (num[i] == '2') Console.Write(two[j]); else if (num[i] == '3') Console.Write(three[j]); else if (num[i] == '4') Console.Write(four[j]); else if (num[i] == '5') Console.Write(five[j]); else if (num[i] == '6') Console.Write(six[j]); else if (num[i] == '7') Console.Write(seven[j]); else if (num[i] == '8') Console.Write(eight[j]); else if (num[i] == '9') Console.Write(nine[j]); } Console.WriteLine(""); k ++; j ++; } } } // Driver Code public static void Main() { // passing 0194 as string to // function hashprint you can // pass whatever string you wish to hashprint("0194"); } } // This code is contributed by Sam007
PHP
<?php // PHP program to print // a number in large size $H = 7; // one extra room in the // char array is required // for storing '\0' $W = 8; function hashprint($num) { global $H; global $W; $i; $j; $k; // declaring char 2D arrays // and initializing with // hash-printed digits $zero= array(" ##### ", // H=0 " # # ", // H=1 " # # ", // H=2 " # # ", // H=3 " # # ", // H=4 " # # ", // H=5 " ##### ");// H=6 $one= array(" # ", " ## ", " # ", " # ", " # ", " # ", " ##### "); $two= array(" ##### ", " # ", " # ", " ##### ", " # ", " # ", " ##### "); $three= array(" ##### ", " # ", " # ", " ##### ", " # ", " # ", " ##### "); $four= array(" # ", " # # ", " # # ", " ##### ", " # ", " # ", " # "); $five= array(" ##### ", " # ", " # ", " ##### ", " # ", " # ", " ##### "); $six= array(" ##### ", " # ", " # ", " ##### ", " # # ", " # # ", " ##### "); $seven= array(" ##### ", " # ", " # ", " #### ", " # ", " # ", " # "); $eight= array(" ##### ", " # # ", " # # ", " ##### ", " # # ", " # # ", " ##### "); $nine= array(" ##### ", " # # ", " # # ", " ##### ", " # ", " # ", " # "); if (strlen($num) > 10) echo "\nYou must enter a " . "number upto 10 digits. \nTry again!\n"; else { echo "\n"; $k = 1; $j = 0; //controls H of each digit while ($k <= 7) //controls height { //reads each digit for ($i = 0; $i < strlen($num); $i++) { if ($num[$i] == '0') echo $zero[$j]; else if ($num[$i] == '1') echo $one[$j]; else if ($num[$i] == '2') echo $two[$j]; else if ($num[$i] == '3') echo $three[$j]; else if ($num[$i] == '4') echo $four[$j]; else if ($num[$i] == '5') echo $five[$j]; else if ($num[$i] == '6') echo $six[$j]; else if ($num[$i] == '7') echo $seven[$j]; else if ($num[$i] == '8') echo $eight[$j]; else if ($num[$i] == '9') echo $nine[$j]; } echo "\n"; $k++; $j++; } } } // Driver Code // passing 0194 as string // to function hashprint // you can pass whatever // string you wish to hashprint("0194"); // This code is contributed by ajit ?>
Producción:
##### # ##### # # # ## # # # # # # # # # # # # # # ##### ##### # # # # # # # # # # ##### ##### # #
Este artículo ha sido aportado por Mayukh Datta . Si te gusta GeeksforGeeks y te gustaría contribuir con un artículo único, también puedes escribir usando write.geeksforgeeks.org o enviar tu artículo por correo a review-team@geeksforgeeks.org. Vea su artículo que aparece en la página principal de GeeksforGeeks y ayude a otros Geeks.
Para ponerse en contacto con el colaborador de este artículo, siga este enlace a su blog: thecoducer
Escriba comentarios si encuentra algo incorrecto o si desea compartir más información sobre el tema tratado anteriormente.
Publicación traducida automáticamente
Artículo escrito por GeeksforGeeks-1 y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA