-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp160202020.cpp
More file actions
84 lines (67 loc) · 1.75 KB
/
p160202020.cpp
File metadata and controls
84 lines (67 loc) · 1.75 KB
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
80
81
82
83
84
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
const int DIMEN = 24;
// fill the canvas with NULLs
char canvas [DIMEN][DIMEN] = {{0}};
// the origin will be at (12, 12)
// so that our drawing is at the middle
// all the points that satisfy the
// equation x^2 + y^2 = 4^2 will be
// filled as *
for(int row = 0; row < DIMEN; row++)
{
for(int col = 0; col < DIMEN; col++)
{
// origin is at the center,
// so obtain the x and y coordinates
// of each element with respect to the
// middle
int x = col - DIMEN/2;
int y = DIMEN/2 - row;
// x^2 + y^2 = 10^2
// since we are dealing with
// integers, we can keep
// a +/-5 tolerance for nicer looks
int sumsq = x*x + y*y;
if((95 < sumsq) && (sumsq < 105))
{
canvas[row][col] = '*';
}
}
}
// print
for(int row = 0; row < DIMEN; row++)
{
for(int col = 0; col < DIMEN; col++)
{
// THERE IS A SPACE AFTER %c
// done for nicer looks
printf("%c ", canvas[row][col]);
}
cout << endl;
}
return 0;
}
// output of the above program
/*
* * * * *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* * * * *
*/