숫자 n이 주어지면 최대 n개의 별에 대한 화살표 별 패턴을 인쇄해야 합니다.
입력 4의 별 패턴은 다음과 같습니다. -

예시
Input: 3 Output:

Input: 5 Output:

아래에 사용된 접근 방식은 다음과 같습니다 -
- 정수를 입력하세요.
- 그런 다음 n개의 공백과 n개의 별을 인쇄합니다.
- n>1까지 감소합니다.
- 이제 n까지 증가합니다.
- 공백과 별표를 오름차순으로 인쇄합니다.
알고리즘
Start In function int arrow(int num) Step 1-> declare and initialize i, j Step 2-> Loop For i = 1 and i <= num and i++ Loop For j = i and j < num and j++ Print a space Loop For j = i and j <= num and j++ Print "*" Print newline Step 3-> Loop For i = 2 and i <= num and i++ Loop For j= 1 and j < I and j++ Print a space Loop For j = 1 and j <= i and j++ Print "*" Print newline In function int main() Step 1-> declare and initialize num = 4 Step 2-> call arrow(num)
예시
#include <stdio.h>
// arrow function
int arrow(int num) {
int i, j;
// Prints the upper part of the arrow
for (i = 1; i <= num; i++) {
// to print the spaces
for (j = i; j < num; j++) {
printf(" ");
}
// to print the * for the pattern
for (j = i; j <= num; j++) {
printf("*");
}
printf("\n");
}
// Prints lower part of the arrow
for (i = 2; i <= num; i++) {
// to print the spaces
for (j = 1; j < i; j++) {
printf(" ");
}
// to print the * for the pattern
for (j = 1; j <= i; j++) {
printf("*");
}
printf("\n");
}
return 0;
}
int main() {
// get the value from user
int num = 4;
// function calling
arrow(num);
return 0;
} 출력
위의 코드를 실행하면 다음 출력이 생성됩니다 -
