Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Write a program for following output using while loop

+13 votes
asked Jul 30, 2019 by Mohana 1 flag
*
* *
* * *
* * * *
* * * * *
* * * *
* * *
* *
*
(If the range is 5)

13 Answers

0 votes
answered Aug 11, 2019 by Lucifer

#include <stdio.h>

int main()

{   

    int i,j;

    

    for(i=1;i<=5;i++)    //This block is used to print the                                   //increasing sequence

    {  

       for(j=1;j<=i;j++)

          printf("*");

      printf("\n");

    }

    

for(i=4;i>=1;i--) // This block to print the decreasing sequence

    {  

       for(j=1;j<=i;j++)

          printf("*");

      printf("\n");

    }

 return 0;

 } // main ends

   

0 votes
answered Aug 22, 2019 by Jongbo (470 points)
#include <stdio.h>

void main ()
{

  int i, j, k = 1, n;
  for (i = 0; i < 9; i++)
    {
      for (j = 0; j < k; j++)
    {

      printf ("*");

    }

      n++;
      if (n > 4)
    {
      k--;
    }
      else if (n < 5)
    {
      k++;
    }

      printf ("\n");
    }

}
0 votes
answered Oct 12, 2019 by Rohan Ghobade (520 points)
Share Code:   
https://onlinegdb.com/BkxzXQkFS
Embed Code:   
<script src="//onlinegdb.com/embed/js/BkxzXQkFS?theme=dark"></script>


Go to this link I have done with while loop and code size is small
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...