Help!! How to print this using loop & condition starements...

This is a discussion on Help!! How to print this using loop & condition starements... within the C Programming forums, part of the General Programming Boards category; Help!! How to print this using loop & condition starements... 0 1 1 1 1 -1 0 1 1 1 ...

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    19

    Help!! How to print this using loop & condition starements...

    Help!! How to print this using loop & condition starements...

    0 1 1 1 1
    -1 0 1 1 1
    -1 -1 0 1 1
    -1 -1 -1 0 1
    -1 -1 -1 -1 0


    help pls..asap...

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    20,976
    What have you tried?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Nov 2011
    Posts
    19
    its so hard..can u help me??

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    20,976
    Well, start by writing nested loops to print a 5 by 5 matrix of 0s.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Nov 2011
    Posts
    19
    Code:
    #include <stdio.h>
    
    
    main()
    {
    
    
        int i, j;
    
    
        for(i = 1; i <= 5; i++)
        {
    
    
        for(j = 1; j <= 5; j++)
                printf("%c", '*');
    
    
            printf("\n");
        }
    }
    then??

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    20,976
    Right. Now in the body of the inner loop, compare i and j, and based on your comparison (less than, equal to, greater than) print (1, 0, -1).

    By the way, you should define main as returning int, and indent your code a little better.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. what condition in the while loop?
    By joeman in forum C++ Programming
    Replies: 3
    Last Post: 03-05-2010, 10:49 AM
  2. Overide for loop condition
    By erasm in forum C Programming
    Replies: 2
    Last Post: 08-11-2009, 08:08 AM
  3. || or starements
    By grimuth in forum C++ Programming
    Replies: 3
    Last Post: 08-19-2007, 07:11 AM
  4. need while(for(loop)) to be condition
    By thestien in forum C++ Programming
    Replies: 4
    Last Post: 10-12-2006, 08:32 AM
  5. help with loop condition
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 03-23-2002, 11:18 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21