Thread: How to print a grid??

  1. #1
    Registered User
    Join Date
    Oct 2001

    How to print a grid??

    How to print a grid????
    Here is the question to be answered:

    Write a program that reads in an integer value in the range 1 to 20 and prints out a square of stars of that demension. for example, if the user enteres 5 the following will bedisplayed:


    this is what i have so far..

    #include <stdio.h>
    #include <stdlib.h>

    int main()
    int counter, num_1;

    counter = 1;

    printf("Enter Number: ");
    scanf("%d", &num_1);

    while (counter <= num_1)





  2. #2
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    So now you produce the first line. So it looks like you'll need to produce the same line num_1 times. Looks like a job for another loop which includes your current loop doesn't it. Have a think about that.

    BTW, you have, quite correctly declared your main() as int, you should return an int at the end of your program. Add a

    return 0;

    after the pause.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  3. #3
    Registered User Strider's Avatar
    Join Date
    Aug 2001
    Nest the while loop:

    for (int i = 0; i < num_1; i++)
        while (counter <= num_1) 
        /* or "\r" or whatever you use for newline (hex - 0x0d0a) */
        counter = 1;
    **Edit - Sorry adrianxw, didn't realize you had already responded.

    Last edited by Strider; 11-12-2001 at 07:51 AM.
    One Ring to rule them all, One Ring to find them,
    One Ring to bring them all and in the darkness bind them
    In the Land of Mordor where the Shadows lie.

  4. #4
    Confused Magos's Avatar
    Join Date
    Sep 2001


    Can't wait for Lord Of the Rings... it's gonna rock! ...or be a flop..? Perhaps it's too hyped?

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Personal Program that is making me go wtf?
    By Submeg in forum C Programming
    Replies: 20
    Last Post: 06-27-2006, 12:13 AM
  2. Scope And Parameter Passing
    By djwicks in forum C Programming
    Replies: 6
    Last Post: 03-28-2005, 07:26 PM
  3. What kind of programs should I start writing?
    By Macabre in forum C++ Programming
    Replies: 23
    Last Post: 04-12-2003, 08:13 PM
  4. Trying to print grid
    By blackgingr in forum C Programming
    Replies: 2
    Last Post: 11-14-2002, 09:54 PM
  5. How to print a grid????
    By Dangerous Dave in forum C Programming
    Replies: 5
    Last Post: 11-09-2001, 01:03 PM
Website Security Test