+92 332 4229 857 99ProjectIdeas@Gmail.com

Lower portion of diamond (C++)


Lower portion of diamond
lowerPortionOfDiamond() drwas the lower portion of the diamond and it takes 2 parameters:
noOfLines takes the number of lines.
ch takes the character to be displayed in the lower portion of diamond.

Code

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

using namespace std;

void lowerPortionOfDiamond(int noOfLines,char ch)
{
   for(int l=0;l<noOfLines*2;l=l+2)
   {
     for(int m=0;m<l;m=m+2)
              cout<<" ";
    
                     for(int n=0;n<(noOfLines*2)-l-1;n=n+1)
                           cout<<ch;
        cout<<endl;  
   }
}

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

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

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

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

0 comments: