1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

for-loop ..help!

Discussion in 'C' started by somali.cc, Aug 23, 2010.

  1. somali.cc

    somali.cc New Member

    Joined:
    Aug 23, 2010
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    0
    Hello all, pls guide me how to write a C-program to generate the following output:

    *
    **
    ***
    ****
    *****
     
  2. somali.cc

    somali.cc New Member

    Joined:
    Aug 23, 2010
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    0
    sorry y aar....I want it typed from right to left....
    *
    **
    ***
    ****
    *****
     
  3. somali.cc

    somali.cc New Member

    Joined:
    Aug 23, 2010
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    0
    again same thing...how to delete a post???
     
  4. jimblumberg

    jimblumberg New Member

    Joined:
    May 30, 2010
    Messages:
    120
    Likes Received:
    29
    Trophy Points:
    0
    So what have you tried? Post the code that is causing you the problems. Also post any error messages you receive from compiling your code.


    Jim
     
  5. virxen

    virxen New Member

    Joined:
    Nov 24, 2009
    Messages:
    387
    Likes Received:
    90
    Trophy Points:
    0
    do you mean like this?
     
  6. somali.cc

    somali.cc New Member

    Joined:
    Aug 23, 2010
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    0
    @ Virxen

    Yes u have got dat diagram right.

    @Jim & @ Virxen

    I am not being able to write a program in C dat will give me the output (as Virxen's diagram).
     
  7. virxen

    virxen New Member

    Joined:
    Nov 24, 2009
    Messages:
    387
    Likes Received:
    90
    Trophy Points:
    0
    hints
    =========
    -your output must have 5 lines (maybe a for from 1 to 5?)

    -the first time you print 4 spaces and one star=5 characters (maybe a second or third for?)
    .....
    the fifth time no spaces and 5 stars=5 characters


    start writing code and post your attempts here to help you.
     
  8. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    Here's one that will do the trick:
    Code:
    void test29()
    {
    	char *ch=" ****************";
    	for (int i=1; i<ch[0]; i++)
    	{
    		for (int j=ch[0]/2; j; j>>=1)
    		{
    			putchar(ch[i&j]);
    		}
    		i<<=putchar('\n')/'\n';
    	}
    }
    
    Hope you get a good mark!
     
    shabbir likes this.
  9. somali.cc

    somali.cc New Member

    Joined:
    Aug 23, 2010
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    0
    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    int i,j,k;
    clrscr();
    for(i=1;i<=5;i++)
    {
    for(j=5-i;j>=1;j--)
    printf(" ");

    for(k=1;k<=i;k++)
    printf("*");

    printf("\n");
    }
    getch();
    }
     
  10. somali.cc

    somali.cc New Member

    Joined:
    Aug 23, 2010
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    0
    I am absolutely new to C-programming. Just started with for-loop
     
  11. somali.cc

    somali.cc New Member

    Joined:
    Aug 23, 2010
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    0
    wat about the following diagram: ?

    pls give some hints to get the following output:

    *
    *
    * *

    * * *

    * *
    *
    *
     
  12. virxen

    virxen New Member

    Joined:
    Nov 24, 2009
    Messages:
    387
    Likes Received:
    90
    Trophy Points:
    0
    another way is this

    Code:
    #include <stdio.h>
    
    int main(){
        for (int i=1;i<=5;i++){
            for (int j=1;j<=5;j++){
                 if (j<=(5-i)) 
                      printf(" ");
                else
                      printf("*");
            }
            printf("\n");
        }
        getchar();
        return 0;
    }
    
     

Share This Page