Tổng dòng/cột max, dòng có nhiều số nguyên tố trong mảng 2 chiều
#include "stdio.h"
#include "conio.h"
#include "math.h"
#define row 100
#define col 100
void nhapmang(int a[][col],int dong, int cot)
{
for(int i=0; i<dong;i++)
for(int j=0; j<cot; j++)
{
printf(“NHap phan tu cua mang: a[%d][%d]”,i, j);
scanf(“%d”,&a[i][j]);
}
}
void xuatmang(int a[][col],int dong, int cot)
{
for(int i=0; i<dong;i++)
{
for(int j=0; j<cot; j++)
printf(“%4d”, a[i][j]);
printf(“\n”);
}
}
long tongdong(int a[][col],int cot,int i)
{
long s=0;
for(int j=0; j<cot; j++)
{
s+=a[i][j];
}
return s;
}
int timdongmax(int a[][col], int dong, int cot)
{
int vt=0;
for( int i=0;i<dong; i++)
for( int j=0; j<cot; j++)
{
if(tongdong(a,cot,i)>tongdong(a,cot,vt))
vt=i;
}
return vt;
}
long cotmax(int a[][col], int dong,int j)
{
long scot=0;
for(int i=0; i<dong; i++)
scot+=a[i][j];
return scot;
}
int timcotmax(int a[][col],int dong, int cot)
{
int vtcot=0;
for(int i=0; i<dong; i++)
for(int j=0; j<cot;j++)
{
if(cotmax(a, dong, j)>cotmax(a, dong, vtcot))
vtcot=j;
}
return vtcot;
}
int ktnt(int p)
{
if(p<2) return 0;
for(int u=2; u<=sqrt(p); u++)
if(p%u==0)
return 0;
return 1;
}
int demdongngto(int a[][col], int cot, int i)
{
int demdong=0;
for(int j=0; j<cot; j++)
{
if(ktnt(a[i][j]))
demdong++;
}
return demdong;
}
int tim_dong_nh_nt(int a[][col], int dong, int cot)
{
int vtdong=0;
for(int i=0; i<dong; i++)
for(int j=0;j<cot;j++)
{
if(demdongngto(a, cot, i)>demdongngto(a, cot, vtdong))
vtdong=i;
}
return vtdong;
}
void main()
{
clrscr();
int a[row][col],dong,cot;
printf(“Nhap vao so dong”); scanf(“%d”,&dong);
printf(“Nhap vao so cot”); scanf(“%d”,&cot);
nhapmang(a, dong, cot);
printf(“Mang vua nhap la \n”);
xuatmang(a, dong, cot);
int kq1= timdongmax(a, dong, cot);
printf(“Dong co tong lon nhat la %d \n”,kq1);
int kq2= timcotmax(a, dong, cot);
printf(“Cot co tong lon nhat la %d \n”,kq2);
int kq3= tim_dong_nh_nt(a, dong,cot);
printf(“Dong co nhieu co nguyen to la %d \n”, kq3);
getch();
}
Last modified on December 30th, 2021 at 9:06 pm
Nam Le
lequocnam
0 responds