Posts
Showing posts from December, 2020
How to make diamond pattern using for loop in c++ || understand logic o...
- Get link
- X
- Other Apps
#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(); }