Question:

Turbo C Question: How can I do these in turbo C?

by  |  earlier

0 LIKES UnLike

Using the format of .c only, how can I do this output?

for example the entered number is 5

Enter number of lines: 5

*

**

***

****

*****

would i use for loops here?

what code should i use?

please help me!

 Tags:

   Report

4 ANSWERS


  1. Yes, you need to use loop.

    It should be as follows:

    void main()

    {

         int n,l;

         cout<<"Enter no. of lines :";

         cin>>n;

         l = 1;

         while (l <= n)

         {

             int x = 1;

             while (x <= l)

            {

                  cout<<"*";

                  x++;

            }

            cout<<endl;

            l++;

         }

    getch();

    }

    Hope this helps.

    your_guide123@yahoo.com


  2. int r,c;

    for(r=1;r<=5;r++)

    {

    for(c=1;c<=r;c++)

    {

    cout<<"*";

    }

    cout<<"\n";

    }

      

  3. Use FOR LOOP, nested For Loop

    sample:

    for( int i = 0 ; i < 5 ; i++ )

    {

       for(int c = 0 ; c < i ; c++)

       {

        print("*");

       }

      println(""); // to goto next line

    }


  4. for (int i=0; i<5; i++){

    printf("*");

    }

    something like that

    run a loop and print * each time

    i am java guy so i am not so sure about the syntax i gave you

Question Stats

Latest activity: earlier.
This question has 4 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.