I think there may be a problem with my usage of brackets below.
Any ideas on this simple program to find roots of quadratic equation?
many thanks!
includeCode:#include <stdio.h> #include <stdlib.h> #include <math.h> int main() { char answer; int a,b,c; float single_root, root_part1, root_part2;//declaring function variables these //being different elements of the //quadratic formula float root1, root2; int is_complex; do printf("Enter coeficients a b c: "); scanf("%f %f %f", &a, &b, &c); is_complex = 0; //(is_complex) function = 0 if a=0 if (a==0) { single_root=-1.0*c/b;//stating variables } else { root_part1 = -1.0*b/(2.0*a); //stating variables root_part2= b*b-4.0*a*c; if (root_part2<0.0) { is_complex = 1; root_part2= -1.0*root_part2;//remember this is not equal to, //this is a directive } root_part2=sqrt(root_part2)/(2.0*a); } if(a==0.0) { Printf("single_root = %f\n ", single_root);//single root case } else if (is_complex==1) { printf("root 1 = %.2f+%.2f i\n", root_part1, root_part2); printf("root 1 = %.2f-%.2f i\n", root_part1, root_part2); } else { root1= root_part1+root_part2; root2= root_part1-root_part2; printf("root1 = %.2f", root1); printf("root2 = %.2f", root2); } { printf("enter next set of coefficients (y/n): "); scanf(" %c", &answer); } while (answer != 'n' && answer != 'N'); scanf("d\n"); exit(0); }



LinkBack URL
About LinkBacks




More portable.