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

Create a function that takes two integers as parameters (width and height in tha

ID: 3729067 • Letter: C

Question

Create a function that takes two integers as parameters (width and height in that order) and prints a rectangle of pluses and dashes as shown below to the screen using only WHILE loops. Do not use for loops. If a value less than 1 is passed as an argument, the function should not print anything. The rectangle should be printed with only dashes (minus), plus signs, and newlines. Each line should end with a newline. There should be no spaces or extra characters anywhere.

For example: printRectangleWhile(10, 6); should print a rectangle with 10 columns and six rows as shown below.

This function should be executed be another file like this:

#include

//Sample main.cc

void printRectangleWhile(int, int);

int main() {

printRectangleWhile(10, 6);

}

Explanation / Answer

#include <stdio.h>

void printRectangleWhile(int, int);

int main()
{
printRectangleWhile(10, 6);
return 0;
}

void printRectangleWhile(int max_col,int max_row)
{
int rowvar=0,colvar=0,sign_var=0;
  
while(rowvar<max_row)
{
colvar=0;
while(colvar<max_col)
{
if(sign_var==0)
{
printf("+");
sign_var=1;
}   
else
{
printf("-");
sign_var=0;
}
colvar++;
}
printf(" ");
rowvar++;
}
  
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote