C program to generate a square matrix

Example#1

#include<stdio.h>
int main()
{
	int n,i,j,a[30][30];
	printf("Enter size of array:");
	scanf("%d",&n);
	printf("Matrix elements are:");
	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
		{
			scanf("%d",&a[i][j]);
		}
	}
	printf("%d*%d matrix is:\n",n,n);
	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
		{
			printf("%d ",a[i][j]);
		}
		printf("\n");
	}
	return 0;
}

Output:

Facebook Comments

Back to Top