Program:
#include<stdio.h>
void main()
{
int arr[10][10],i, j, k,n,middle,size;
printf("\nEnter the order:\n");
scanf("%d",&size);
printf("Enter the matrix:\n");
for(i=0;i<size;i++)
for(j=0;j<size;j++)
scanf("%d",&arr[i][j]);
for(i=size-1, j=0; i > 0; i--, j++)
{
for(k=j; k < i; k++)
printf("%d ", arr[j][k]);
for(k=j; k < i; k++)
printf("%d ", arr[k][i]);
for(k=i; k > j; k--)
printf("%d ", arr[i][k]);
for(k=i; k > j; k--)
printf("%d ", arr[k][j]);
}
middle = (size-1)/2;
if (size % 2 == 1)
printf("%d\n", arr[middle][middle]);
}
Output:
nn@linuxmint ~ $ gcc c28.c
nn@linuxmint ~ $ ./a.out
Enter the order:
3
Enter the matrix:
1
2
3
4
5
6
7
8
9
1 2 3 6 9 8 7 4 5
nn@linuxmint ~ $
#include<stdio.h>
void main()
{
int arr[10][10],i, j, k,n,middle,size;
printf("\nEnter the order:\n");
scanf("%d",&size);
printf("Enter the matrix:\n");
for(i=0;i<size;i++)
for(j=0;j<size;j++)
scanf("%d",&arr[i][j]);
for(i=size-1, j=0; i > 0; i--, j++)
{
for(k=j; k < i; k++)
printf("%d ", arr[j][k]);
for(k=j; k < i; k++)
printf("%d ", arr[k][i]);
for(k=i; k > j; k--)
printf("%d ", arr[i][k]);
for(k=i; k > j; k--)
printf("%d ", arr[k][j]);
}
middle = (size-1)/2;
if (size % 2 == 1)
printf("%d\n", arr[middle][middle]);
}
Output:
nn@linuxmint ~ $ gcc c28.c
nn@linuxmint ~ $ ./a.out
Enter the order:
3
Enter the matrix:
1
2
3
4
5
6
7
8
9
1 2 3 6 9 8 7 4 5
nn@linuxmint ~ $
Nice blog. Your blog Information is awesome. Thanks for sharing information.
ReplyDeletehow to fix brother printer offline issue
Food Tray Box Packaging Wholesale
ReplyDelete