Program No : 45 :

Write a program in C to read and display a 3 x 3 Matrix ?

                  program no  :45
purpose : read and print a 3 x 3 matrix

#include<"stdio.h">
#include<"conio.h">

main ()
{
	
	int *a;
	a=(int *) malloc(3 * sizeof(int));
	a[0]=(int *) malloc(3 * sizeof(int));
	a[1]=(int *) malloc(3 * sizeof(int));
	a[2]=(int *) malloc(3 * sizeof(int));
	readmatrix(a);

	printmatrix(a);

	getch();

}

readmatrix(m)
int *m;
{
	int i, j;

	for(i=0;i<3;i++)
		for (j=0; j<3;j++)

			scanf("%d", m+i*3+j);
}

printmatrix(m)
int *m;
{
	int i,j;
	for(i=0;i<3;i++)
	{
		for (j=0; j<3;j++)
			printf("%d  ", *(m+i*3+j));
		printf("\n");
	}
}  

Back