0

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 by Nick Evan: Fixed formatting

3
Contributors
3
Replies
6
Views
5 Years
Discussion Span
Last Post by collinskawere
0

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.

-1
#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 by timetraveller92: n/a

Votes + 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.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.