Advertisement
Guest User

Untitled

a guest
Dec 12th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. #include <fstream>
  4.  
  5. using namespace std;
  6.  
  7. int main(){
  8. fstream f;
  9. fstream g;
  10. f.open("dane.txt");
  11. g.open("dane-zapis.txt");
  12. float a ,b ,c, x0, x1, x2;
  13. double delta;
  14. string liczby;
  15. getline(f, liczby);
  16.  
  17.  
  18.  
  19. while(!f.eof()){
  20.  
  21. cout << a << "x^2+" << b << "x+" << c << "=0\n";
  22. g << a << "x^2+" << b << "x+" << c << "=0\n";
  23.  
  24. delta = b * b - 4 * a * c;
  25.  
  26. cout << "delta=" << delta << endl;
  27. g << "delta=" << delta << endl;
  28.  
  29. if (delta < 0) {
  30.  
  31. cout << "Brak rozwiazan\n";
  32. g << "Brak rozwiazan\n";
  33.  
  34. } else if (delta == 0) {
  35. x0 = (-b / (2 * a));
  36.  
  37. cout << "pierwiastek to " << x0 << "\n";
  38. g << "pierwiastek to " << x0 << "\n";
  39.  
  40. } else {
  41. x1 = (-b - sqrt(delta)) / (2 * a);
  42. x2 = (-b + sqrt(delta)) / (2 * a);
  43.  
  44. cout << "pierwszy pierwiastek: " << x1 << "\ndrugi pierwiastek:" << x2;
  45. g << "pierwszy pierwiastek: " << x1 << "\ndrugi pierwiastek:" << x2;
  46. }
  47. }
  48. f.close();
  49. g.close();
  50.  
  51.  
  52. return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement