Customizable training materials to learn C++

Looking for C++ Tutorial Visit Nano teach c++!
  • C++ Program to find Prime Number
    02/07/2014 - 0 Comments
    A prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself. Example: #include<iostream> #include<math.h>…
  • C++ Inheritance
    07/07/2014 - 0 Comments
    One of the most important concepts in object-oriented programming is that of inheritance. Inheritance is a mechanism of reusing and extending existing classes without modifying…
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