-
Notifications
You must be signed in to change notification settings - Fork 0
/
Chapter4-Q31.c
56 lines (38 loc) · 1 KB
/
Chapter4-Q31.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
Author is : Ibrahim Halil GEZER
4.31 (Diamond Printing Program) Write a program that prints the following diamond shape.
You may use printf statements that print either a single asterisk (*) or a single blank. Maximize
your use of repetition (with nested for statements) and minimize the number of printf statements.
*
***
*****
*******
*********
*******
*****
***
*
*/
#include<stdio.h>
int main (void)
{
int space , i , j;
int number = 5 ;
/* Top diamond */
for (i=1; i<=number; i++) { // inner for begins
for (space=number-i ; space>=1; space--) // outer for begins
printf (" ");
for (j=1; j <= (2*i-1); j++)
printf ("*");
printf ("\n") ;
} // // inner for ends
// bottom diamond
for ( i = 1; i <= number; i++ ) {
for (space=1; space <= i; space++ )
printf ( " " );
for (j =1 ; j<= (2*number-1)- 2*i ; j++ )
printf ("*") ;
printf ("\n");
}
return 0 ;
} // end function main