C Online Compiler
Example: Draw a Rectangle in C language using For loop
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// Draw a Rectangle in C language using For loop #include <stdio.h> int main() { int r = 0, c = 0, i, j; // r - To store the number of rows // c - To store the number of columns printf("-----Enter the number of rows & columns-----\n"); scanf("%d%d", &r, &c); for (i = 1; i <= r; i++) { for (j = 1; j <= c; j++) { if (i == 1 || i == r || j == 1 || j == c) printf("* "); else printf(" "); } printf("\n"); } return 0; }
8 12
Output
Clear
ADVERTISEMENTS