FOR - C# (Continue)
CODE
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace For_continue
{
class Program
{
static void Main(string[] args)
{
#region Tinh S=1+1/2!+1/3!+...+1/n!
//Console.WriteLine("Tinh S=1+1/2!+1/3!+...+1/n!");
//Console.Write("Moi ban nhap n = ");
//int n = int.Parse(Console.ReadLine());
//int gt = 1;
//double sum = 0;
//for (int i = 1; i <= n; i++)
//{
// gt *= i;
// sum += 1 / Convert.ToDouble(gt);
//}
//Console.WriteLine("Ket qua la {0}", sum);
//Console.ReadLine();
#endregion
#region Tinh S=1+2*2!+3*3!+...+n*n
//Console.WriteLine("Tinh S=Tinh S=1+2*2!+3*3!+...+n*n");
//Console.Write("Moi ban nhap n = ");
//int n = int.Parse(Console.ReadLine());
//double sum = 0;
//for (int i = 1; i <= n; i++)
//{
// sum += i * i;
//}
//Console.WriteLine("Ket qua la {0}", sum);
//Console.ReadLine();
#endregion
#region Tinh S=1-1/2+1/3-1/4+1/5-.....1/n
Console.WriteLine("Tinh S=1-1/2+1/3-1/4+1/5-.....1/n");
Console.Write("Moi ban nhap n = ");
int n = int.Parse(Console.ReadLine());
double sum = 0;
for (int i = 1; i <= n; i++)
{
if(i%2!=0)
{
sum += 1 / Convert.ToDouble(i);
}
else
{
sum -= 1 / Convert.ToDouble(i);
}
}
Console.WriteLine("Ket qua la {0}", sum);
Console.ReadLine();
#endregion
}
}
}
lúc 03:33 2 tháng 2, 2022
Lucky Club Casino site - Lucky Club
Lucky Club Casino is an online gambling platform with luckyclub.live many different casino games, promotions and so much more. We offer a whole range of games with a high Rating: 4.8 · Review by Lucky Club Casino