
// diamond2.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream.h>
int main()
{
int Max_DiamondRange = 100, MainCounter = 1;
int LoopRange = ((Max_DiamondRange - 2)/4); //For Running Upper and Lower Loop Seprate.
int StartRange = 1;
int EndRange = 0;
//Print 1st *
cout<<"Diamond Structure with "<<Max_DiamondRange<<" '*'."<<endl<<endl<<endl;
while((LoopRange+1) >= MainCounter){
cout<<" ";
MainCounter++;
}
cout<<"*"<<endl;
//Generate Upper Body of the diamond
MainCounter = 1;
while(LoopRange >= MainCounter){
StartRange = 1;
EndRange = (LoopRange - MainCounter) + 1;
while(EndRange >= StartRange){
cout<<" ";
StartRange++;
}
cout<<"*";
StartRange = 1;
EndRange = (2 * MainCounter)-1;
while(EndRange >= StartRange){
cout<<" ";
StartRange++;
}
cout<<"*"<<endl;
MainCounter++;
}
//Generate lower Body of the diamond
MainCounter = 1;
while(LoopRange >= MainCounter){
StartRange = 1;
EndRange = MainCounter;
while(EndRange >= StartRange){
cout<<" ";
StartRange++;
}
cout<<"*";
StartRange = 1;
EndRange = ((LoopRange * 2) - (MainCounter * 2)+1);
while(EndRange >= StartRange){
cout<<" ";
StartRange++;
}
cout<<"*"<<endl;
MainCounter++;
}
//Print last *
MainCounter = 1;
while((LoopRange+1) >= MainCounter){
cout<<" ";
MainCounter++;
}
cout<<"*"<<endl<<endl;
cout<<"HeHeHe !"<<endl;
return 0;
}
Diamond shape example in c/c++ source code, Diamond shapeexample source code, source code,
Diamond shape example in c/c++ source code, Diamond shapeexample source code, source code,
Diamond shape example in c/c++ source code, Diamond shapeexample source code, source code,
Diamond shape example in c/c++ source code, Diamond shapeexample source code, source code,
Dear Readers if you have any query/question feel free to ask me via comment box given below. Also Follow us on social media site and share that post with your friends. - See more at: http://onlinecomputercafe.blogspot.com/2015/12/lcm-source-code-example-in-cc-source.html#sthash.oxxMKP7j.dpuf
useful tutorial keep it up...
EmoticonEmoticon