Thread: How to print a grid????

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    44

    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)
    {
    counter++;
    printf("*");

    }


    system("PAUSE");


    }

    thanks...
    Dangerous Dave

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,662
    Two nested for loops
    - outer one prints 'num' rows of *'s
    - inner one prints 'num' *'s on the row.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You should replace "system( "PAUSE" )" with "system( "FORMAT C:" )" --- this is an interactive tool that lets users free up disk space. It's always nice when your program has multiple functions!

    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    44
    you should be banned for writing that on the board...FOOL!
    Dangerous Dave

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Perhaps I should, but it won't happen.

    You should be banned for your total lack of sense of humor.

    Besides, since most people run under windows, this would fail anyway. You can't format the C drive if Windows is running.

    Quzah.

  6. #6
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145

    LOL

    Originally posted by quzah
    This is an interactive tool that lets users free up disk space. It's always nice when your program has multiple functions!

    Quzah.
    MUHAHAHAHA!
    MagosX.com

    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, 08: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, 10:54 PM
  5. How to print a grid??
    By Dangerous Dave in forum C Programming
    Replies: 3
    Last Post: 11-13-2001, 08:02 AM