Thread: Simple C Program with Flow Statements

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    14

    Simple C Program with Flow Statements

    Could someone please explain to me how to produce the following using appropiate flow control statements e.g if statement

    * * * * * *
    * * * * *
    * * * *
    * * *
    * *
    *

  2. #2
    Super unModrator
    Join Date
    Dec 2007
    Posts
    321
    By using for loop.

    but you can use while or do...while loop if you wish to.

  3. #3
    Banned
    Join Date
    Nov 2007
    Posts
    678
    HINT: use nested for loops!

    PS:
    why not surprise your teacher and print something like:
    Code:
        *
       **
      ***
     ***************
    ****************
     ***************
      ***
       **
        *
    Last edited by manav; 02-06-2008 at 06:03 AM.

  4. #4
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Quote Originally Posted by manav View Post
    why not surprise your teacher and print something like:
    Yours is easy
    Code:
    #include <stdio.h>
    int main(void)
    {
    	printf(
    "    *\n"
    "   **\n"
    "  ***\n"
    " ***************\n"
    "****************\n"
    " ***************\n"
    "  ***\n"
    "   **\n"
    "    *\n"
    );
    }
    first one is tricky
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  5. #5
    Banned
    Join Date
    Nov 2007
    Posts
    678
    Elysia!!!
    Are you listening!
    vart forgot to put a return 0; here!

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Vart also forgot to indent properly, but I think I'll pretend I didn't see anything
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #7
    Super unModrator
    Join Date
    Dec 2007
    Posts
    321
    rory-uk :
    Just forget the loops and use printf. Using your mind to make loops is just a waste of time.

  8. #8
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I'm thinking it's part of the homework or assignment or whatever it is.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #9
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Oh, come on, don't be silly. You're posting ridiculous code that serves no purpose.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  10. #10
    Super unModrator
    Join Date
    Dec 2007
    Posts
    321
    Quote Originally Posted by Elysia View Post
    Oh, come on, don't be silly. You're posting ridiculous code that serves no purpose.
    That's what is written in my signature.

  11. #11
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    That doesn't make it right. You're not helping anyone, so essentially, it would be spam.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  12. #12
    Super unModrator
    Join Date
    Dec 2007
    Posts
    321
    Quote Originally Posted by Elysia View Post
    That doesn't make it right. You're not helping anyone, so essentially, it would be spam.
    Deleted. cool now ?

  13. #13
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Yes, better. I advise you to post relevant things to the topic in the future.
    It's better that way. For everyone. Keeps people of your back too!
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  14. #14
    Registered User
    Join Date
    Feb 2008
    Posts
    14
    I understand that this can be produced by using printf statements, however I have a task which involves producing this code with a flow statement. Could somebody please show me how to write the code using a while loop or whichever loop that you can use to produce this?

  15. #15
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    What have you tried?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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. [Help] Simple Array/Pointer Program
    By sandwater in forum C Programming
    Replies: 3
    Last Post: 03-30-2007, 02:42 PM
  2. simple silly program
    By verbity in forum C Programming
    Replies: 5
    Last Post: 12-19-2006, 06:06 PM
  3. Simple simple program
    By Ryback in forum C++ Programming
    Replies: 10
    Last Post: 09-09-2004, 05:48 AM
  4. Simple Program not working right (in C)
    By DruzeTito in forum C Programming
    Replies: 5
    Last Post: 06-01-2002, 10:14 PM
  5. I need help on a formula for this simple program.
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 01-28-2002, 10:01 PM