Advertisement
Guest User

Untitled

a guest
May 22nd, 2018
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 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 ConsoleApplication1
  8. {
  9. class Program
  10. {
  11. static int VratInt(ref int cislo)
  12. {
  13. do { Console.WriteLine("Zadejte cele cislo"); } while (!(int.TryParse(Console.ReadLine(), out cislo)));
  14. return cislo;
  15. }
  16. public static void ZadejKoeficienty(ref int a, ref int b, ref int c)
  17. {
  18. int cislo = 0;
  19. Console.WriteLine("Kvadraticka rovnice ve tvaru ax^2+bx+c=0\nZadejte koeficient a");
  20. do
  21. {
  22. a = VratInt(ref cislo);
  23. if (a == 0) Console.WriteLine("Nejedna se o kvadratickou rovnici, ale o linearni rovnici.\nZadejte koeficient a ruzny od nuly");
  24. }
  25. while (a == 0);
  26. Console.WriteLine("Zadejte koeficient b");
  27. b = VratInt(ref cislo);
  28. Console.WriteLine("Zadejte koeficient c");
  29. c = VratInt(ref cislo);
  30. double d = (Math.Pow(b, 2) - 4) * a * c;
  31. if (d == 0)
  32.  
  33. Console.WriteLine("Dvojnasobne reseni x={0}", -b / (2 * a));
  34.  
  35. else
  36. if (d < 0)
  37. Console.WriteLine("Rovnice nema reseni v oboru realnych cisel");
  38. else
  39. Console.WriteLine("x1={0}, x2={1}", (-b + Math.Sqrt(d)) / (2 * a), (-b - Math.Sqrt(d)) / (2 * a));
  40. }
  41.  
  42. static void Main(string[] args)
  43. {
  44. char volba = '9';
  45. int a = 0, b = 0, c = 0;
  46.  
  47. do
  48. {
  49. Console.Clear();
  50. if (volba == '1') ZadejKoeficienty(ref a, ref b, ref c);
  51. Console.WriteLine("1..Zadani koeficientu a reseni kvadratickou rovnice \n------------\n0..Konec");
  52. volba = Console.ReadKey().KeyChar;
  53. } while (volba != '0');
  54. }
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement