C program to Print the given Array in Spiral form: Spiral matrix. Produce a spiral array. A spiral array is a square arrangement of the first N2 natural numbers, where the. numbers increase sequentially as you go around the edges of the array spiraling inwards.
C program to Print the given Array in Spiral form
#include <stdio.h>
#define MAX 256
int main() {
int i, j, n, arr[MAX];
printf("Enter the number of array entries:");
scanf("%d", &n);
printf("Enter your array entries:\n");
for (i = 0; i < n; i++) {
printf("Data[%d]: ", i);
scanf("%d", &arr[i]);
}
printf("Printing given array in spiral form:\n");
for (i = 0; i < n; i++) {
if (i % 2 == 0) {
printf(" %d\n", arr[i]);
} else {
printf(" %d\n", arr[i]);
}
}
return 0;
}
Output of Program
Enter the number of array entries:4
Enter your array entries:
Data[0]: 3
Data[1]: 3
Data[2]: 7
Data[3]: 8
Printing given array in spiral form:
á3
á á3
á7
á á8