Switch & Loop – Let us C https://c.praveshagrawal.com Example C Programs Sat, 02 Dec 2023 10:59:07 +0000 en-US hourly 1 https://wordpress.org/?v=6.5.3 Do-While Loop Example https://c.praveshagrawal.com/2023/12/02/do-while-loop-example/ https://c.praveshagrawal.com/2023/12/02/do-while-loop-example/#respond Sat, 02 Dec 2023 10:59:07 +0000 https://c.praveshagrawal.com/?p=46 #include <stdio.h> int main() { // Using a do-while loop to print numbers from 1 to 5 printf("Do-While Loop Example:\n"); int i = 1; do { printf("%d\n", i); i++; } while (i <= 5); return 0; } ]]> https://c.praveshagrawal.com/2023/12/02/do-while-loop-example/feed/ 0 While Loop Example https://c.praveshagrawal.com/2023/12/02/while-loop-example/ https://c.praveshagrawal.com/2023/12/02/while-loop-example/#respond Sat, 02 Dec 2023 10:58:41 +0000 https://c.praveshagrawal.com/?p=44 #include <stdio.h> int main() { // Using a while loop to print numbers from 1 to 5 printf("While Loop Example:\n"); int i = 1; while (i <= 5) { printf("%d\n", i); i++; } return 0; } ]]> https://c.praveshagrawal.com/2023/12/02/while-loop-example/feed/ 0 For Loop Example https://c.praveshagrawal.com/2023/12/02/for-loop-program/ https://c.praveshagrawal.com/2023/12/02/for-loop-program/#respond Sat, 02 Dec 2023 10:58:01 +0000 https://c.praveshagrawal.com/?p=41 #include <stdio.h> int main() { // Using a for loop to print numbers from 1 to 5 printf("For Loop Example:\n"); for (int i = 1; i <= 5; i++) { printf("%d\n", i); } return 0; } ]]> https://c.praveshagrawal.com/2023/12/02/for-loop-program/feed/ 0 Switch with C https://c.praveshagrawal.com/2023/12/02/switch-with-c/ https://c.praveshagrawal.com/2023/12/02/switch-with-c/#respond Sat, 02 Dec 2023 10:56:53 +0000 https://c.praveshagrawal.com/?p=39 #include <stdio.h> int main() { // Declare a variable char grade; // Prompt the user for input printf("Enter your grade (A, B, C, D, or F): "); // Read user input scanf(" %c", &grade); // Note the space before %c to consume any leading whitespace // Evaluate the grade using a switch statement switch (grade) { case 'A': printf("Excellent!\n"); break; case 'B': printf("Good!\n"); break; case 'C': printf("Satisfactory\n"); break; case 'D': printf("Needs Improvement\n"); break; case 'F': printf("Fail\n"); break; default: printf("Invalid grade entered.\n"); } return 0; } ]]> https://c.praveshagrawal.com/2023/12/02/switch-with-c/feed/ 0