PRACTICAL 3.1: FIND ROOTS OF QUADRATIC EQNS
EXPERIMENT 3
PRACTICAL : 3.1
Aim: FIND ROOTS OF QUADRATIC EQNS
code:
#include<stdio.h>
#include<math.h> /* mthis includes math functions like pow*/
void main(){
float a,b,c,root1,root2,D,real,img;
printf("Enter value of 'a': ");
scanf("%f",&a);
printf("Enter value of 'b': ");
scanf("%f",&b);
printf("Enter value of 'c': ");
scanf("%f",&c);
D=b*b-4*a*c;
printf("\nDescriminent= %f",D);
if (D==0){
root1=root2=-b/(2*a);
printf("\nRoots are equal: %f",root1);
}
else if(D>0){
root1=-b+sqrt(D)/(2*a);
root2=-b-sqrt(D)/(2*a);
printf("\nDifferent Roots fount! They are: \n 1. %f \n 2. %f",root1,root2);
}
else real=-b/(2*a);
img=sqrt(-D)/(2*a);
printf("\nComplex numbers Fount; \n 1.Root 1: %f+%fi \n 2.Root 2: %f-%fi",real,img,real,img);
printf("\n\n A Program by SUKH");
}