/* Demonstrates passing a pointer to a multidimensional */
/* array to a function. */
#include <stdio.h>
void printarray_1(int (*ptr)[4]);
void printarray_2(int (*ptr)[4], int );
void main()
{
  int  multi[3][4] = { { 1, 2, 3, 4 },
    { 5, 6, 7, 8 },
    { 9, 10, 11, 12 } };
  /* ptr is a pointer to an array of 4 ints. */
  int (*ptr)[4], count;
  /* Set ptr to point to the first element of multi. */
  ptr = multi;
  /* With each loop, ptr is incremented to point at the next*/
  /* element (that is, next 4-element integer array) of multi.*/
  for (count = 0; count < 3; count++)
    printarray_1(ptr++);
  puts("\n\nPress a key...");
  getchar();
  printarray_2(multi, 3);
}
void printarray_1(int (*ptr)[4])
{
  /* Prints the elements of a single 4-element integer array. */
  /* p is a pointer to type int. You must use a type cast */
  /* to make p equal to the address in ptr. */
  int *p, count;
  p = (int *)ptr;
  for (count = 0; count < 4; count++)
    printf("\n%d", *p++);
}
void printarray_2(int (*ptr)[4], int n)
{
  /* Prints the elements of an[]by four-element integer array. */
  int *p, count;
  p = (int *)ptr;
  for (count = 0; count < (4 * n); count++)
  printf("\n%d", *p++);
}

#include <stdio.h>
/*summation function*/
int summatrix ();

int summatrix (a, b,n,m)
int a[][100]; int b[][100];
int n; int m;
{
	int sum=0, j=0, o=0;
	int c[100][100]; int n1; int m1;

	while (o<=m-1){
		while (j<=n-1){
			c[j][o]=a[j][o]+b[j][o];
			j++;
		}
  		o++;
	}
	return (sum);
}

main ()
{

  /* initialize variables 
  int summatrix (int a[][], int b[][], int n, int m);
  */
  int n, m, i, l=0;
  int a[100][100], b[100][100];
  n=100;
  m=100;

 /*input rows and columns of both arrays */
  puts("Enter the # of rows and columns for both arrays");
  scanf("%i, %i", &n, &m);
  /*enter first two dimension array*/
  while (l<=m-1){
	 i=0;
	 while (i<=n-1){
	  	printf("Enter array 1, row %i, column %i:", i, l);
		scanf("%i", &a[i][l]);
	  	i++;
	 }
  }
 /*re-initialize variables*/
	l=1;  
 /*enter second two dimension array*/
 	while (l<=m-1){
	 	i=0;
	 	while (i<=n-1){
			printf("Enter array 2, row %i, column %i:", i, l);
	    	scanf("%i", &b[i][l]);
			i++;
		}
	}
   printf("The sum is %i \n", summatrix (a, b, n, m));
}

About this document ...

This document was generated using the LaTeX2HTML translator Version 96.1 (Feb 5, 1996) Copyright © 1993, 1994, 1995, 1996, Nikos Drakos, Computer Based Learning Unit, University of Leeds.

The command line arguments were:
latex2html -split 0 -html_version 3.0 multi.tex.

The translation was initiated by Vijay & on Thu Apr 2 10:52:25 EST 1998


Vijay &
Thu Apr 2 10:52:25 EST 1998