Square of array elements in C || Arrays || C Programming
In this, we are going to see a program in which we will find the square of all array elements in C programming language.

//Finds the square of array elements

#include <stdio.h>

// Defining the rows and columns of matrix using inbuilt function in C
#define MAX_ROWS 3
#define MAX_COLS 4

void print_square(int []);

void main(void)
{
    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]);
    }
}

void print_square(int x[])
{
    int col;
    for (col = 0;col<MAX_COLS;col++)
    {
        printf("%d\t",x[col]*x[col]);
        printf("\n");
    }
}


#ENJOY CODING


Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post