Make Shapes with C++


Make Diamond, Pyramid, Triangle and more with loops




*Featured Code Created By Saad Mughal



C++ Source Code


/*Printing Differnt Shapes using for loop*/
#include <iostream>
using namespace std;
void pyrmid()
{
int row, c, n = 10, temp;
//"Enter the number of rows in pyramid of stars you wish to see ";
temp = n;
for ( row = 1 ; row <= n ; row++ )
{
for ( c = 1 ; c < temp ; c++ )
cout<<" ";
/*Leaving spaces before printing * */
temp--;
for ( c = 1 ; c <= 2*row - 1 ; c++ )
cout<<"*";
/*Printing stars by calculating rows */
cout<<"\n";
/*moving to new line after printing one */
}
 
 
 
}
void Daimond()
{
int n = 10, c, k, space = 1;
//cout<<"n is number of rows\n";
space = n - 1;
/*here we will divide diamond in 2 parts upper and lower */
/*printing upper part*/
for (k = 1; k <= n; k++)
{
for (c = 1; c <= space; c++)
cout<<" ";
/*leaving space before printing * */
space--;
for (c = 1; c <= 2*k-1; c++)
cout<<"*";
/*printing * by calculating row no */

Click here to run this code





Comments

Popular posts from this blog

Multi-tap Keypad Text Entry

Crypto Mining