-
Notifications
You must be signed in to change notification settings - Fork 0
/
Lecture15 AlgorithmicShapes.c
79 lines (58 loc) · 1.22 KB
/
Lecture15 AlgorithmicShapes.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <stdio.h>
#include <stdlib.h>
//Written by Bunyamin Yavuz in 2022
//Drawing shapes to improve algorithmic talent
int main()
{
/* <---Drawing some shapes--->
First example output;
*
**
***
****
*****
Second example output:
*****
****
***
**
*
*/
//First shape example
int i,j;
/*
The important part is to understand the first for loop is for the number of rows
and the second loop is for column structure.
*/
for(i = 1; i <= 5;i++)
{
for(j = 1; j <= i; j++)
{
printf("*");
}
printf("\n");
}
//Second shape example
for(i = 1; i <= 5;i++)
{
for(j = 5; j >= i; j--)
{
printf("*");
}
printf("\n");
}
//Third example
//Allow the user to determine the number of row and column and draw the rectangular with "*"
int row,column;
int x,y;
printf("Enter the number of row and column: ");
scanf("%d %d",&row,&column);
for(x = 1; x <= row;x++)
{
for(y = 1; y <= column; y++)
{
printf("*");
}printf("\n");
}
return 0;
}