SO i was solving this problem and i get this output
**But i am expecting output like this **
what is my mistake here?
I know i don't code efficiently and i want to know how can i make this code more compact any suggestions will be helpful as i am still learning these things.
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
int main()
{
int i,j,k,l,f=0,x=0,q=0,row,column,size;
int res[100];
printf("Enter the row: ");
scanf("%d",&row);
printf("Enter the column: ");
scanf("%d",&column);
size= row*column;
int **arr;
arr=(int**)malloc(row * sizeof(int));
for(i=0;i<row;i++)
{
arr[i] = (int*)malloc(column*sizeof(int));
}
for(i=0;i<row;i++)
{
for (j=0;j<column;j++)
{
printf("Enter the value at row %d and column %d : ",i,j);
scanf("%d",(*(arr+i)+j));
}
}
for(i=0;i<row;i++)
{
for (j=0;j<column;j++)
{
printf("
The value at row %d and column %d : %d",i,j,*(*(arr+i)+j));
}
}
printf("
The duplicate value(s) are:
");
for(i=0; i<row; i++)
{
for(j=0; j<column; j++)
{
for(k=0; k<row; k++)
{
for(l=0; l<column; l++)
{
if(*(*(arr+i)+j)== *(*(arr+k)+l))
{
f=f+1;
}
if(f>1)
{
printf("%d in positions (%d,%d)",*(*(arr+i)+j),k,l);
}
}
}f=0;
}
}
free(arr);
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…