Guest User

Untitled

a guest
Oct 27th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.19 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Lab3
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. //объявляем массив
  14. String[,] graph = new String[60, 60];
  15. int a, b, c;
  16.  
  17. //заполняем массив пробелами
  18. for (int i = 0; i < 60; i++)
  19. {
  20. for (int g = 0; g < 60; g++)
  21. {
  22. graph[i, g] = " ";
  23. }
  24. }
  25.  
  26. //в массиве строим координатные оси
  27. for (int i = 0; i < 60; i++)
  28. {
  29. graph[30, i] = "-";
  30. graph[i, 30] = "|";
  31. }
  32.  
  33.  
  34. //строим график на выбор в массиве
  35.  
  36. Console.WriteLine("Выберите график функции из предложенных:\n1. a*x^2 + b*x + c \n2. a*sin(b*x)");
  37. int choice = int.Parse(Console.ReadLine());
  38. if (choice == 1)
  39. {
  40. Console.WriteLine("Вы выбрали график функции a*x^2 + b*x + c");
  41. Console.WriteLine("Введите значение переменной a");
  42. a = int.Parse(Console.ReadLine());
  43. Console.WriteLine("Введите значение переменной b");
  44. b = int.Parse(Console.ReadLine());
  45. Console.WriteLine("Введите значение переменной c");
  46. c = int.Parse(Console.ReadLine());
  47.  
  48. for (int x = -30; x < 30; x++)
  49. {
  50. int y = a * x * x + b * x + c;
  51. if ((y > 30) || (y <= -30)) { continue; };
  52. graph[30 - y, 30 + x] = "1";
  53. }
  54. }
  55.  
  56. if (choice == 2)
  57. {
  58. Console.WriteLine("Вы выбрали график функции a*sin(b*x)");
  59. Console.WriteLine("Введите значение переменной a");
  60. a = int.Parse(Console.ReadLine());
  61. Console.WriteLine("Введите значение переменной b");
  62. b = int.Parse(Console.ReadLine());
  63.  
  64. for (int x = -30; x < 30; x++)
  65. {
  66. double y = a * Math.Sin(b * x);
  67. Math.Round(y);
  68. int f = Convert.ToInt32(y);
  69. if ((f > 1) || (f < -1)) { continue; };
  70. graph[30 - f, 30 + x] = "1";
  71. }
  72. }
  73.  
  74. //вывод графика
  75. Console.WriteLine("График выбранной вами функции:");
  76. for (int i = 0; i < 60; i++)
  77. {
  78. for (int g = 0; g < 60; g++)
  79. {
  80. Console.Write(graph[i, g]);
  81. if (g == 59)
  82. {
  83. Console.WriteLine(graph[i, g]);
  84. }
  85. }
  86. }
  87. }
  88. }
  89. }
Add Comment
Please, Sign In to add comment