Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.4 kB
4
Indexable
Never
using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Nhap N so nguyen: ");
            int n = int.Parse(Console.ReadLine());
            int[] a = new int[n];
            for(int i = 0; i < n; i++)
            {
                Console.Write("Nhap so thu {0}: ", i+1);
                a[i] = int.Parse(Console.ReadLine());
            }
            for(int i = 0; i < n; i++)
            {
                Console.Write(a[i] + " ");
            }
            Console.WriteLine();
            int[] temp = new int[n];
            int index = 0;
            for (int i = 0; i < n; i++)
            {
                if(a[i] != 0)
                {
                    temp[index] = a[i];
                    index++;
                }
            }
            Console.WriteLine("Mang sau khi xoa het so 0");
            for (int i = 0; i < index; i++)
            {
                Console.Write(temp[i] + " ");
            }
            int Tong = 0;
            int dem = 0;
            for(int i = 0; i < index; i++)
            {
                if(temp[i] % 3 == 0)
                {
                    Tong += temp[i];
                    dem++;
                }
            }
            Console.WriteLine();
            Console.WriteLine("TBC cac so chia het cho 3: {0}", Tong/dem);
        }
    }
}