C Online Compiler
Example: Basic Box with Fixed Dimensions in C
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// Basic Box with Fixed Dimensions #include <stdio.h> int main() { // Step 1: Define box dimensions int width = 7; int height = 4; // Step 2: Loop through each row for (int i = 1; i <= height; i++) { // Step 3: Loop through each column in the current row for (int j = 1; j <= width; j++) { // Step 4: Check if current position is part of the border if (i == 1 || i == height || j == 1 || j == width) { printf("*"); // Print asterisk for border } else { printf(" "); // Print space for interior } } printf("\n"); // Move to the next line after each row } return 0; }
Output
Clear
ADVERTISEMENTS