using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace bai_1_sgkt35
{
class Program
{
static int n;
static int []a;
static void Nhap()
{
Console.Write("nhap so luong phan tu cua mang n="); n = int.Parse(Console.ReadLine());
a = new int[n];
Console.WriteLine("nhap cac phan tu cua mang");
for (int i = 0; i < n; i++)
{
Console.Write("a[{0}]=",i);
a[i] = int.Parse(Console.ReadLine());
}
}
static void Hien()
{
Console.WriteLine("mang vua nhap la:");
for (int i = 0; i < n; i++)
{
Console.Write(a[i] + "\t");
Console.WriteLine();
}
}
static float TinhTong()
{
float s = 0;
for (int i = 0; i < n; i++)
{
s = s + a[i];
}
return s;
}
static void Main(string[] args)
{
float s = 0;
Nhap();
Hien();
s = TinhTong();
Console.WriteLine("tong cac phan tu trong mang la:"+s);
Console.ReadKey();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace bai_1_sgkt35
{
class Program
{
static int n;
static int []a;
static void Nhap()
{
Console.Write("nhap so luong phan tu cua mang n="); n = int.Parse(Console.ReadLine());
a = new int[n];
Console.WriteLine("nhap cac phan tu cua mang");
for (int i = 0; i < n; i++)
{
Console.Write("a[{0}]=",i);
a[i] = int.Parse(Console.ReadLine());
}
}
static void Hien()
{
Console.WriteLine("mang vua nhap la:");
for (int i = 0; i < n; i++)
{
Console.Write(a[i] + "\t");
Console.WriteLine();
}
}
static float TinhTong()
{
float s = 0;
for (int i = 0; i < n; i++)
{
s = s + a[i];
}
return s;
}
static void Main(string[] args)
{
float s = 0;
Nhap();
Hien();
s = TinhTong();
Console.WriteLine("tong cac phan tu trong mang la:"+s);
Console.ReadKey();
}
}
}