Write a program for following output using while loop

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

12 Answers

0 votes
answered Aug 11 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 by (410 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");
    }

}
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.
...