이 튜토리얼에서는 주어진 연 패턴을 인쇄하는 프로그램에 대해 논의할 것입니다.
이를 위해 입력을 N=5로 사용합니다. 우리의 임무는 전체 높이가 2N+1 =5인 주어진 Kitestructure를 인쇄하는 것입니다. 여기에는 상부 다이아몬드 구조에 대한 9개의 라인과 하부 불완전 다이아몬드 구조에 대한 2개의 라인이 포함됩니다.
예
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
int main(){
int i, j, k, sp, space = 4;
char prt = '$';
//printing the upper half of the first diamond
for (i = 1; i <= 5; i++){
//printing the spaces in the front
for (sp = space; sp >= 1; sp--){
cout << " ";
}
//printing $ character
for (j = 1; j <= i; j++){
cout << prt;
}
for (k = 1; k <= (i - 1); k++){
if (i == 1){
continue;
}
cout << prt;
}
cout << "\n";
space--;
}
space = 1;
//printing the lower half of the first diamond
for (i = 4; i >= 1; i--){
for (sp = space; sp >= 1; sp--) {
cout << " ";
}
for (j = 1; j <= i; j++){
cout << prt;
}
for (k = 1; k <= (i - 1); k++){
cout << prt;
}
space++;
cout << "\n";
}
space = 3;
//printing the second incomplete diamond
for (i = 2; i <= 5; i++){
if ((i % 2) != 0){
for (sp = space; sp >= 1; sp--){
cout << " ";
}
for (j = 1; j <= i; j++){
cout << prt;
}
}
if ((i % 2) != 0) {
cout << "\n";
space--;
}
}
return 0;
} 출력
$ $$$ $$$$$ $$$$$$$ $$$$$$$$$ $$$$$$$ $$$$$ $$$ $ $$$ $$$$$