Customizable training materials to learn C++

Looking for C++ Tutorial Visit Nano teach c++!
  • C++ Objects and Classes
    08/07/2014 - 0 Comments
    In object-oriented programming languages like C++, the data and functions (procedures to manipulate the data) are bundled together as a self-contained unit called an object. A…
  • C++ Data Types
    11/07/2014 - 0 Comments
    Data types in any of the language means that what are the various type of data the variables can have in that particular language. Information is stored in a computer memory…
Nano teach C++ found result for your search here:

C++ Loops, Creating a Pyramid

C++ program to create a pyramid using for loop and if condition.
Example:
#include<iostream>
using namespace std;

int main()
{
   int i,j,k,space=10; // to print the pyramid in center, you can also increase the # of spaces
   
for (int i=0;i<=5;i++)
{
   for (int k=0;k<space;k++)
{
   cout<<" ";
}
for (int j=0;j<2*i-1;j++)
{
   cout<<"*";
}
   space--;
   cout<<endl;
}
cin.get(); /*use this to wait for a keypress*/

} 
 















Program Output:
         *
        ***
       *****
      *******
     *********

No comments:

Post a Comment