Q:

Write a C program to print the roots of Bhaskara’s formula from the given three floating numbers. Display a message if it is not possible to find the roots

0

Write a C program to print the roots of Bhaskara’s formula from the given three floating numbers. Display a message if it is not possible to find the roots

Test Data :
Input the first number(a): 25
Input the second number(b): 35
Input the third number(c): 12
Expected Output:
Root1 = -0.60000
Root2 = -0.80000

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <stdio.h>
#include <math.h>    
int main() {
	double a, b, c, pr1;  	
	printf("\nInput the first number(a): "); 
    scanf("%lf", &a);
    printf("\nInput the second number(b): "); 
    scanf("%lf", &b);
    printf("\nInput the third number(c): "); 
    scanf("%lf", &c);
	pr1 = (b*b) - (4*(a)*(c));
    if(pr1 > 0 && a != 0) {
		double x, y;
		pr1 = sqrt(pr1);
		x = (-b + pr1)/(2*a);
		y = (-b - pr1)/(2*a);
		printf("Root1 = %.5lf\n", x);
		printf("Root2 = %.5lf\n", y);
	} 
	else
	 {
		printf("\nImpossible to find the roots.\n");
	}
	return 0;
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now