Write A Program To Create A Matrix
Code::
#include<stdlib.h>
int main()
{
int **a,i,j,r,c;
printf("Enter the size of row and coloumn\n");
scanf("%d%d",&r,&c);
a=(int**)malloc(r*sizeof(int));
for(i=0;i<c;i++)
{
a[i]=(int*)malloc(c*sizeof(int));
}
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf("Enter elemens the position of %d%d\n",i,j);
scanf("%d",&a[i][j]);
}
}
printf("the result is-->\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf("%4d",a[i][j]);
}
printf("\n");
}
return 0;
}
Input::
Enter the size of row and coloumn
3
3
Enter elemens the position of 00
1
Enter elemens the position of 01
2
Enter elemens the position of 02
3
Enter elemens the position of 10
4
Enter elemens the position of 11
5
Enter elemens the position of 12
6
Enter elemens the position of 20
7
Enter elemens the position of 21
8
Enter elemens the position of 22
9
Output::
the result is-->
1 2 3
4 5 6
7 8 9
ReplyDeleteget all updates about tech from
Software Updates