Complex root calculator
Hi Everyone
Hi Family I hope so you all are fine and doing your work during this pandemic of covid-19. I hope so you all are safe and all are stay at your home. I hope so my family will take my advice seriously and my family will stay in their own home for sometime so that they can protect themselves. I feel that you are my family so i had given this advice if you don't like it so please forgive me for giving this suggestion. So Today we are going to make a basic program on finding square root of a number or complex root of a number using c programming. So without wasting your time let's get started.
Today we are going to talk about making a basic program for finding the square root of any number. So for this we neet to use math.h header file and some important formulas to keep in mind so that we can find square root of a number. The formulas are for ax^2+bx+c=0
- If d>0 then x=(-b±√d)/2a.
- If d=0 then x=b/2a.
So for this we will get first off all in input we will have a , b, c and then we will find d and then we will find the roots of this equation so let's get started
Program:
#include<stdio.h>
#include<math.h>
void main()
{
double a,b,c,d,rt1,rt2;
printf("Enter a,b,c ");
scanf("%f%f%f",&a,&b,&c);
d=b*b - 4*a*c;
if(d>=0)
{
if(d>0)
{
rt1=(-b+sqrt(d))/(2.0*a);
rt2=(-b-sqrt(d))/(2.0*a);
printf("The first root is : %f",rt1);
printf("The second root is : %f",rt2);
}
else
{
rt1=-b/(2.0*a);
printf("The root is : %f\n",rt1);
}
}
else
{
rt1=(-b+sqrt(d))/(2.0*a);
printf("root is : (- %5.2f ±i %5.2f)/(2*%5.2f)\n",b,d,a);
}
}
In this you can see first we have given three parameters means a,b,c after that we will evaluate delta so that we can confirm that roots are imaginary or one root or two roots are that after that we have used the sqft function which will give us the square root of number. After that we have usen the conditional statements to check if d>0 so we have to print two roots. If d=0 we have to print 1 root and if d<0 then we have to print imaginary roots. So using this logic you can make a root calculator. You can also use switch statement to make this calculator for addition, substract, multiplication, division and square root.
So this is a practicle of c programming language. This is a small practicle or i can say that a project where you can learn so many things like conditional statements , use of printf, scanf and sqft function of math.h header file.
Thanks for watching this . Thanks to my family or I can say that thanks to everyone who is watching this blog. Thanks to everyone for supporting me. Please comment if you face any problem or have any doubt in this. Thanks my family.
Made by:great lord shri krishna
Comments
Post a Comment