+92 332 4229 857 99ProjectIdeas@Gmail.com

Upper portion of diamond (C++)


Upper Portion Of Diamond
upperPortionOfDiamond() drwas the upper portion of the diamond and it takes 2 parameters:
noOfLines takes the number of lines.
ch takes the character to be displayed in the upper portion of diamond.

Code

#include "stdafx.h"
#include "iostream"
#include "conio.h"
#include "iomanip"

using namespace std;

void upperPortionOfDiamond(int noOfLines,char ch)
{
   for(int i=0;i<noOfLines*2;i=i+2)
   {
      for(int j=0;j<((noOfLines*2)-2)-i;j=j+2)
              cout<<" ";
      
          for(int k=0;k<i+1;k++)
                     cout<<ch;
       cout<<endl;
   }
}

int main()
{
       upperPortionOfDiamond(8,'!');cout<<endl;
       upperPortionOfDiamond(8,'*');cout<<endl;
       upperPortionOfDiamond(8,'#');cout<<endl;

       _getche();
       return 0;
}
Output
       !
      !!!
     !!!!!
    !!!!!!!
   !!!!!!!!!
  !!!!!!!!!!!
 !!!!!!!!!!!!!
!!!!!!!!!!!!!!!

       *
      ***
     *****
    *******
   *********
  ***********
 *************
***************

       #
      ###
     #####
    #######
   #########
  ###########
 #############
###############

0 comments: