Search
 
SCRIPT & CODE EXAMPLE
 

CPP

Programs for printing pyramid patterns in C++

#include<iostream>
using namespace std;

int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j <= i; j++)
		{
			cout << "*";
		}
		cout << "
";
	}
	return 0;
}
Comment

Pyramid pattren program in C++

#include <iostream>
using namespace std;

int main() {
  int size = 5;
  for (int i = 0; i < size; i++) {
    // print spaces
    for (int j = 0; j < size - i - 1; j++) {
      cout << " ";
    }
    // print stars
    for (int k = 0; k < 2 * i + 1; k++) {
      cout << "*";
    }
    cout << "
";
  }
  return 0;
}

/* Output
    *
   ***
  *****
 *******
*********

*/
Comment

the pyramid in c++

#include <iostream>
using namespace std;

int main()
{
    int rows;

    cout << "Enter number of rows: ";
    cin >> rows;
	
  	int i = 1;
    while(i  <= rows)
    {
      	int j = 1
        while(j <= i)
        {
            cout << "* ";
          	j++
        }
        cout << "
";
      	i++;
    }
    return 0;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: how to return char* from function in c++ 
Cpp :: c++ vector initialization 
Cpp :: sort vector in reverse order c++ 
Cpp :: c++ pi float 
Cpp :: why is using namespace std a bad practice 
Cpp :: c++ output 
Cpp :: how to sort in descending order in c++ 
Cpp :: throw exception c++ 
Cpp :: what is thread in c++ 
Cpp :: C++ break with for loop 
Cpp :: sorting vector elements c++ 
Cpp :: comparator in sort c++ 
Cpp :: c++ ternary operator 
Cpp :: how to get the time in c++ as string 
Cpp :: length of string in c++ 
Cpp :: cpp getter as const 
Cpp :: c++ map insert 
Cpp :: c detect os 
Cpp :: c++ char array size 
Cpp :: zero fill in c++ 
Cpp :: c++ thread 
Cpp :: hello c++ 
Cpp :: size of a matrix using vector c++ 
Cpp :: c for loop decrement 
Cpp :: count sort algorithm 
Cpp :: c++ math 
Cpp :: take a function argument 
Cpp :: how to empty a std vector 
Cpp :: c++ remove all elements equal to 
Cpp :: how to declare a 2d vector stack 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =