Decision Making in C: if, if-else, and switch Statements

Every interesting program needs to make decisions — do this if a condition holds, do something else otherwise. C provides two main tools for this: the if family of statements and the switch statement. This is Post 5, closing out the Unit I series on C fundamentals. The if Statement if (condition) { // executes … Read more

Check Whether a Character Is a Vowel, Consonant, Digit, or Special Character in C

This program reads a character from the keyboard and, using if-else statements, determines whether it is a vowel, consonant, digit, or special character. C Program #include <stdio.h> int main() { char ch; printf(“Enter a character: “); scanf(” %c”, &ch); if ((ch >= ‘a’ && ch = ‘A’ && ch = ‘A’ && ch = ‘0’ … Read more

Check Triangle Type: Equilateral, Isosceles, Scalene, or Invalid in C

This program reads the three sides of a triangle and determines whether it is equilateral, isosceles, scalene, or not a valid triangle at all — using nested if-else statements. C Program #include <stdio.h> int main() { float a, b, c; printf(“Enter the three sides of the triangle: “); scanf(“%f %f %f”, &a, &b, &c); if … Read more