[codes=c]#include "conio.h"
#include "stdio.h"
#include "math.h"
#define ROW 100
#define COL 100
void nhapmang(int a[][COL], int sodong, int socot)
{
for(int i = 0; i<sodong; i++)
for(int j = 0; j<socot; j++)
{
printf("a[%d][%d]=", i, j);
scanf("%d", &a[i][j]);
}
}
void xuatmang( int a[][COL], int sodong, int socot)
{
for(int i = 0; i<sodong; i++)
{
for(int j = 0; j<socot; j++)
printf("%4d",a[i][j]);
}
printf("\n");
}
int demptux(int a[][COL], int sodong, int socot, int x)
{
int dem = 0;
for(int i = 0; i<sodong; i++)
for(int j = 0; j<socot; j++)
{
if(a[i][j]==x)
dem++;
}
return dem;
}
int songuyento(int n)
{
if(n<2) return 0;
if (n==2) return 1;
for(int i=2;i<=sqrt(n);i++)
if(n%i==0)
return 0;
return 1;
}
int tontaidongtoanngto(int a[][COL], int sodong, int socot)
{
int j;
for(int i = 0; i< sodong; i++)
{
for(j = 0; j< socot; j++)
{
if(songuyento(a[i][j])==0)
break;
}
if(j==socot)
return 1;
}
return 0;
}
int dongktoanngto(int a[][COL], int sodong, int socot, int k)
{
int j;
for(int i = 0; i< sodong; i++)
{
for( j = 0; j< socot; j++)
{
if(songuyento(a[k][j])!=1)
break;
}
if(j==socot)
return 1;
}
return 0;
}
void main()
{
//clrscr();
int a[ROW][COL],sodong, socot,x,k;
printf("NHap vao so dong: ");
scanf("%d",&sodong);
printf("Nhap vao so cot: ");
scanf("%d",&socot);
nhapmang(a, sodong, socot);
printf("Mang vua nhap la: \n");
xuatmang(a, sodong, socot);
printf("NHap vao phan tu x cam dem: ");
scanf("%d",&x);
int kq = demptux(a, sodong, socot,x) ;
printf("Phan tu %d co %d phan tu.",x,kq);
int ktr = tontaidongtoanngto(a, sodong, socot);
if(ktr==1) printf("Co ton tai dong chua toan nguyen to");
else printf("KHong co dong nao chua ca");
printf("Nhap vao dong thu k ban can kiem tra: ");
scanf("%d",&k);
int kq2 = dongktoanngto( a, sodong, socot, k);
if(kq2==1) printf("Co ton tai dong chua toan nguyen to");
else printf("KHong co dong nao chua ca");
getch();
}[/codes]
Last modified on March 31st, 2021 at 1:22 am
Nam Le
lequocnam
0 responds