C Online Compiler
Example: Solid Rectangle (User-Defined Size) in C
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// Solid Rectangle (User-Defined Size) #include <stdio.h> int main() { // Step 1: Declare variables for rows and columns int numRows, numCols; // Step 2: Prompt user for input printf("Enter the number of rows: "); scanf("%d", &numRows); printf("Enter the number of columns: "); scanf("%d", &numCols); // Step 3: Input validation (optional but good practice) if (numRows <= 0 || numCols <= 0) { printf("Dimensions must be positive integers.\n"); return 1; // Indicate an error } printf("\nYour rectangle:\n"); // Step 4: Outer loop for rows for (int i = 0; i < numRows; i++) { // Step 5: Inner loop for columns for (int j = 0; j < numCols; j++) { printf("*"); } printf("\n"); } return 0; }
Output
Clear
ADVERTISEMENTS