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

## Introduction

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.

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

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.

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,i,j;
int sa,k=0;
printf("Enter elements for 3 * 3 matrix\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf("%d",&a[i][j]);
sa[k]=a[i][j];
k++;

}
}
printf("Matrix Elements are\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%d ",a[i][j]);
}
printf("\n");
}
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;
}
``````

## Explanation

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.