Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<math.h>
- void main()
- {
- int a,b,c;
- float fa,fb,fc,total[2],sqrcheck;
- printf("Enter the Coefficients: ");
- scanf("%d %d %d",&a,&b,&c);
- switch(a){
- case 0: break;
- case 1: printf("x^2"); break;
- case -1: printf("-x^2"); break;
- default: printf("%dx^2",a);
- }
- switch(b){
- case 0: break;
- case 1: printf("x"); break;
- case -1: printf("-x"); break;
- default: if(a==0 || b<0){printf("%dx",b);}else if(b>0){printf("+%dx",b);}
- }
- switch(c){
- case 0: break;
- case 1: if(a==0&&b==0){printf("1");}else {printf("+1");}; break;
- case -1: printf("-1"); break;
- default: if(a==0 && b==0 || c<0){printf("%d",c);}else if(c>0){printf("+%d",c);};
- }
- fa = a;
- fb = b;
- fc = c;
- sqrcheck = pow(fb,2) - (4.0*fa*fc);
- total[0] = (- fb + sqrt(sqrcheck)) / (2.0*fa);
- total[1] = (- fb - sqrt(sqrcheck)) / (2.0*fa);
- if(sqrcheck>=0 && fa != 0){
- printf("\nx = %.5g and %.5g",total[0],total[1]);
- }
- else if(sqrcheck < 0){
- printf("\nROOT DOES NOT EXIST...\nTHE VALUE UNDER ROOT IS (%g)",sqrcheck);
- }
- else if(a == 0){
- printf("\nINFINITY or It is not a QUADRATIC EQUATION.\nBUT CURRENT VALUE UNDER ROOT IS (%g)",sqrcheck);
- }
- else{
- printf("\nThere is no Answer");
- exit(0);
- }
- getchar();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement