how can i create something of this sort:

*
***
*****
*******
*********
*******
*****
***
*

this is my source code:

#include <stdio.h>


int main()
{
int i;
i = 1;
while(i <= 5)
{


printf("*\n");


i++;


}



getchar();
}

Edited 3 Years Ago by Nick Evan: Fixed formatting

With two for loops, one nested inside the other. The outer for loop manages the rows, and the inner for loop manages the variables for the columns inside the row being printed.

Remember that the total width of the diagram, minus the number of stars you print on that row, is the number of spaces that must be printed on the row.

#include<stdio.h>
#define LINES 9
int main()
{
int i,j;
for(i=1;i<=LINES;i++)
{
    if(i-1<=LINES/2)
      {
       for(j=1;j<=i;j++)
            printf("*");
      }
    else
     {
       for(j=LINES;j>=i;j--)
            printf("*");
      }
printf("\n");
}
getchar();
}

Just change the define number as per the number of lines u require

Edited 5 Years Ago by timetraveller92: n/a

Comments
We do NOT do homework for others! That's called cheating! We help them find their own solutions.
This question has already been answered. Start a new discussion instead.