| | |
for loops
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Sep 2003
Posts: 2
Reputation:
Solved Threads: 0
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?
Last edited by lobo; Sep 22nd, 2003 at 8:43 pm.
•
•
Join Date: Sep 2003
Posts: 22
Reputation:
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<width;temp++)
for (temp2=0;temp2<height;temp2++)
print out '#'
How it works is it goes across:
#####
But since theres another for loop every time it moves across one, it goes down a column:
###
###
###
For example, it'll start at the first #, right? It'll loop until it reaches the last one, but for every time it goes across, it makes a column with a second for loop.
Hopefully I've explained clearly enough.
Btw, I don't know what 'cs' is, but here's some C/C++ code, if it'll help:
That's untested, but according to all logic and reasoning available at the time of writing, it should work.
Get input and store in variables named 'width' and 'height'
for (temp=0;temp<width;temp++)
for (temp2=0;temp2<height;temp2++)
print out '#'
How it works is it goes across:
#####
But since theres another for loop every time it moves across one, it goes down a column:
###
###
###
For example, it'll start at the first #, right? It'll loop until it reaches the last one, but for every time it goes across, it makes a column with a second for loop.
Hopefully I've explained clearly enough.
Btw, I don't know what 'cs' is, but here's some C/C++ code, if it'll help:
C Syntax (Toggle Plain Text)
#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.
![]() |
Similar Threads
- Program Help Using For Nested Loops (C++)
- Need Advice on for loops with vowels (Java)
- Loops (C++)
- Need some help with my do-while and while loops (Java)
- Help with loops (Java)
- merged:nesting loops (C++)
- help for program involving switch loops and file (C++)
Other Threads in the C Forum
- Previous Thread: struct dynamic 2d array alloc
- Next Thread: read ip on xp
| Thread Tools | Search this Thread |
#include * append array arrays asterisks bash binarysearch calculate changingto char character cm copyimagefile creafecopyofanytypeoffileinc createprocess() database dynamic execv feet fgets file floatingpointvalidation fork forloop framework function getlogicaldrivestrin givemetehcodez global grade gtkwinlinux hacking histogram ide include incrementoperators input intmain() iso kernel keyboard kilometer km license linked linkedlist linux list lists locate logical_drives looping loopinsideloop. lowest matrix meter microsoft mqqueue number oddnumber odf opensource openwebfoundation overwrite owf pdf performance pointer posix probleminc process program programming radix recursion recv recvblocked research reversing scripting segmentationfault sequential single socket socketprogramming standard strchr string systemcall testing threads turboc unix urboc user variable wab whythiscodecausesegmentationfault windowsapi





