Skip to content

Instantly share code, notes, and snippets.

@btechmag
Created April 29, 2021 07:25
Show Gist options
  • Save btechmag/69f1ec719d321d25c94c51bd80f1fda2 to your computer and use it in GitHub Desktop.
Save btechmag/69f1ec719d321d25c94c51bd80f1fda2 to your computer and use it in GitHub Desktop.
C Program to print the roots of integers using Bhaskara's formula.
#include<stdio.h>
#include<math.h>
int main()
{
//Program to print the roots of numbers using Bhaskara's formula
double a, b, c, temp;
printf("Input the first number: ");
scanf("%lf", &a);
printf("Input the second number: ");
scanf("%lf", &b);
printf("Input the third number: ");
scanf("%lf", &c);
temp = (b * b) - (4 * a * c);
if(temp > 0 && a != 0)
{
temp = sqrt(temp);
printf("Root1 = %.3lf ", (-b + temp) / (2 * a) );
printf("\nRoot2 = %.3lf ", (-b - temp) / (2 * a));
}
else
{
printf("Impossible to find the roots");
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment