#include<stdio.h>
#include<stdlib.h>
void xuat(int **a,int h,int c)
{
for(int i=0;i<h;i++)
{
printf("\n\n");
for(int j=0;j<c;j++) printf("%-4d",a[i][j]);
}
printf("\n");
}
int min(int **a,int h,int c)
{
int i,j,b[10]={0,0,0,0,0,0,0,0,0,0};
for(i=0;i<h;i++)
for(j=0;j<c;j++)
do{
b[a[i][j]%10]++;
a[i][j]/=10;
}while(a[i][j]!=0);
int min,vt;
for(i=0;i<10;i++)if(b[i]!=0){min=b[i];vt=i;break;}
for(i=0;i<10;i++) if(min>b[i] && b[i]!=0){min=b[i];vt=i;}
return vt;
}
void main()
{
printf("nhap so hang, so cot:\n");
int h,c;scanf("%d%d",&h,&c);
int **a=(int**)malloc(h*sizeof(int*));
for(int i=0;i<h;i++) a[i]=(int*)malloc(c*sizeof(int));
for(int i=0;i<h;i++)
for(int j=0;j<c;j++)
a[i][j]=rand()%51;
xuat(a,h,c);
printf("\n\nchu so xuat hien it nhat: %d\n",min(a,h,c));
}
0 comments:
Post a Comment