Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cmath>
- #include<cstdio>
- using namespace std;
- void nhap(float a, float b, float c){
- cin>>a>>b>>c;
- }
- void nghiem(float a, float b, float c){
- float x1, x2;
- if(a==0){
- if(b==0){
- if(c==0) cout<<"Phuong trinh co vo so nghiem";
- else cout<<"Phuong trinh vo nghiem";
- }
- if(b!=0){
- x1 = -c/b;
- printf("Nghiem cua phuong trinh la: %.2f", x1);
- }
- }
- else {
- float delta;
- int x = 0;
- delta = b*b-4*a*c;
- if(delta > 0) x=1;
- if(delta == 0) x=0;
- if(delta < 0) x=-1;
- switch(x){
- case 1:{
- x1 = (-b+sqrt(delta))/(2*a);
- x2 = (-b-sqrt(delta))/(2*a);
- printf("Phuong trinh co 2 nghiem la: %.2f, %.2f", x1, x2);
- break;
- }
- case 0:{
- x1 = -b/(2*a);
- printf("Nghiem cua phuong trinh la: %.2f", x1);
- break;
- }
- case -1:{
- cout<<"Pt vo nghiem";
- break;
- }
- default: cout<<"khong the giai phuong trinh nay!";
- }
- }
- }
- main(){
- float a,b,c;
- // nhap(a, b, c);
- cin>>a>>b>>c;
- nghiem(a, b, c);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement