C Program Assignments
C Program Assignments
C program to find the roots of a quadratic equation ax^2 + bx + c = 0 using nested if-else
statements.
3. Conditions:
a. If the discriminant is positive, there are two real and distinct roots.
C Code:
#include <stdio.h>
#include <math.h>
int main() {
discriminant = b * b - 4 * a * c;
if (discriminant > 0) {
printf("Roots are real and distinct: %.2f and %.2f\n", root1, root2);
} else if (discriminant == 0) {
printf("Roots are real and equal: %.2f and %.2f\n", root1, root2);
} else {
realPart = -b / (2 * a);
printf("Roots are complex: %.2f + %.2fi and %.2f - %.2fi\n", realPart, imaginaryPart, realPart,
imaginaryPart);
return 0;
C program to check whether a given year is a leap year using nested if-else statements.
3. Output: The program prints whether the given year is a leap year.
C Code:
#include <stdio.h>
int main() {
int year;
scanf("%d", &year);
if (year % 4 == 0) {
if (year % 100 == 0) {
if (year % 400 == 0) {
} else {
} else {
} else {
return 0;