forked from KISHOREMUTHU/Data-Structures-And-Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomplex_number_pattern.c
More file actions
67 lines (35 loc) · 1.2 KB
/
Copy pathcomplex_number_pattern.c
File metadata and controls
67 lines (35 loc) · 1.2 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
# Data-Structures-And-Algorithms
Here I will post my regular DSA problems
#include<stdio.h>
// Complex number pattern program
int main (){
int n;
printf( "Enter 'n' value : " );
scanf("%d",&n); // Getting user input
int total = 2*n-1;
// Consider the pattern to be an array of numbers
int a[total][total];
int i,j,k=1;
int l=n;
// for loop for assigning the value to each array element
while(k<=n){
for(i=k;i<=total;i++){
for(j=k;j<=total;j++){
if(i==k||i==total||j==k||j==total){
a[i][j] = l;
}
}
}
l--;
k++;
total--;
}
printf("\nThe answer is :\n\n");
// for loop for printing the answers
for(i=1;i<=2*n-1;i++){
for(j=1;j<=2*n-1;j++){
printf ("%d ",a[i][j]);
}
printf("\n");
}
}