Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a C++ program that draw a diamond as the sample execution below. In the pr

ID: 639345 • Letter: W

Question

Write a C++ program that draw a diamond as the sample execution below. In the program, you can assume that the number given by a user is always valid (= positive number). In the program, you must use only pointer variables and dynamic memory. [For instance, even an index variable in a loop must be a pointer variable]. A sample run of your program should be like below:

Enter a number: 5

*

***

*****

*******

*********

*******

*****

***

*

This is another sample run of your program:

Enter a number: 3

*

***

*****

***

*

Explanation / Answer

#include <iostream>
using namespace std;

int main()
{
cout << "Hello World";
for(int i=1; i<5; i++)

{

for(int j=1; j<=i; j++)

{

cout<<"*";

}

cout<<endl<<endl;

}
for(int i=5; i>=1; i--)

{

for(int j=1; j<=i; j++)

{

cout<<"*" ;

}

cout<<endl<<endl;

}
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote