SHARE
TWEET

Untitled

a guest Jun 19th, 2017 33 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <stdio.h>
  3.  
  4. #define ROWS 3
  5. #define COLS 5
  6.  
  7. struct ARRAYSTRUCT {
  8.     int A[ROWS][COLS];
  9. };
  10.  
  11. int sum(ARRAYSTRUCT * mystruct) {
  12.   int total = 0;
  13.   for (int i = 0; i < ROWS; i++)
  14.      for (int j = 0; j < COLS; j++)
  15.         total += mystruct->A[i][j];
  16.   return total ;
  17. }
  18.  
  19. int main() {
  20.   int i, j ;
  21.   //int A[ROWS][COLS] ;
  22.   ARRAYSTRUCT mystruct;
  23.  
  24.   for ( i = 0; i < ROWS; i++ ) { for ( j = 0; j < COLS; j++ ) mystruct.A[i][j] = rand() ; }
  25.   for ( i = 0; i < ROWS; i++ ) { for ( j = 0; j < COLS; j++ ) printf( "A[%d][%d] == %d\n", i, j, mystruct.A[i][j] ) ; }
  26.   int total = sum( &mystruct ) ;
  27.   printf("\nTotal: %d\n\n", total);
  28.   return 0 ;
  29. }
RAW Paste Data
Top