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

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

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

#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;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.