This program is for finding the roots (ie. Real and Imaginary part) of a equation. This is a part of Mumbai University MCA Colleges C Programs MCA Sem 1
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float a,b,c;
float r1,r2,num,real,img;
clrscr();
printf("Enter the values of a,b & c\n");
scanf("%f %f %f",&a,&b,&c);
num=((b*b)-(4*a*c));
if(a==0)
{
printf("Its not a quadratic equation");
}
else
{
if(num<0)
{
real=-b/(2*a);
img=(sqrt(-num)/(2*a));
printf("The roots are %f + %fi\n",real,img);
printf("The roots are %f - %fi",real,img);
}
else
{
r1=(-b+(sqrt(num)))/(2*a);
r2=(-b-(sqrt(num)))/(2*a);
printf("The roots are %f and %f",r1,r2);
}
}
getch();
}
Hope this Program is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs. Happy Programming and Studying.
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float a,b,c;
float r1,r2,num,real,img;
clrscr();
printf("Enter the values of a,b & c\n");
scanf("%f %f %f",&a,&b,&c);
num=((b*b)-(4*a*c));
if(a==0)
{
printf("Its not a quadratic equation");
}
else
{
if(num<0)
{
real=-b/(2*a);
img=(sqrt(-num)/(2*a));
printf("The roots are %f + %fi\n",real,img);
printf("The roots are %f - %fi",real,img);
}
else
{
r1=(-b+(sqrt(num)))/(2*a);
r2=(-b-(sqrt(num)))/(2*a);
printf("The roots are %f and %f",r1,r2);
}
}
getch();
}
Hope this Program is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs. Happy Programming and Studying.
No comments:
Post a Comment