[codes=c#]using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace th1
{
class Program
{
static void c1()
{
Console.Write(“Nhap vao ho va ten: “);
string hoten = Console.ReadLine();
Console.Write(“Nhap vao tuoi: “);
int tuoi = Convert.ToInt32(Console.ReadLine());
Console.Write(“Nhap vao gioi tinh: “);
string gioitinh = Console.ReadLine();
Console.Write(“Nhap vao so thik: “);
string sothik = Console.ReadLine();
Console.WriteLine(“Ten la: ” + hoten + “\tTuoi la ” + tuoi + “\tGioi tinh la ” + gioitinh + “\tSo thik la ” + sothik);
Console.ReadLine();
}
static void c2()
{
int ttc2 = 0;
do
{
Console.WriteLine(“Nhap vao gia tri 1->7. 0 de thoat. (Mac dinh Chu nhat co gia tri 1) >”);
int thu = Convert.ToInt32(Console.ReadLine());
switch (thu)
{
case 1: Console.WriteLine(“Chu nhat”); ttc2 = 1; break;
case 2: Console.WriteLine(“Thu 2”); ttc2 = 1; break;
case 3: Console.WriteLine(“Thu 3”); ttc2 = 1; break;
case 4: Console.WriteLine(“Thu 4”); ttc2 = 1; break;
case 5: Console.WriteLine(“Thu 5”); ttc2 = 1; break;
case 6: Console.WriteLine(“Thu 6”); ttc2 = 1; break;
case 7: Console.WriteLine(“Thu 7”); ttc2 = 1; break;
case 0: ttc2 = 0; break;
default: Console.WriteLine(“Ko tim thay”); ttc2 = 1; break;
}
} while (ttc2 == 1);
}
static int nt(int b)
{
if (b <= 2) return 0;
for (int i = 2; i < b; i++)
if (b % i == 0) return 0;
return 1;
}
static void c3()
{
Console.WriteLine(“Nhap so phan tu”);
int n=Convert.ToInt32(Console.ReadLine());
int[]a=new int[n];
for (int i = 0; i < n; i++)
{
Console.Write(” a[{0}]= “, i);
a[i] = Convert.ToInt32(Console.ReadLine());
}
Console.WriteLine(“Mang vua nhap la:”);
foreach(int i in a)
Console.Write(” {0} “,i);
Console.WriteLine(“\n”);
int ck = 0;
foreach (int i in a)
if (nt(i) == 1)
{
ck = 1;
Console.Write(“So nguyen to co trong mang la: “);
Console.Write(“{0} “, i);
}
if (ck == 0)
Console.Write(“KO coa snt nao”);
}
static void Main(string[] args)
{
int t = 0;
do
{
Console.WriteLine(“Chon 1 2 or 3, 0 de thoat:> “);
int c = Convert.ToInt32(Console.ReadLine());
switch (c)
{
case 0: t = 0; break;
case 1: c1(); t = 1; break;
case 2: c2(); t = 1; break;
case 3: c3(); t = 1; break;
default: Console.WriteLine(“Chon lai: >”); t = 1; break;
}
} while (t == 1);
}
}
}
[/codes]
Last modified on December 4th, 2020 at 3:16 am
Nam Le
lequocnam
chỉ mang tính tham khảo, sai chỗ nào anh em bình loạn he