Не выводит решение в консоли - C#
Формулировка задачи:
вот задание
Постройте таблицу значений функции y=f(x) для х[a, b] с шагом h.
Замечание
При решении задачи разработайте две версии метода f так, чтобы их сигнатуры соответствовали следующим описаниям:
static double f (double x) ,static void f (double x, out double y) как вызвать именно вызвать в static void main или что другое допишите код пожалуйста, помогите плз завтра сдаю лабу
вводить значения, например, 3.4.5
Листинг программы
- class Program
- {
- static void Main(string[] args)
- {
- static double f(double x)
- {
- if (x < 1)
- return Math.Pow(x * x - 1, 2);
- else if (x > 1)
- return 1 / Math.Pow(1 + x, 2);
- else
- return 0;
- }
- static void f(double x, out double y)
- {
- y = 0;
- if (x < 1)
- {
- y = Math.Pow(x * x - 1, 2);
- }
- else
- if ( x > 1)
- {
- y = Math.Pow(1 / 1 + x, 2);
- }
- else
- if (x==1)
- {
- y=0;
- Console.ReadKey();
- }
- }
- }
- }
все решилось
Листинг программы
- class Program
- {
- static void Main(string[] args)
- {
- int a = 0;
- int b = 0;
- int h = 0;
- double y = 0;
- Console.WriteLine("Введите нижний диапазон: ");
- Read(ref a);
- Console.WriteLine("Введите верхний диапазон: ");
- Read(ref b);
- Console.WriteLine("Введите шаг: ");
- Read(ref h);
- Console.WriteLine();
- if ((b > a) && (h > 0))
- {
- Console.WriteLine(" 1 способ | 2 способ\n{0,11}", "|");
- for (double x = a; x <= b; x += h)
- {
- f(x);
- Console.Write("{0,9} |", f(x));
- f(x, out y);
- Console.WriteLine(" {0}", y);
- }
- }
- else
- {
- Console.WriteLine("Проверьте значения");
- }
- Console.ReadKey();
- }
- static void Read(ref int n)
- {
- bool f = false;
- while (!f)
- {
- f = int.TryParse(Console.ReadLine(), out n);
- if (f == false)
- {
- Console.WriteLine("Неверные данные. Попробуйте снова!");
- }
- }
- }
- static double f(double x)
- {
- if (x < 1)
- return Math.Pow(x * x - 1, 2);
- else if (x > 1)
- return 1 / Math.Pow(1 + x, 2);
- else
- return 0;
- }
- static void f(double x, out double y)
- {
- y = 0;
- if (x < 1)
- {
- y = Math.Pow(x * x - 1, 2);
- }
- else
- if ( x > 1)
- {
- y = Math.Pow(1 / 1 + x, 2);
- }
- else
- if (x==1)
- {
- y=0;
- Console.ReadKey();
- }
- }
- }
- }
Решение задачи: «Не выводит решение в консоли»
textual
Листинг программы
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApplication11
- {
- class Program
- {
- static double f(double x)
- {
- if (x < 1)
- return Math.Pow(x * x - 1, 2);
- else if (x > 1)
- return 1 / Math.Pow(1 + x, 2);
- else
- return 0;
- }
- static void f(double x, out double y)
- {
- y = 0;
- if (x < 1)
- {
- y = Math.Pow(x * x - 1, 2);
- }
- else
- if (x > 1)
- {
- y = Math.Pow(1 / 1 + x, 2);
- }
- else
- if (x == 1)
- {
- y = 0;
- Console.ReadKey();
- }
- }
- static void Main(string[] args)
- {
- for(int counter = 0; counter < 10; counter += 2) // [0, 9] с шагом 2
- {
- Console.Write("{0:F2} ", f(counter));
- }
- Console.ReadKey();
- }
- }
- }
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д