C program to find the frequency of even numbers in matrix

Here, we are going to learn how to find the frequency of even numbers in matrix in C programming language?
Submitted by Nidhi, on July 14, 2021

Problem Solution:

Given a matrix, we have to find the frequency of even numbers in matrix using C program.

Program:

The source code to find the frequency of EVEN numbers in MATRIX is given below. The given program is compiled and executed using GCC compile on UBUNTU 18.04 OS successfully.

// C program to find the frequency of EVEN numbers in MATRIX

#include <stdio.h>

#define ROW 3
#define COL 3

int main()
{
    int Matrix[ROW][COL] = {
        { 9, 8, 7 },
        { 5, 4, 6 },
        { 1, 2, 3 }
    };

    int i, j, EvenFrequency = 0;

    printf("Matrix:\n");
    for (i = 0; i < ROW; ++i) {
        for (j = 0; j < COL; ++j) {
            if (Matrix[i][j] % 2 == 0)
                EvenFrequency++;
            printf(" %d", Matrix[i][j]);
        }
        printf("\n");
    }

    printf("Frequency of EVEN numbers is: %d\n", EvenFrequency);

    return 0;
}

Output:

Matrix:
 9 8 7
 5 4 6
 1 2 3
Frequency of EVEN numbers is: 4

Explanation:

Here, we created a 3X3 matrix matrix using the 2D array. Then we find the frequency of EVEN numbers and print the result on the console screen.

C Two-dimensional Arrays Programs »





Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.