Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Program: Empty Box Please help solve this. Write a program that first prompts th

ID: 3597175 • Letter: P

Question

Program: Empty Box

Please help solve this.

Write a program that first prompts the user to enter two numbers from the keyboard. You must use the scanf function to do this. Each number will be between 1 and 50 inclusive. The first number, say W, represents the width of a box. The second number, say L, represents the length of the box. Your program should then print out an empty box of asterisks that is W asterisks wide and L asterisks long. You need to e-submit: submit canning p18 p18.c You need to paper submit too To see how it should work you can execute canning/1010programs/p18 You must use for-loops as they should be used. Two of them. Nested. No while loop. No do-while loop.

Explanation / Answer

#include <stdio.h>

int main(int argc, char *argv[]) {
int w, h;

printf("Enter width: ");
scanf("%d", &w);

printf("Enter height: ");
scanf("%d", &h);

int i, j;
for(i = 1; i <= h; i++) {
printf("*");
for(j = 2; j < w; j++) {
if (i == 1 || i == h) {
printf("*");
}
else {
printf(" ");
}
}
printf("* ");
}

return 0;
}

Sample run

Enter width: 5
Enter height: 7
*****
* *
* *
* *
* *
* *
*****