-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnumberSquarePattern.c
More file actions
44 lines (39 loc) · 806 Bytes
/
numberSquarePattern.c
File metadata and controls
44 lines (39 loc) · 806 Bytes
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
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main()
{
int n, size, start, end;
scanf("%d", &n);
// Complete the code to print the pattern.
size = (2 * n) - 1;
start = 0;
end = size - 1;
int a[size][size];
while (n != 0)
{
for (int i = start; i <= end; i++)
{
for (int j = start; j <= end; j++)
{
if (i == start || i == end || j == start || j == end)
{
a[i][j] = n;
}
}
}
++start;
--end;
--n;
}
for (int i = 0; i < size; i++)
{
for (int j = 0; j < size; j++)
{
printf("%d ", a[i][j]);
}
printf("\n");
}
return 0;
}