Search item in Matrix by R4R Team

Matrix:
-Multidimensional Array
-Matrix consist of the rows and columns.

Syntax-
array[row][column]
//Martix with numbers of rows and columns

program-

#include< stdio.h>
int main()
{
int a[10][10],r,c,i,j,count=0,num;
printf("Enter rows and columns in matrix\n");
scanf("%d%d",&r,&c);
printf("Enter %d number in matrix\n",r*c);
//input in matrix
for(i=0;i< r;i++){
for(j=0;j< c;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("Matrix is\n");
for(i=0;i< r;i++){
for(j=0;j< c;j++)
{
printf("%d ",a[i][j]);
}
printf("n");
}
printf("Enter number to search\n");
scanf("%d",&num);
for(i=0;i< r;i++)
{
for(j=0;j< c;j++)
{
if(a[i][j]==num){
printf("Number is present at %d row and %d column",i+1,j+1);
break;
}
}
}
}


output-

Enter rows and columns in matrix
2 3
Enter 6 number in matrix
1 3 4 2 5 7
Matrix is
1 3 4
2 5 7
Enter number to search
3
Number is present at 1 row and 2 column

-In this program, firstly we Take a input in Matrix




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!