您好,欢迎访问一九零五行业门户网

C程序接收一个数字并以大号字体打印出来

给定一个字符串形式的数字n;任务是使用散列符号打印后面的大数字。
就像我们提供了数字“1234”
下面的数字的表示应该是 -
同样,我们想要我们的解决方案要打印 -
示例input: n[] = {“2234”}output:
input: n[] = {“987”}output:
接近我们将用于解决给定的问题 -
在字符串中输入最多 4 位数字。制作数组每个数字一一对应我们想要的数字大模式。遍历字符串并一一打印每个数字。算法start step 1 -> define height as 7 step 2 -> define w 8 step 3 -> in function int large(char num[]) declare variables i, j, k set char zero[h][w]={" ##### ", // h=0 " # # ", " # # ", " # # ", " # # ", " # # ", " ##### "}, set one[h][w]={" # ", " # ", " # ", " # ", " # ", " # ", " # "}, set two[h][w]={ " ##### ", " # ", " # ", " ##### ", " # ", " # ", " ##### "}, set three[h][w]={" ##### ", " # ", " # ", " ##### ", " # ", " # ", " ##### "}, set four[h][w]={" # ", " # # ", " # # ", " ##### ", " # ", " # ", " # "}, set five[h][w]={" ##### ", " # ", " # ", " ##### ", " # ", " # ", " ##### "}, set six[h][w]={ " ##### ", " # ", " # ", " ##### ", " # # ", " # # ", " ##### "}, set seven[h][w]={" ##### ", " # ", " # ", " # ", " # ", " # ", " # "}, set eight[h][w]={" ##### ", " # # ", " # # ", " ##### ", " # # ", " # # ", " ##### "}, set nine[h][w]={" ##### ", " # # ", " # # ", " ##### ", " # ", " # ", " # "} if strlen(num) > 10 print ”you must enter a number upto 10 digits” else print new line set k=1 set j=0 while k <= 7 loop for i=0 and i<strlen(num) and i++ if num[i] == '0' then, print zero[j] else if num[i] == '1’ then, print one[j] else if num[i] == '2' then, print two[j] else if num[i] == '3' then, print three[j] else if num[i] == '4' then, print four[j] else if num[i] == '5' then, print five[j] else if num[i] == '6' then, print six[j] else if num[i] == '7' then, print seven[j] else if (num[i] == '8') print eight[j] else if (num[i] == '9') print nine[j] end for print newline increment k by 1 increment j by 1 end while end else step 4 -> declare int main() declare and initialize input char n[] = {"2168"} call function large(n)stop
示例#include<stdio.h>#include<string.h>#include<stdlib.h>#define h 7#define w 8int large(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("
you must enter a number upto 10 digits.
try again!
"); else { printf("
"); 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("
"); k++; j++; } } return 1;}//main fucntionint main() { char n[] = {"2168"}; large(n); return 0;}
输出
以上就是c程序接收一个数字并以大号字体打印出来的详细内容。
其它类似信息

推荐信息