If Else – Let us C https://c.praveshagrawal.com Example C Programs Sat, 02 Dec 2023 11:25:01 +0000 en-US hourly 1 https://wordpress.org/?v=6.5.3 Logical AND/OR in If-Else https://c.praveshagrawal.com/2023/12/02/logical-and-or-in-if-else/ https://c.praveshagrawal.com/2023/12/02/logical-and-or-in-if-else/#respond Sat, 02 Dec 2023 11:25:01 +0000 https://c.praveshagrawal.com/?p=124 #include <stdio.h> int main() { // Logical AND/OR in if-else int age; char gender; printf("Enter your age: "); scanf("%d", &age); printf("Enter your gender (M/F): "); scanf(" %c", &gender); // Note the space before %c to consume any leading whitespace if (age >= 18 && gender == 'M') { printf("You are an adult male.\n"); } else if (age >= 18 && gender == 'F') { printf("You are an adult female.\n"); } else { printf("You are not an adult.\n"); } return 0; } ]]> https://c.praveshagrawal.com/2023/12/02/logical-and-or-in-if-else/feed/ 0 Ternary Operator https://c.praveshagrawal.com/2023/12/02/ternary-operator/ https://c.praveshagrawal.com/2023/12/02/ternary-operator/#respond Sat, 02 Dec 2023 11:24:38 +0000 https://c.praveshagrawal.com/?p=118 #include <stdio.h> int main() { // Ternary operator int num1, num2, max; printf("Enter two numbers: "); scanf("%d %d", &num1, &num2); max = (num1 > num2) ? num1 : num2; printf("Maximum number: %d\n", max); return 0; } ]]> https://c.praveshagrawal.com/2023/12/02/ternary-operator/feed/ 0 If-Else Ladder https://c.praveshagrawal.com/2023/12/02/if-else-ladder/ https://c.praveshagrawal.com/2023/12/02/if-else-ladder/#respond Sat, 02 Dec 2023 11:24:18 +0000 https://c.praveshagrawal.com/?p=119 #include <stdio.h> int main() { // If-else ladder int marks; printf("Enter your marks: "); scanf("%d", &marks); if (marks >= 90) { printf("Grade: A\n"); } else if (marks >= 80) { printf("Grade: B\n"); } else if (marks >= 70) { printf("Grade: C\n"); } else if (marks >= 60) { printf("Grade: D\n"); } else { printf("Grade: F\n"); } return 0; } ]]> https://c.praveshagrawal.com/2023/12/02/if-else-ladder/feed/ 0 Nested If-Else Statement https://c.praveshagrawal.com/2023/12/02/nested-if-else-statement/ https://c.praveshagrawal.com/2023/12/02/nested-if-else-statement/#respond Sat, 02 Dec 2023 11:24:03 +0000 https://c.praveshagrawal.com/?p=120 #include <stdio.h> int main() { // Nested if-else statement int score; printf("Enter your exam score: "); scanf("%d", &score); if (score >= 90) { printf("Grade: A\n"); } else { if (score >= 80) { printf("Grade: B\n"); } else { printf("Grade: C\n"); } } return 0; } ]]> https://c.praveshagrawal.com/2023/12/02/nested-if-else-statement/feed/ 0 Simple If-Else Statement https://c.praveshagrawal.com/2023/12/02/using-if-else-statement/ https://c.praveshagrawal.com/2023/12/02/using-if-else-statement/#respond Sat, 02 Dec 2023 10:55:28 +0000 https://c.praveshagrawal.com/?p=37 #include <stdio.h> int main() { // Simple if-else statement int number; printf("Enter an integer: "); scanf("%d", &number); if (number % 2 == 0) { printf("The entered number is even.\n"); } else { printf("The entered number is odd.\n"); } return 0; } ]]> https://c.praveshagrawal.com/2023/12/02/using-if-else-statement/feed/ 0