Tuesday, 12 February 2013

Write a c program to accept mXn matrix from user and display the elements of given matrix using function



#include<stdio.h>
#include<conio.h>
  void main()
{
  void mat(int,int);
  int r,c;
  clrscr();
  printf("\n Enter the limit row \n");
  scanf("%d",&r);
  printf("\n Enter the coloum col \n");
  scanf("%d",&c);
  mat(r,c);
  getch();
}
  void mat (int r,int c)
{
  int a[10][20];
  int i=0,j=0;
  printf("\nEnter the matrix element \n");
  for(i=0;i<r;i++)
{
  for(j=0;j<c;j++)
{
  scanf("%d",&a[i][j]);
}
}
  printf("\nThe entered matrix is:\n\n");
  for(i=0;i<r;i++)
{
  for(j=0;j<c;j++)
{
  printf("\t%d",a[i][j]);
}
  printf("\n");
}
}

OUTPUT:

Enter the limit row
 3

Enter the coloum col
3
Enter the matrix element
1
2
3
4
5
6
7
8
9

The entered matrix is:

    1       2       3
    4       5       6
   7       8       9

No comments:

Post a Comment