Introduction to Loop in c programming

  

Different question of using loop in c programming

  

example of different qauestion using switch in c programming

  

example of how to use condition in c

  

Different example of condition in c programming

  

example of how to use switch in c programming

  

Introduction to array in c programming

  

Different question and answer in array

  

example of how to use switch using switch


example of a simple C program that uses a `switch` statement to determine the day of the week based on a user-input number:



1. switch Statements:


The switch statement is another way to control program flow based on the value of an expression. It's typically used when you have a single expression that you want to compare to multiple values.


example of switch stament


In this program, the user enters a number, and the `switch` statement is used to determine and print the corresponding day of the week. The `default` case is used to handle invalid inputs


#include <stdio.h>
int main() {
int day;
// Prompt the user to enter a number (1-7)
printf("Enter a number (1-7): ");
scanf("%d", &day);
switch (day) {
case 1:
printf("Monday\n");
break;
case 2:
printf("Tuesday\n");
break;
case 3:
printf("Wednesday\n");
break;
case 4:
printf("Thursday\n");
break;
case 5:
printf("Friday\n");
break;
case 6:
printf("Saturday\n");
break;
case 7:
printf("Sunday\n");
break;
default:
printf("Invalid input. Please enter a number between 1 and 7.\n");
}
return 0;
}

Contact Us

Email: info@learn.co.rw
Phone: +250723709880
Whatsap: +250725527181

we will try to reply to your message as quickly as we can. please be aware that because of many messages we receive it take us same time to respond