C Program to Find Duplicate Numbers From The 3 by 3 Matrix


In this post, I am going to write a c program to find duplicate numbers from the 3 by 3 matrix. I have easily written this program.

Also Read: Switch Case in C Program to Calculate Area of Circle and Triangle

The logic of this program is so simple. Here, I am converting this multi-dimensional array into a single-dimensional array. Then it has become very easy to find out duplicate numbers.

Before going further, let us see the expected output first.

Expected Output

c program to find duplicate numbers from the 3*3 matrix
Fig. c program to find duplicate numbers from the 3 by 3 matrix

As you can see in the above figure, we are reading the elements for the 3 by 3 matrix. After that, we are displaying the same matrix. After displaying the matrix, we will display the duplicate numbers.

Also Read: C Program to Print Multiples of 5 using do-while loop

Now see the actual c program.

C Program to Find Duplicate Numbers From the 3 by 3 Matrix

#include <stdio.h>
#include <stdlib.h>
int main()
    int a[3][3],i,j;
    int sa[10],k=0;
    printf("Enter elements for 3 * 3 matrix\n");

    printf("Matrix Elements are\n");
            printf("%d ",a[i][j]);
    printf("Duplicate Array Elements are\n");
    for(int i=0;i<9; i++)
        for(int j=i+1;j<9;j++)
            if(sa[i] == sa[j])
                printf("%d ", sa[j]);
    return 0;


Now, I am going to explain this program.

Variable Declaration

In this program, I have declared five variables of type int. Out of which, one is a two-dimensional array, one single dimensional array, two-loop variables, and one counter variable.

Input Part

Here, we are asking the user to enter elements for the 3 * 3 matrix. We are storing these elements in the array a[][].

At the same time, I am also storing these array elements from a two-dimensional array to a one-dimensional array.

Processing Part and Output

Using two loops, we are finding the duplicate numbers in the given array. The first element of the array is compared with all the elements until we get our duplicate number. If we get the duplicate number, we will print that number and then move to the next duplicate number.

I hope, this program will help you. Thanks for reading.

Important C Programs

  1. Program in C to Find Longest Line in a File
  2. Palindrome in C using Pointers
  3. Insert and Delete element in Array in C using switch case
  4. C Program to Add Alternate Elements of a 2D Array
  5. Arrays in C for Complete Beginners
  6. C Program to Find Area of a Circle using Preprocessor
  7. Program in C to Remove White Spaces and Comments from a File
  8. C Program to Print Numbers Except Multiples of n
  9. Reverse a Number using getchar and putchar function in c
  10. The while loop in C Programming

Leave a Comment