Advertisement
Guest User

kwadratowa

a guest
Mar 13th, 2016
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. #include <conio.h>
  4. #include <fstream>
  5.  
  6. using namespace std;
  7.  
  8. void kwadratowa (float a,float b,float c)
  9. {
  10. float delta=(b*b)-(4*a*c);
  11.  
  12. if (delta<0)
  13. cout<<"nie ma miejsc zerowych"<<endl;
  14. if (delta==0)
  15. {
  16. float x1=(-b)/(2*a);
  17. cout<<"miejsce zerowe wynosi "<<x1<<endl;
  18. }
  19. if (delta>0)
  20. {
  21. float x1=(-b-sqrt(delta))/(2*a);
  22. float x2=(-b+sqrt(delta))/(2*a);
  23. cout<<"miejsca zerowe to "<<x1<<" oraz "<<x2<<endl;
  24. }
  25. }
  26.  
  27. main ()
  28. {
  29.  
  30. ifstream odczyt("rownanie kwadratowe z pliku dane.txt");
  31. float a,b,c;
  32.  
  33. if (odczyt)
  34. {
  35. while (!odczyt.eof())
  36. {
  37. odczyt>>a;
  38. odczyt>>b;
  39. odczyt>>c;
  40. kwadratowa(a,b,c);
  41. }
  42. }
  43.  
  44.  
  45.  
  46.  
  47. fstream plik("rownanie kwadratowe z pliku wynik.txt", ios::out);
  48.  
  49. if( plik.good() )
  50. {
  51.  
  52.  
  53. plik <<"miejsca zerowe to: "<< kwadratowa << " ";
  54. plik.flush();
  55.  
  56. plik.close();
  57. }
  58. return 0 ;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement