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 Lab3
- {
- class Program
- {
- static void Main(string[] args)
- {
- //объявляем массив
- String[,] graph = new String[60, 60];
- int a, b, c;
- //заполняем массив пробелами
- for (int i = 0; i < 60; i++)
- {
- for (int g = 0; g < 60; g++)
- {
- graph[i, g] = " ";
- }
- }
- //в массиве строим координатные оси
- for (int i = 0; i < 60; i++)
- {
- graph[30, i] = "-";
- graph[i, 30] = "|";
- }
- //строим график на выбор в массиве
- Console.WriteLine("Выберите график функции из предложенных:\n1. a*x^2 + b*x + c \n2. a*sin(b*x)");
- int choice = int.Parse(Console.ReadLine());
- if (choice == 1)
- {
- Console.WriteLine("Вы выбрали график функции a*x^2 + b*x + c");
- Console.WriteLine("Введите значение переменной a");
- a = int.Parse(Console.ReadLine());
- Console.WriteLine("Введите значение переменной b");
- b = int.Parse(Console.ReadLine());
- Console.WriteLine("Введите значение переменной c");
- c = int.Parse(Console.ReadLine());
- for (int x = -30; x < 30; x++)
- {
- int y = a * x * x + b * x + c;
- if ((y > 30) || (y <= -30)) { continue; };
- graph[30 - y, 30 + x] = "1";
- }
- }
- if (choice == 2)
- {
- Console.WriteLine("Вы выбрали график функции a*sin(b*x)");
- Console.WriteLine("Введите значение переменной a");
- a = int.Parse(Console.ReadLine());
- Console.WriteLine("Введите значение переменной b");
- b = int.Parse(Console.ReadLine());
- for (int x = -30; x < 30; x++)
- {
- double y = a * Math.Sin(b * x);
- Math.Round(y);
- int f = Convert.ToInt32(y);
- if ((f > 1) || (f < -1)) { continue; };
- graph[30 - f, 30 + x] = "1";
- }
- }
- //вывод графика
- Console.WriteLine("График выбранной вами функции:");
- for (int i = 0; i < 60; i++)
- {
- for (int g = 0; g < 60; g++)
- {
- Console.Write(graph[i, g]);
- if (g == 59)
- {
- Console.WriteLine(graph[i, g]);
- }
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment