Thread: a question

  1. #16
    Just a Member ammar's Avatar
    Join Date
    Jun 2002
    Posts
    953
    Kuwait:
    After all this explanations and codes, it should be clear now!

    I like the code Prelude wrote.
    but I think the main() function should return a value, but it's realy nice.

  2. #17
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Originally posted by ammar

    I like the code Prelude wrote.
    but I think the main() function should return a value, but it's realy nice.
    It's a matter of personal taste. I usually omit the return 0, in favor of code brevity. Both ways are vaild in ISO C++.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  3. #18
    use printf() if you must.
    I like Prelude's code , but what does the (~n & k) test for?
    Compilers:
    GCC on Red Hat 8.1 (Primary)
    GCC on Mac OS X 10.2.4 (Secondary)

    Others:
    MinGW on XP

  4. #19
    Originally posted by SPiRiToFCaT
    Code:
    for(int i=1; i<=10; i++)
      {
         for(int k=10-i; k>0; k--)
         {
            printf(" ");
         }
       for(j=1; j<=i; j++)
       {
          printf("*");
          printf("\n");
       }
     }
    You want 10-i spaces before each line of stars right?
    so just print 10-i spaces. Meaning, print a space 10-i times.
    Take the printf("\n"); out of the second inside for loop, and put it at the very end of the outside for loop. The rest (arguably) is up to you.

    ~Inquirer, over and out.
    Compilers:
    GCC on Red Hat 8.1 (Primary)
    GCC on Mac OS X 10.2.4 (Secondary)

    Others:
    MinGW on XP

  5. #20
    Registered User
    Join Date
    Oct 2002
    Posts
    38

    Thumbs up Thanx for all

    thanx i understand now how to do it

    thanx again

  6. #21
    Registered User
    Join Date
    Oct 2002
    Posts
    8
    is this the way that you want??

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


    if so the code is this
    Code:
    /*
    for(int i=1; i<=9; i++)
    	{
    		for(int k=10-i; k>0; k--)
    		{
    		printf(" ");
    		}
    		for(int j=1; j<=i; j++)
    		{
    		printf("*");
    		}
    		printf("\n");
    	}
    
    
    */

  7. #22
    Just a Member ammar's Avatar
    Join Date
    Jun 2002
    Posts
    953
    Originally posted by Sang-drax
    It's a matter of personal taste. I usually omit the return 0, in favor of code brevity. Both ways are vaild in ISO C++.
    That's new, I didn't know that you can ommit the return 0 in the int main() function.
    Thanks for that.

  8. #23
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Nested for-loops aren't neccessary:
    Code:
    for (int i=1;i<=10;++i)
      cout << setw(i) << setfill('*') << "" << endl;
    EDIT:

    Perhaps this is more what you want:
    Code:
    for (int i=1;i<=10;++i)
      cout << setw(10-i)<<setfill(' ') << ""<< setw(i) << setfill('*') << "" << endl;
    Last edited by Sang-drax; 10-31-2002 at 05:00 AM.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM