recent

C Program To Print Square Of Each Element Of 2D Array Matrix

C Program To Print Square Of Each Element Of 2D Array Matrix

#include<stdio.h>
#define MAX_ROWS 3
#define MAX_COLS 4

void print_square(int[]);    //function declaration

void main(void)   // No return type and no argument passed
{

   int row;
   int num[MAX_ROWS][MAX_COLS] = { { 0, 1, 2, 3 },
                            { 4, 5, 6, 7 },
                            { 8, 9, 10, 11 } };

   for (row = 0; row < MAX_ROWS; row++)
      print_square(num[row]);  //function call
}

void print_square(int x[])    //function definition
{
   int col;
   for (col = 0; col < MAX_COLS; col++)
      printf("%d\t", x[col] * x[col]);
   printf("\n");
}
Powered by Blogger.