C Online Compiler
Example: Left Arrow Pattern and Right Arrow Pattern in C language
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// Left Arrow Pattern and Right Arrow Pattern in C language #include <stdio.h> int main() { int r, r1, c, rows, row1; printf("-----Enter the number of rows to print the left & right arrows pattern-----\n"); scanf("%d", &rows); row1 = rows; rows = rows * 4; printf("\n----Ths is the left arrow pattern-----\n\n"); for (r = 1; r < rows; r++) { // to print the left arrow if (r <= row1) { for (c = 1; c <= (row1 - r); c++) printf(" "); for (c = r;c <= row1; c++) printf("*"); printf("\n"); } if (r > row1 && r <= row1 * 2) { for (c = 1; c <= (r - row1); c++) printf(" "); for (c = 1; c <= (r - (row1 - 1)); c++) { if ((r - row1) < row1) printf("*"); } printf("\n"); } // to print the right arrow if (r > row1 * 2 && r <= row1 * 3) { if (r == (row1 * 2) + 1) printf("\n----Ths is the right arrow pattern-----\n\n"); for (c = (r - 1) - (row1 * 2); c >= 1; c--) printf(" "); for (c = (3 * row1) - (r - 1); c >= 1; c--) printf("*"); printf("\n"); } if (r > row1 * 3) { for (c = (row1 * 4) - (r + 1); c >= 1; c--) printf(" "); for (c = (r + 1) - (3 * row1); c >= 1; c--) printf("*"); printf("\n"); } } return 0; }
5
Output
Clear
ADVERTISEMENTS