write a main function to get an int N from the user and prin

write a main function to get an int N from the user and print the following pattern, shown examples are N = 4 and N = 5.

N = 4

*

***

*****

*******

N = 5

*

***

*****

*******

*********

each line adds 2 stars. total lines = N.

Solution


// C++ code
#include <iostream>
#include <string>
#include <fstream>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <iomanip>      // std::setprecision

using namespace std;

int main()
{

   int n;
   cout << \"Enter n: \";
   cin >> n;

   for (int i = 1; i < 2*n; i=i+2)
   {
       for (int j = 1; j <= i; ++j)
       {
           cout << \"*\";
       }

       cout << endl;
   }

}

/*
output:

Enter n: 5
*
***
*****
*******
*********


Enter n: 4
*
***
*****
*******


*/

write a main function to get an int N from the user and print the following pattern, shown examples are N = 4 and N = 5. N = 4 * *** ***** ******* N = 5 * *** *
write a main function to get an int N from the user and print the following pattern, shown examples are N = 4 and N = 5. N = 4 * *** ***** ******* N = 5 * *** *

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site