#include <stdio.h>
#include <conio.h>
#include <math.h>
int A[20][20];
int n, m;
int NgTo(int);
int HH(int);
int CP(int);
void NGUYENTO();
void HOANHAO();
void CHINHPHUONG();
void NHAP();
void main()
{
NHAP();
printf("\n\n Nhan phim bat ki de tim cac so nguyen to trong mang tren");getch
(); NGUYENTO();
printf("\n\n Nhan phim bat ki de tim cac so hoan hao trong mang tren");getch
(); HOANHAO();
printf("\n\n Nhan phim bat ki de tim cac so chinh phuong trong mang tren");getch
(); CHINHPHUONG();
getch();
clrscr();gotoxy(28, 20);textcolor(14);
cprintf("Le Manh Linh - CNTT DHTN\n");
getch();
}
void NHAP()
{
int i, j;
clrscr();
do
{
clrscr();
printf("\n Nhap so hang cua ma tran (nho hon 20): ");scanf("%d",&m
); }
while ((m <= 0)||(m > 20));
do
{
clrscr();
printf("\n Nhap so hang cua ma tran (nho hon 20): %d\n",m
); printf(" Nhap so cot cua ma tran (nho hon 20): ");scanf("%d",&n
); }
while ((n <= 0)||(n > 20));
printf("\n Nhap gia tri cac phan tu cua ma tran:\n"); for (i = 0; i < m; ++i)
for (j = 0; j < n; ++j)
{
clreol();
}
clrscr();
printf(" Ma tran vua nhap la:\n\n "); textcolor(YELLOW);
for (i = 0; i < m; ++i)
{
for (j = 0; j < n; ++j)
{
gotoxy(wherex() + j, wherey());
cprintf("%6d",A[i][j]);
}
}
}
int NgTo(int x)
{
int i, ngto;
ngto = 1;
if (x <= 2)
{
if (x < 2) ngto = 0;
}
else
for (i
= 2; i
<= sqrt(x
); i
++) {
if (x % i == 0)
{
ngto = 0;break;
}
}
return ngto;
}
void NGUYENTO()
{
int i, j;
clrscr();
printf(" Ma tran vua nhap la:\n\n "); for (i = 0; i < m; ++i)
{
for (j = 0; j < n; ++j)
{
gotoxy(wherex() + j, wherey());
if (NgTo(A[i][j]) == 1) textcolor(RED);
else textcolor(YELLOW);
cprintf("%6d",A[i][j]);
}
}
textcolor(WHITE);
cprintf("\n\n Nhung so nguyen to trong mang duoc in");
textcolor(RED);cprintf(" mau do !");
}
int HH(int x)
{
int i, hh = 0,s = 0;
for (i = 1; i <= (x / 2); ++i)
{
if (x % i == 0) s = s + i;
}
if (s == x) hh = 1;
return(hh);
}
void HOANHAO()
{
int i, j;
clrscr();
printf(" Ma tran vua nhap la:\n\n "); for (i = 0; i < m; ++i)
{
for (j = 0; j < n; ++j)
{
gotoxy(wherex() + j, wherey());
if (HH(A[i][j]) == 1) textcolor(GREEN);
else textcolor(YELLOW);
cprintf("%6d",A[i][j]);
}
}
textcolor(WHITE);
cprintf("\n Nhung so hoan hao trong mang duoc in");
textcolor(GREEN);cprintf(" mau xanh !");
}
int CP(int x)
{
int cp = 0;
return(cp);
}
void CHINHPHUONG()
{
int i, j;
clrscr();
printf(" Ma tran vua nhap la:\n\n "); for (i = 0; i < m; ++i)
{
for (j = 0; j < n; ++j)
{
gotoxy(wherex() + j, wherey());
if (CP(A[i][j]) == 1) textcolor(BLUE);
else textcolor(YELLOW);
cprintf("%6d",A[i][j]);
}
}
textcolor(WHITE);
cprintf("\n Nhung so chinh phuong trong mang duoc in");
textcolor(BLUE);cprintf(" mau xanh !");
textcolor(WHITE);cprintf("");
}