Print a diamond of *: the top half has n rows, and row i has 2i - 1 stars after n - i spaces; the bottom half is the same upside down, one row shorter. row(spaces, stars) is already written and prints one row. Finish diamond(n); the program prints one with n = 3 and one with n = 4.
* *** ***** *** * * *** ***** ******* ***** *** *
#include <stdio.h>
void row(int spaces, int stars) {
for (int i = 0; i < spaces; i++) printf(" ");
for (int i = 0; i < stars; i++) printf("*");
printf("\n");
}
void diamond(int n) {
for (int i = 1; i <= n; i++) {
// your code here: row i of the top half
}
for (int i = n - 1; i >= 1; i--) {
// your code here: the bottom half, the same row as the top
}
}
int main(void) {
diamond(3);
diamond(4);
return 0;
}
Run tries the examples. When they look right, Submit.