数字を受け取って大きなサイズで印刷するCプログラム
文字列の形式で数値nが与えられます。タスクは、ハッシュ記号を使用して次の番号を大きく印刷することです。
番号「1234」を提供したように
次の数の表現は-
である必要があります
同様に、ソリューションを印刷する必要があります-
例
Input: n[] = {“2234”} Output:
Input: n[] = {“987”} Output:
特定の問題を解決するために使用するアプローチ −
- 最大4桁の数字を文字列に入力します。
- すべての数値の配列を、その数値に必要な大きなパターンを1つずつ作成します。
- 文字列をトラバースして、すべての数字を1つずつ印刷します。
アルゴリズム
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 8 int 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("\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++; } } return 1; } //main fucntion int main() { char n[] = {"2168"}; large(n); return 0; }
出力
-
Cで中実および中空の菱形パターンを印刷するプログラム
プログラムの説明 以下に示すように、中実および中空の菱形パターンを印刷します アルゴリズム 中空菱形の場合- Accept the Number of Rows for Hollow Rhombus from the User Create a Hollow Rhombus containing the same number of Rows specified by the User. Print the first row containing the number of stars same as the number of rows. Print the second row
-
多数の階乗を見つけるPythonプログラム
nの数が多いとします。その階乗を見つける必要があります。他のいくつかの言語では、整数データ型の範囲を超える可能性があるため、多数の階乗を見つけるのは非常に困難です。ただし、Pythonでは、長さを自動的に検出し、デフォルトで数値をより大きな整数形式に更新します。 したがって、入力がn =50の場合、出力はになります。 30414093201713378043612608166064768844377641568960512000000000000 これを解決するには、次の手順に従います- 数学ライブラリから階乗クラスをインポートする 任意の大きな値のnの階乗を計算する