ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

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 »


ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.