1-misol. Quyidagi ifodaning qiymatini hisoblovchi dastur tuzing.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace dotnetuz
{
class Program
{
static void Main(string[] args)
{
double s, a, x;
try
{
Console.Write("a=");
a = Double.Parse(Console.ReadLine()); Console.Write("x=");
x = Double.Parse(Console.ReadLine());
s = (a * a + Math.Exp(2 * a - 6)) / (x * (a + Math.Pow(2, x)));
Console.WriteLine("s=" + s);
}
catch (SystemException ex)
{
Console.WriteLine("Ifodaning qiymatini hisoblashda" + ex.Message + " xatolik yuz berdi");
}
finally
{
Console.WriteLine("Ifodaning qiymatini hisoblash tugadi");
}
Console.ReadLine();
}
}
}
2-Misol. sonlar va son berilgan bo’lsa, yig’indini hisoblovchi dastur tuzing.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace dotnetuz
{
class Program
{
static void Main(string[] args)
{
double[] a = new double[10];
double x, s = 0;
Console.Write("x=");
try
{
x = Double.Parse(Console.ReadLine());
for (int i = 0; i < 10; i++)
{
a[i] = Double.Parse(Console.ReadLine());
if (x + i != 0) { s += a[i] / (x + i); } else throw new DivideByZeroException();
}
Console.WriteLine("s=" + s);
}
catch (DivideByZeroException)
{
Console.WriteLine("Ifodani hisoblashda 0 ga bo'lish uchradi");
}
catch (IndexOutOfRangeException)
{
Console.WriteLine("Massivning indeksi chegaradan tashqariga chiqdi");
}
catch (SystemException ex)
{
Console.WriteLine("Xatolik:" + ex.Message +" yuz berdi");
}
finally
{
Console.WriteLine("Dastur tugadi");
}
Console.ReadLine();
}
}
}
Do'stlaringiz bilan baham: |