program to print stars

// program to print the star (*) as show bellow :
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int s, c,i;
for (s = 20, c = 1; c <= 40; c += 2, s--)
{
cout<<setw(s);
for (i = 1; i <= c; i++)
cout << "*";
cout << endl;
}
system("pause");
}

this is the program basicaly i don't know how c+=2, condition is working in loop?
can any one explain this program?
I tried to run your code, and this happened:


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


Is that what is supposed to happen? If not, then want do you want your code to do?
Topic archived. No new replies allowed.