C++ program to print patterns using for loop



Source Code :

#include <iostream>
using namespace std;

int main(){

int in=12;
int a=in;
a/=2;


for(int i=1;i<=a+1;i++){

for(int j=1;j<=a+1;j++){
if(j<=a+2-i){
cout<<j;
}else{
   cout<<" ";
}

}
for(int x=a;x>=1;x--){
if(x<=a+2-i){
cout<<x;
}else{
cout<<" ";
}

}
cout<<endl;
}
}

No comments:

Post a Comment