Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Diagnostics;
- namespace ForDZ
- {
- class Program
- {
- static double circle(int r, double x)
- {
- if (x > r) throw new ApplicationException("nan");
- return 2 * Math.Sqrt(r * r - x * x);
- }
- delegate double function(int r, double x);
- static double integral(function f, int r, double accuracy)
- {
- Console.WriteLine("Processing: 0%");
- double res = 0;
- double startX = -r + accuracy;
- double endX = r - accuracy;
- long time = (long)((endX - startX) / accuracy);
- long oneprocent = time / 100;
- long counter = 0;
- for (double i = startX; i < endX; i += accuracy)
- {
- res += ((f(r, i) + f(r, i + accuracy)) / 2) * accuracy;
- counter++;
- if (counter % oneprocent == 0)
- {
- Console.Clear();
- Console.WriteLine("Processing: {0}%", counter / oneprocent);
- }
- }
- Console.Clear();
- return res;
- }
- static void Main(string[] args)
- {
- int radius = 1;
- double accuracy = 1E-10;
- double areaPI = Math.PI * radius * radius;
- double areaINT = integral(new function(circle), radius, accuracy);
- Console.WriteLine("Интегральная площадь: {0} \nПлощадь через пи: {1} \nРазница: {2}", areaINT, areaPI, Math.Abs(areaINT - areaPI));
- //Console.WriteLine("end");
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement