Skip to content

Instantly share code, notes, and snippets.

@hongphuc5497
Last active May 16, 2026 07:56
Show Gist options
  • Select an option

  • Save hongphuc5497/78780210f73764835a608b3df9ddf01f to your computer and use it in GitHub Desktop.

Select an option

Save hongphuc5497/78780210f73764835a608b3df9ddf01f to your computer and use it in GitHub Desktop.
C1-C2-C3

a)

Dòng 5: Khai báo trùng biến i

Dòng 6: Thiếu dấu ; sau while (i <= n)

Dòng 16: Thiếu dấu ; sau i++

Dòng 18: Sai index {1}, {2} => {0}, {1}

Đoạn code sửa lỗi:

static void Main(string[] args)

{
    int n;
    n = int.Parse(Console.ReadLine()); 
    int i = 1, demDuong = 0, demAm = 0;

    while (i <= n)
    {
        Console.Write("Nhap so thu {0}: ", i);
        int x = int.Parse(Console.ReadLine());

        if (x > 0)
            demDuong++;
        else if (x < 0)
            demAm++;
        else
            Console.WriteLine("So 0 khong tinh vao dem!");

        i++;
    }
     Console.WriteLine("Co {0} so duong va {1} so am.", demDuong, demAm); 
}

b)

Kết quả khi chạy chương trình:

Nhap so thu 1: 3
Nhap so thu 2: 0
So 0 khong tinh vao dem!
Nhap so thu 3: 7 
Nhap so thu 4: -2
Nhap so thu 5: 5
Co 3 so duong va 1 so am.

c)

Khi kết thúc vòng lặp, giá trị của i là 6

using System;
class Program
{
static void Main(string[] args)
{
double nhietDo;
Console.Write("Nhap nhiet do (°C): ");
nhietDo = double.Parse(Console.ReadLine());
while (nhietDo < 0 || nhietDo > 45)
{
Console.WriteLine("Nhiet do khong hop le! Nhap lai.");
Console.Write("Nhap nhiet do (°C): ");
nhietDo = double.Parse(Console.ReadLine());
}
if (nhietDo < 35)
{
Console.WriteLine("Than nhiet thap! Can suoi am!");
}
else if (nhietDo <= 37.5)
{
Console.WriteLine("Than nhiet binh thuong.");
}
else if (nhietDo <= 39)
{
Console.WriteLine("Dang sot nhe.");
}
else
{
Console.WriteLine("Sot cao! Can gap bac si!");
}
}
}
using System;
class Program
{
static void Main(string[] args)
{
double[] P = new double[7];
Nhap(P);
double max, min;
TimMaxMin(P, out max, out min);
int dem = DemNgayNong(P);
double tb = TinhTrungBinh(P);
Console.WriteLine("Nhiet do cao nhat: " + max);
Console.WriteLine("Nhiet do thap nhat: " + min);
Console.WriteLine("So ngay tren 35°C: " + dem);
Console.WriteLine("Nhiet do trung binh: " + tb);
}
static void Nhap(double[] P)
{
for (int i = 0; i < 7; i++)
{
double t;
Console.Write("Nhap nhiet do ngay {0}: ", i + 1);
t = double.Parse(Console.ReadLine());
while (t < 0 || t > 60)
{
Console.WriteLine("Nhap sai! Nhap lai.");
Console.Write("Nhap nhiet do ngay {0}: ", i + 1);
t = double.Parse(Console.ReadLine());
}
P[i] = t;
}
}
static void TimMaxMin(double[] P, out double max, out double min)
{
max = P[0];
min = P[0];
for (int i = 1; i < 7; i++)
{
if (P[i] > max)
max = P[i];
if (P[i] < min)
min = P[i];
}
}
static int DemNgayNong(double[] P)
{
int dem = 0;
for (int i = 0; i < 7; i++)
{
if (P[i] > 35)
dem++;
}
return dem;
}
static double TinhTrungBinh(double[] P)
{
double tong = 0;
for (int i = 0; i < 7; i++)
{
tong += P[i];
}
return tong / 7;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment