0% found this document useful (0 votes)
12 views

Control flow

The document contains multiple C programs demonstrating basic programming concepts. These include finding the largest number using if-else statements, checking if a number is positive, negative, or zero, determining if a character is a vowel or consonant, checking if an integer is odd or even, and finding the roots of a quadratic equation. Each program includes necessary logic and input/output statements to perform its respective task.

Uploaded by

Swatilagna sahu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Control flow

The document contains multiple C programs demonstrating basic programming concepts. These include finding the largest number using if-else statements, checking if a number is positive, negative, or zero, determining if a character is a vowel or consonant, checking if an integer is odd or even, and finding the roots of a quadratic equation. Each program includes necessary logic and input/output statements to perform its respective task.

Uploaded by

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

(1) C Program to Find the Largest Number 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;
}

(2) C Program to check if a number is positive, negative, or zero using simple


conditional checks

#include <stdio.h>

void checkNum(int N) {

// Check if the number is zero


if (N == 0) {
printf("Zeri\n");
}
// Check if the number is less than zero
else if (N < 0) {
printf("Negative\n");
}
// If neither, the number is positive
else {
printf("Positive\n");
}
}

int main() {
int N = 10;
checkNum(N);
return 0;
}

(3)C program to check vowel or consonant

int main()
{
char ch = 'A';

// Checking if the character ch


// is a vowel or not.
if (ch == 'a' || ch == 'A' || ch == 'e' || ch == 'E'
|| ch == 'i' || ch == 'I' || ch == 'o' || ch == 'O'
|| ch == 'u' || ch == 'U') {

printf("The character %c is a vowel.\n", ch);


}
else {
printf("The character %c is a consonant.\n", ch);
}

return 0;
}
(4) Check whether an integer is odd or even

#include <stdio.h>
int main() {
int number;
printf("Enter an integer: ");
scanf("%d", &number);

// True if the remainder is 0


if (number%2 == 0) {
printf("%d is an even integer.",number);
}
else {
printf("%d is an odd integer.",number);
}

return 0;
}
(5) Find the roots of the quadratic equation

#include <math.h>
#include <stdio.h>
int main() {
double a, b, c, discriminant, root1, root2, realPart, imagPart;
printf("Enter coefficients a, b and c: ");
scanf("%lf %lf %lf", &a, &b, &c);

discriminant = b * b - 4 * a * c;

// condition for real and different roots


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

// condition for real and equal roots


else if (discriminant == 0) {
root1 = root2 = -b / (2 * a);
printf("root1 = root2 = %.2lf;", root1);
}

// if roots are not real


else {
realPart = -b / (2 * a);
imagPart = sqrt(-discriminant) / (2 * a);
printf("root1 = %.2lf+%.2lfi and root2 = %.2f-%.2fi", realPart, imagPart,
realPart, imagPart);
}

return 0;
}

You might also like