How to make diamond pattern using for loop in c++ || understand logic o...

#include<iostream>
#include<conio.h>
using namespace std;
int main()
{     // MH Computer Academy 
// Muhammad Hahsmi 
int i, j, r;
cout<<"\n\n Display the Pattern Like a Dimond:\n";
cout<<"----------------------------------------"<<endl;
cout<<"Input number of rows (Half of the Diamond)";
cin>>r;
for(i=1;i<=r;i++)// outer for loop for no of Rows
{
for(j=1;j<=r-i;j++)
{
cout<<" ";
}
for(int k=1;k<=2*i-1;k++)
{
cout<<"*";
}cout<<endl; 
}
// second half diamond 
for(i=r-1;i>=1;i--)// outer for loop for no of Rows
{
for(j=1;j<=r-i;j++)
{
cout<<" ";
}
for(int k=1;k<=2*i-1;k++)
{
cout<<"*";
}cout<<endl; 
}
return 0;
getch();
}

Comments

Popular posts from this blog

How to create Simple ATM Machine in C++ Program||ATM Program deposit withdraw money in c++|Using CLI || C++ project with Source Code || MH Computer Academy(Muhammad Hashmi)

How to Calculate GPA/CGPA || GPA Calculator Step by Step in C++ ||Sourc...

C++ Project GYM Management System || Source Code with Explanation | MH Computer Academy || Muhammad Hashmi || Learn Programming