Develop a program to compute the roots of a quadratic equation by
accepting the coefficients. Print appropriate messages.
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
void main()
float a,b,c, root1, root2, realp, imgp, disc;
printf("\n\n Enter the values for coefficients a,b and c: ");
scanf("%f%f%f",&a,&b,&c);
if(a == 0 || b == 0 || c == 0)
printf("\n Invalid Inputs Try Again");
exit(0);
disc = b*b-4*a*c;
if(disc == 0)
printf("\nThe Roots are Equal");
root1 = root2 = -b / (2.0*a);
printf("\n Root1 = Root2 = %f", root1);
if(disc > 0)
{
printf("\n The Roots are Real and Distinct");
root1 = (-b + sqrt(disc))/(2.0*a);
root2 = (-b - sqrt(disc))/(2.0*a);
printf("\nRoot1 = %f", root1);
printf("\nRoot2 = %f", root2);
if(disc < 0)
printf("\n The Roots are Imaginary");
realp = -b/(2.0*a);
imgp = sqrt(fabs(disc))/(2.0*a);
printf("\nRoot1=%f +i %f",realp,imgp);
printf("\nRoot2 = %f -i %f",realp,imgp);
}
Implement Binary Search on Integers.
#include <stdio.h>
#include<stdlib.h>
void main()
int i, low, high, mid, n, key, a[100];
printf("Enter number of elements:\n");
scanf("%d",&n);
printf("Enter integer numbers in ascending order:\n");
for (i = 0; i< n; i++)
scanf("%d",&a[i]);
printf("Enter value to Search:\n");
scanf("%d", &key);
low = 0;
high = n - 1;
while (low <= high)
mid = (low+high)/2;
if (key == a[mid])
printf("%d found at location %d\n", key, mid+1);
exit(0);
}
if (key > a[mid] )
low = mid + 1;
if (key < a[mid])
high = mid - 1;
printf(" %d is Not found \n", key);