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.Threading.Tasks;
- namespace lab5
- {
- abstract class Zalozenia
- {
- Zalozenia(double e){
- error = e;
- }
- ~Zalozenia() {
- }
- protected double error;
- virtual public double sqrtNumber(double num){
- double temp = 0, temp2 = 0;
- if (this.error == 0)
- {
- if (num >= 0)
- {
- temp = Math.Sqrt(num);
- }
- else
- {
- temp = Math.Sqrt(-(num));
- }
- }
- else if (this.error > 0 && this.error <= 0.1)
- {
- if (num >= 0)
- {
- temp = 1.0 * (num / 2);
- temp2 = 1.0 * (num / temp);
- }
- else
- {
- temp = 1.0 * (-(num) / 2);
- temp2 = 1.0 * (-(num) / temp);
- }
- for (; ; )
- {
- if (Math.Abs(temp - temp2) < this.error || Math.Pow(temp, 2) == num)
- {
- break;
- }
- else
- {
- temp = (1.0 * temp + temp2) / 2;
- temp2 = (1.0 * num) / (1.0 * temp);
- }
- }
- }
- else if (this.error > 0.1)
- {
- if (num >= 0)
- {
- temp = 1.0 * (num / 2);
- temp2 = 1.0 * (num / temp);
- }
- else
- {
- temp = 1.0 * (-(num) / 2);
- temp2 = 1.0 * (-(num) / temp);
- }
- for (; ; )
- {
- if (Math.Abs(temp - temp2) < this.error || Math.Pow(temp, 2) == num)
- {
- break;
- }
- else
- {
- temp2 = temp;
- temp = temp2 - ((Math.Pow(temp2, 2) - num) / (2 * temp2));
- }
- }
- }
- return temp;
- }
- virtual public void wyswietl()
- {
- }
- virtual public void rozwiazRownanie()
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement