Pages

Monday, 30 April 2018

Array Input using function

A, B and C are three 3x3 matrices containing real elements. Write a ‘C’ function to input from user appropriate values into matrices A and B. Use suitable loops. Make use of pointers if necessary.

Solution : 

/*==============================
Girfa Student Help
Program : 3x3 Array input using function
More Program : http://girfahelp.blogspot.in/p/2-d-array-programming.html
================================*/
#include<stdio.h>
#include<conio.h>
#define MAX 3
void input(int [][MAX]);
void print(int [][MAX]);

void main()
{
     int ar[MAX][MAX];
     clrscr();
     input(ar);
     print(ar);
     getch();
}
void input(int ar[][MAX])
{
     int r,c;
     for(r=0;r<MAX;r++)
     {
          for(c=0;c<MAX;c++)
          {
              printf("Enter number>> ");
              scanf("%d",&ar[r][c]);
          }
     }
}
void print(int ar[][MAX])
{
     int r,c;
     for(r=0;r<MAX;r++)
     {
          for(c=0;c<MAX;c++)
          {
              printf("\t%d",ar[r][c]);
          }
          printf("\n");
     }

}

No comments:

Post a Comment