Tuesday, 29 May 2012

2b) Write a C program toe find the roots of a quadratic equation.

/*******program on quadratic equations********/


#include<stdio.h>
#include<conio.h>
#include<math.h>
main()
{
int a,b,c;
int delta,root1,root2;
 printf("\nEnter the value for a:");
scanf("%d",&a);
printf("\nEnter the value for b:");
scanf("%d",&b);
printf("\n Enter the value for c");
scanf("%d",&c);
delta=pow(b,2)-4*a*c
 if(delta<0)
      printf("\n The roots are imaginary")
else
if(delta>0)
{
root1= (-b-sqrt(delta))/(2*a)
root2= (-b+sqrt(delta))/(2*a)
printf("\nThe roots are \nroot1=%d \t root2=%d",root1,root2);
 }
else
{
root = -b/2*a;
printf("\n The root is  %d",&root);

}

No comments:

Post a Comment