-2

can someone help me, I need a program like this but it must not use for loop.
or can someone revise it using do loop? I need it badly

here is the code:

{


int n, i, j;

do{
    printf("Enter a positive int n: ");
    scanf("%d",&n);

   } while (n < 0); 




  do{


    for (i = 1; i <= n; i++)
    {
     for (j = 1; j <= i; j++)
         printf("*");
         printf("\n");                

    }


 } while (i <= n);        
getch();



}
2
Contributors
1
Reply
19
Views
3 Years
Discussion Span
Last Post by NathanOliver
0

No one is going to do your work for you. There is little difference in a do-while loop compared to a for loop. Yopu just have to make your own counter and take care of it with a do while loop versus a for loop. Here is how you can chnage a for loop to a do-while loop:

for (int i = 0 /*variables*/; i < 10 /* condition */; i++ /*increment section */)
    {
        //do stuff
    }

    // becomes

    int i = 0; // variable section
    do
    {
        //do stuff
        i++; // dont forget to increment the counter.  increment section
    } while (i < 10) // condtion 

Now that you have that you should be able to do it with a for loop and then once that is working you can convert the for loop to a do-while loop.

Edited by NathanOliver

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.