Quadratic Roots
Quadratic Roots
Algorithm:
Step 1. Start
Step 2. Read the coefficients of the equation, a, b and c from the user.
Step 3. Calculate discriminant = (b * b) – (4 * a * c)
Step 4. If discriminant > 0:
4.1: Calculate root1 = ( -b + sqrt(discriminant)) / (2 * a)
4.2: Calculate root2 = ( -b - sqrt(discriminant)) / (2 * a)
4.3: Display "Roots are real and different"
4.4: Display root1 and root2
Step 5: Else if discriminant = 0:
5.1: Calculate root1 = -b / (2 *a)
5.2: root2 = root1
5.3: Display "Root are real and equal"
5.4: Display root1 and root2
Step 6. Else:
6.1: Calculate real = -b / (2 * a)
6.2:Calculate imaginary = sqrt(-discriminant) / (2 * a)
6.3: Display “Roots are imaginary”
6.4: Display real, "±" , imaginary, "i"
Step 7. Stop
Program:
#include <math.h>
#include <stdio.h>
int main() {
double a, b, c, d, root1, root2, realPart, imagPart;
printf("Enter coefficients a, b and c: ");
scanf("%f %f %f", &a, &b, &c);
d = b * b - 4 * a * c;
return 0;
}
OUTPUT
Enter coefficients a, b and c: 1
2
1
root1 = -1.000000 and root2 = -1.000000
int main() {
int a = 11, b = 2, c = 9;
return 0;
}
Output:
1
2
3
3 is the largest number.
Output2:
3
2
1
3 is the largest number.
3Q)C program for finding grade based on marks:
STEP1:READ grade
STEP2:IF grade>=90
Print grade A
Step3:Else If grade>=70 && grade <= 89.99
Print grade B
Step4:Else if grade>=50 && grade >= 69.99
Print grade C
Step5:grade <50
Print Fail
Step6:stop
#include <stdio.h>
#include <stdlib.h>
int main()
{
// Write a program that would determine a student's grade based on the set ranges
float grade;
printf("Please enter the grade for the student (in percentages) : \n");
scanf("%f", grade);
if (grade>=90){
printf("GRADE A");
}
else if (grade>=70 && grade <= 89.99 ){
printf("GRADE B");
}
else if (grade>=50 && grade >= 69.99){
printf("GRADE C");
}
else {
printf(" failed");
}
return 0;
}