Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<math.h>
- float delt(float a,float b,float c){
- float sonuc;
- sonuc= b*b-4*a*c;
- return sonuc;
- }
- float solve(float a,float b,float c,float *root1,float *root2){
- float delta,sonuc;
- if(a==0){
- return -1;
- }
- delta=delt(a,b,c);
- if(sonuc==0){
- *root1=(-1*b/2*a);
- return 1;
- }
- if(sonuc<0){
- return 0;
- }
- *root1=(-1*b+sqrt(delt(a,b,c)))/2*a;
- *root2=(-1*b-sqrt(delt(a,b,c)))/2*a;
- return 2;
- }
- int main(){
- int solved;
- float a,b,c;
- float r1,r2;
- scanf("%f%f%f",&a,&b,&c);
- solved = solve(a,b,c,&r1,&r2);
- if(solved == -1) {
- printf("not quadratic\n");
- }
- if(solved == 1){
- printf("r1=r2: %f",r1);
- }
- if(solved == 2){
- printf("r1: %f r2: %f",r1,r2);
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement