Explain Quiz II 1
No.
Code
1
//The diamond point
2
#include<stdio.h>
3
#include<stdlib.h>
4
main()
5
{
6
int n;
7
int x, y;
8
printf("Enter a odd positive integer : ");
9
scanf("%d", &n);
10
for(x=n/2;x>=-n/2;x--)
11
{
12
for(y=-n/2;y<=n/2;y++)
13
{
14
if((abs(x)+abs(y))==n/2)
15
{
16
printf("x");
17
}
18
else if((abs(x)==abs(y))&&(abs(x)<=n/4)&&(abs(y)<=n/4))
19
{
20
printf("x");
21
}
22
else if((abs(x)+abs(y))<n/2)
23
{
24
printf(".");
25
}
26
else
27
{
28
printf(" ");
29
30
}
31
}
32
printf("\n");
33
}
34
}
17
x
8
*
7
* . *
6
* .
.
. *
5
* .
.
.
.
. *
4
* .
.
.
.
.
.
. *
3
* . * .
.
.
.
. * . *
2
* .
.
. * .
.
. * .
.
. *
1
* .
.
.
.
. * . * .
.
.
.
. *
0 * .
.
.
.
.
.
. * .
.
.
.
.
.
. *
-1
* .
.
.
.
. * . * .
.
.
.
. *
-2
* .
.
. * .
.
. * .
.
. *
-3
* . * .
.
.
.
. * . *
-4
* .
.
.
.
.
.
. *
-5
* .
.
.
.
. *
-6
* .
.
. *
-7
* . *
-8
*
-8
-7
-6
-5
-4
-3
-2
-1
0
1
2
3
4
5
6
7
8
y
• ก
10 for(x=n/2;x>=-n/2;x--) กก ก
• ก
12 for(y=-n/2;y<=n/2;y++) กก ก
• ก
14 if((abs(x)+abs(y))==n/2) ก plot
* ก!"#"$ |x|+|y| = n/2 %$#"$
ก& Diamond '(
• ก
18 else if((abs(x)==abs(y))&&(abs(x)<=n/4)&&(abs(y)<=n/4)) ก plot
*
ก!"#"$ |x|=|y| %)