using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace bt_13
{
class Program
{
static int h, c, i, j;
static int[,] a;
static void nhap()
{
Console.Write("nhap so hang h="); h = int.Parse(Console.ReadLine());
Console.Write("nhap so cot c="); c = int.Parse(Console.ReadLine());
a = new int[h, c];
Console.WriteLine("nhap cac phan tu cua mang:");
for (i = 0; i < h; i++)
for (j = 0; j < c; j++)
{
Console.Write("a[{0},{1}]=",i,j);
a[i, j] = int.Parse(Console.ReadLine());
Console.WriteLine();
}
}
static void hien()
{
Console.WriteLine("mang vua nhap la:");
for (i = 0; i < h; i++)
{
for (j = 0; j < c; j++)
Console.Write(a[i, j] + "\t");
Console.WriteLine();
}
}
static bool nt(int x)
{
bool kt = true;
for (i = 2; i < x / 2; i++)
{
if (x % i == 0)
kt = false; break;
}
return kt;
}
static void tinhtong()
{
bool kt = nt(a[i, j]);
float s = 0;
int dem = 0;
for (i = 0; i < h; i++)
for (j = 0; j < c; j++)
if (kt && (a[i, j] > 1))
{
s = s + a[i, j];
dem = dem + 1;
}
if (dem == 0)
Console.WriteLine("khong co so nguyen to nao ca");
else
Console.Write("tong cac phan tu la so nguyen to la:" + s);
}
static void Main(string[] args)
{
nhap();
hien();
tinhtong();
Console.ReadKey();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace bt_13
{
class Program
{
static int h, c, i, j;
static int[,] a;
static void nhap()
{
Console.Write("nhap so hang h="); h = int.Parse(Console.ReadLine());
Console.Write("nhap so cot c="); c = int.Parse(Console.ReadLine());
a = new int[h, c];
Console.WriteLine("nhap cac phan tu cua mang:");
for (i = 0; i < h; i++)
for (j = 0; j < c; j++)
{
Console.Write("a[{0},{1}]=",i,j);
a[i, j] = int.Parse(Console.ReadLine());
Console.WriteLine();
}
}
static void hien()
{
Console.WriteLine("mang vua nhap la:");
for (i = 0; i < h; i++)
{
for (j = 0; j < c; j++)
Console.Write(a[i, j] + "\t");
Console.WriteLine();
}
}
static bool nt(int x)
{
bool kt = true;
for (i = 2; i < x / 2; i++)
{
if (x % i == 0)
kt = false; break;
}
return kt;
}
static void tinhtong()
{
bool kt = nt(a[i, j]);
float s = 0;
int dem = 0;
for (i = 0; i < h; i++)
for (j = 0; j < c; j++)
if (kt && (a[i, j] > 1))
{
s = s + a[i, j];
dem = dem + 1;
}
if (dem == 0)
Console.WriteLine("khong co so nguyen to nao ca");
else
Console.Write("tong cac phan tu la so nguyen to la:" + s);
}
static void Main(string[] args)
{
nhap();
hien();
tinhtong();
Console.ReadKey();
}
}
}