0% found this document useful (0 votes)
25 views9 pages

Quadratic Roots

Uploaded by

R Vishnu Vardhan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views9 pages

Quadratic Roots

Uploaded by

R Vishnu Vardhan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

1Q)Program for finding 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;

// condition for real and different roots


if (d > 0) {
root1 = (-b + sqrt(d)) / (2 * a);
root2 = (-b - sqrt(d)) / (2 * a);
printf("root1 = %f and root2 = %f", root1, root2);
}

// condition for real and equal roots


else if (d == 0) {
root1 = root2 = -b / (2 * a);
printf("root1 = %f and root2 = %f", root1, root2);
}
// if roots are not real
else {
realPart = -b / (2 * a);
imagPart = sqrt(-discriminant) / (2 * a);
printf("root1 = %f+%fi and root2 = %f-%fi", realPart, imagPart, realPart, imagPart);
}

return 0;
}
OUTPUT
Enter coefficients a, b and c: 1
2
1
root1 = -1.000000 and root2 = -1.000000

Enter coefficients a, b and c: 2


5
9
root1 = -1.250000+1.713914i and root2 = -1.250000-1.713914i

2Q)Program for finding biggest of 3 numbers:


Algorithm:
1. Start
2. Add values to A, B, and C for comparison.
3. Check whether A is Greater than B.
o If it is true, see if A is greater than C.
 If it is true, print ‘A’ as the greatest number.
 ‘C’ will be printed as the greatest number if false.
o If that is false, check if B is greater than C.
 If it is true, print ‘B’ as the highest number.
 ‘C’ will be printed as the greatest number if false.
4. End

// C program to find the maximum number out of the three


// given numbers using if-else statement
#include <stdio.h>

int main() {
int a = 11, b = 2, c = 9;

// Finding max using compound expressions


if (a >= b && a >= c)
printf("%d is the largest number.", a);
else if (b >= a && b >= c)
printf("%d is the largest number.", b);
else
printf("%d is the largest number.", c);

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;
}

You might also like