//Rhombus.cpp: Defines the entry point of the console application. //#include"stdafx.h"#include<iostream>#include<math.h>using namespacestd;voidRhombus (Char,Char,int);int_tmain (intARGC, _tchar*argv[]) {Rhombus ('O',' ',5); return 0;}voidRhombus (CharChsymbol='*',CharChspaece=' ',intrownum= One){ //Char chsymbol= ' * '; //symbols//Char chspaece= '; //Space//int rownum=11; //number of rows, which can be exported as odd-numbered diamonds intmidnum=rownum/2;//Middle Number for(intI=0; i<rownum;i++){ for(intj=0; j<rownum;j++) { intSymbolnum=i>midnum?2* (Rownum-i)-1:2*i+1;//Number of symbols intSpaecenum=abs (midnum-i);//Number of spaces if(J<spaecenum)//When looping to empty columnscout<<chspaece; Else if(J>=spaecenum&&j<spaecenum+symbolnum)//When looping to a symbol columncout<<Chsymbol; Else if(J>=spaecenum+symbolnum)//when the loop is over a symbol and then to a spacecout<<chspaece; } cout<<"\ n"; }}
Console Application C + + output diamond