Regarding this Hollow diamond pattern

This is my code yet i am getting wrong answer,
Can any one help me??

#include
using namespace std;
//inbulit sort
int main() {
int n;
cin>>n;
for(int i=1;i<=n;i++) cout<<"* ā€œ;
cout<<endl;
for(int i=1;i<=n/2;i++){
for(int j=1;j<=((n-1)/2)-i+1;j++) cout<<ā€* ";
for(int j=1;j<=2i-1;j++) cout<<" ā€œ;
for(int j=1;j<=((n-1)/2)-i+1;j++) cout<<ā€
ā€œ;
cout<<endl;
}
for(int i=n/2;i>=1;i–){
for(int j=1;j<=((n-1)/2)-i+1;j++) cout<<ā€* ";
for(int j=1;j<=2i-1;j++) cout<<" ā€œ;
for(int j=1;j<=((n-1)/2)-i+1;j++) cout<<ā€
ā€œ;
cout<<endl;
}
for(int i=1;i<=n;i++) cout<<ā€* ";
cout<<endl;
return 0;
}

Actually there is some mistake in the upper code ,

This is the code: #include #include using namespace std; int main() { int n; cin>>n; for(int i=1;i<=n;i++) {cout<<"* ā€œ;} cout<<endl; for(int i=1;i<=n/2;i++){ for(int j=1;j<=((n-1)/2)-i+1;j++) {cout<<ā€* ";} for(int j=1;j<=2i-1;j++){ cout<<" ā€œ;} for(int j=1;j<=((n-1)/2)-i+1;j++){ cout<<ā€ ā€œ;} cout<<endl; } for(int i=n/2;i>=1;i–){ for(int j=1;j<=((n-1)/2)-i+1;j++){ cout<<ā€* ";} for(int j=1;j<=2i-1;j++) {cout<<" ā€œ;} for(int j=1;j<=((n-1)/2)-i+1;j++) {cout<<ā€ ā€œ;} cout<<endl; } for(int i=1;i<=n;i++) {cout<<ā€* ";} cout<<endl; return 0; }

@gods_eye,
Corrected code, here.
And please use Coding Blocks IDE for sharing code here next time, see yourself, can you understand such an untidy code?

1 Like