Star Pattern with 1,3,7,15,31,63 sequence logic.

Hi, I am stuck on this program:

Write a program to print following output:

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


I figured out that the logic is "every row is the double of the previous row plus 1". But I am failing to write it in the programming language. Can somebody give me a quick reply regarding the logic used in the program?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include<iostream>
#include<conio.h>
#include<stdio.h>

	void main()
   {
    clrscr();
    int row,column,n;
    n=1;
    for(column=1;column<=63;column++)
        {
            for(row=1;row<=column;row++)
                {
                   n=row+row+1;
                    cout<<n;
                 }
         cout<<endl;
        }
      getch();
    }
1
2
3
4
int num=0;
for each row
   num = 2 * num + 1
   print "num" stars, following by a newline

Please can you write the whole program again? I can not understand. :(
GOT IT!

[code]
#include<iostream>
#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
int r,n;
for(n=0;n<=63;)
{
for(r=1;r<=n;r++)
{
cout<<"*";
}
n=2*n+1;
cout<<endl;
}
getch();
}
[\code]
Topic archived. No new replies allowed.