0

I can not remember how to do this for anything.
I need to make a pyramid look like this using a while loop

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

I can do it using a for loop, but when I do a while all I get is the first row the ten rows and just one column. any help?

#include<stdio.h>
#include <iostream>
int main (void)
{
 int row,col;
 int num;
 

num=10;
row=0;
col=0;

 while(row<=num)
 {
              row++;
    while(col<row)
    
           col++;    
        printf("* ");
 printf("\n");

 }


system("PAUSE");

return 0;
}
3
Contributors
3
Replies
5
Views
7 Years
Discussion Span
Last Post by aamira_s
0

You were close...

#include<stdio.h>

int main (void)
{
  int row,col;
  int num;


  num=10;
  row=0;
  col=0;

  while(row<=num)
  {
    row++;
    while(col<row)
    {
      col++;    
      printf("* ");
     }
    printf("\n");
    col = 0;
  }

  return 0;
}
0

Thanks.
So for future reference. I forgot the brackets on the second while and I had to reset the columns to zero?

0
#include<stdio.h>
int main()
{
    int i,j,n=10;
    for(i=1;i<=n;i++){
       for(j=1;j<=i;j++){
        printf("*");
       }
       printf("\n");
    }
    return 0;
}

Edited by Nick Evan: Fixed formatting

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.