954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

for loops

i am in a intro to cs class and need help with a current project. it is a simple project but I seem to be stuck. the program is to read 2 integers for the height and width of a rectangle and then display the rectangle using "#" 's. We are to do this using a loop construct such as a for loop. my problem is that I do not know how to display the "#"'s for the width of the rectangle. can anyone help?

lobo
Newbie Poster
2 posts since Sep 2003
Reputation Points: 10
Solved Threads: 0
 

Awright, I don't know what 'cs' is. But here's a basic idea of what you need to do:

Get input and store in variables named 'width' and 'height'
for (temp=0;temp#include <stdio.h>
int main(void) {
int temp=0,temp2=0,width=0,height=0;
printf("Input width and height:\n");
scanf("%d%d",&width,&height);
for (temp=0;temp<width;temp++)
for (temp2=0;temp2<height;temp2++)
putchar('#');
return 0;
}


That's untested, but according to all logic and reasoning available at the time of writing, it should work.

Mike29936
Newbie Poster
22 posts since Sep 2003
Reputation Points: 12
Solved Threads: 0
 

thanks, by the way I used "cs" to stand for "computer science"

lobo
Newbie Poster
2 posts since Sep 2003
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You