To use Notepad to write code to compute an equation, you can follow these steps:
1. Open Notepad.
2. Type the following code:
#include <stdio.h>
int main() {
float a, b, c;
float discriminant;
float root1, root2;
printf("Enter the coefficients of the quadratic equation: ");
scanf(" %f %f %f ", &a, &b, &c);
discriminant = b * b - 4 * a * c;
if (discriminant > 0) {
root1 = (-b + sqrt(discriminant)) / (2 * a);
root2 = (-b - sqrt(discriminant)) / (2 * a);
printf("The roots of the equation are %f and %f.\n", root1, root2);
} else if (discriminant == 0) {
root1 = -b / (2 * a);
printf("The root of the equation is %f.\n", root1);
} else {
printf("The equation has no real roots.\n");
}
return 0;
}
3. Save the file as `equation.c`.
4. Open a terminal window. 5. Navigate to the directory where you saved the file. 6. Type the following command to compile the code:
gcc equation.c -o equation
7. Type the following command to run the code:
./equation
The code will prompt you to enter the coefficients of the quadratic equation. Enter the coefficients and the code will print the roots of the equation.
About Author
Discover more from SURFCLOUD TECHNOLOGY
Subscribe to get the latest posts sent to your email.