Page 1 of 3 123 LastLast
Results 1 to 10 of 29
  1. #1

    Thumbs up problem for loop * c++


    good morning guys naa ta ko patan-aw ninyo kung unsa kulang ani nga code.
    mao ni ang problem :

    write a program that would generate the output below :

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

    note : use only 1 printf("*") and place this inside a loop.


    din mao ni akong code :

    Code:
    #include<stdio.h>
    #include<conio.h>
    
     
    
    main()
    {
          int x,y,a=6,b=1,z=5;
          
          for(x=b;x<=a;x++)
          {
                           for(y=b;y<=x;y++)
                           {
                                       if(y<=z)
                                       z--;
                                       printf("*");
                           }
                                printf("\n");
          }
          
          getch();
          
          }
    ang problem nya kay ang iyaha rang katunga ang mu increment pero nig abot nya sa maximum kay dli na xa mu decrement. mao rani iyang i output :

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

    diha rajud xa kutob, ang naka lisud man gud ani kay kelangan isa ra ka printf("*") ang gamiton may unta to ug duha kay dali ra.. huhuhu.. really need your help guys. unsa kaha kulang ani akong codes. huhuhu.

  2. #2
    here's the working code (^_^)

    Code:
    #include<stdio.h>
    #include<conio.h>
    
     
    
    main()
    {
          int x,y,a=6,b=5,z;
          
          for(x=1;x<=(a*2)-1;x++)
          {
                           if(x<=a)
                               z = x;
                           else
                               z = b--;
                                                  
                           for(y=1;y<=z;y++)
                           {
                                       printf("*");
                           }
                           printf("\n");
                           
          }
          
          getch();
          
          }

  3. #3
    the code above is only suited for the output you wanted to have in your post.
    the code in this post is more flexible. Pwede nimo ma-input ang size sa middle na line.
    meaning, if you want an output like the one you placed in your post, just enter 6.
    try out different numbers for different sizes. ^^

    made this just for fun. hehe. ^^


    Code:
    #include<stdio.h>
    #include<conio.h>
    
     
    
    main()
    {
          int x,y,a,b,z;
          
          printf("Enter a number: ");
          scanf("%d", &a);
          
          b = a - 1;
          
          for(x=1;x<=(a*2)-1;x++)
          {
                           if(x<=a)
                               z = x;
                           else
                               z = b--;
                                                  
                           for(y=1;y<=z;y++)
                           {
                                       printf("*");
                           }
                           printf("\n");
                           
          }
          
          getch();
          
          }

  4. #4
    thank you kaau jc.. karon pako pwede diay ni nga line ?.. : z = b--; ..i never think of it.. hehehe..
    unsa diay interpretation ani ?.. :int a=6; din (a*2)-1 ako gisuwayan ug dritso 11 kay dli man noon xa mubalik ug kagamay.. mag cge ra xag increase..

  5. #5
    z = b--;
    ang pasabot ani kay imu ibutang sa z ang value sa b before nimo sya minusan. ^^

    i don't know unsay problem if diretsoon nimog 11. . hehe. ako ra mn nang giingon ana pra flexible ang code. hehehe.

    glad to be of help ^^

  6. #6
    kanang z = b-- mao man na g tawag na decrementation, the same ra ang principle nila sa incrementation pru opposite lang na decrementation.

  7. #7
    ahh i see.. ask lang ko pwede raba ni magamitan ug isa ra ka printf("*") if pananglit pangayoan kog in-ani na output?..
    Code:
     
           *
          **
         ***
       *****
      ******
     *******
      ******
       *****
        ***
         **
          *
    i mean.. if diamond na iyang porma ba.. sorry for the drawing.. hehe pwede pa kaha na xa magamitan ug isa ka printf("*") ?...
    unsaon pud?..
    Last edited by public7enemy; 02-18-2011 at 06:07 AM.

  8. #8
    possible na sya. though its a bit more complicated. one way of doing it is using d gotoxy() na function.
    this function lets your cursor (the blinking underscore) jump to a coordinate in your monitor.
    coz if you dnt use that, kelangan pa ka ug another printf to put some spaces.

  9. #9
    possible sad na gamitan ra nimo ug usa ka loop

  10. #10
    If you intend to use one printf("*") only.
    You need 1 loop to plot your row,
    another 1 loop to plot your column.

  11.    Advertisement

Page 1 of 3 123 LastLast

Similar Threads

 
  1. Skin and Fur Problems for Dogs~
    By chanbri in forum Pet Discussions
    Replies: 228
    Last Post: 07-31-2011, 07:00 AM
  2. Anyone here having no internet problems for 2 weeks? (PLDT)
    By pinkchocobo in forum Networking & Internet
    Replies: 3
    Last Post: 09-23-2010, 05:51 PM
  3. for loop problem
    By istoryansucks in forum Programming
    Replies: 2
    Last Post: 08-08-2010, 04:15 AM
  4. Replies: 20
    Last Post: 12-02-2009, 10:56 PM
  5. Compatible ink problem for Epson C63
    By KittyAnnette in forum Computer Hardware
    Replies: 13
    Last Post: 02-18-2006, 03:47 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
about us
We are the first Cebu Online Media.

iSTORYA.NET is Cebu's Biggest, Southern Philippines' Most Active, and the Philippines' Strongest Online Community!
follow us
#top