-
-
Notifications
You must be signed in to change notification settings - Fork 122
Expand file tree
/
Copy pathintroductionToSWITCH.c
More file actions
53 lines (45 loc) · 1.25 KB
/
introductionToSWITCH.c
File metadata and controls
53 lines (45 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// I will be creating a SWITCH script example, a switch can be used instead of if...else statements to optimize the code.
#include <stdio.h>
int main()
{
int selectedNum;
printf("Please select a number between [1-10] and it will be printed on the screen.");
scanf("%d",&selectedNum);
switch (selectedNum)
{
case 1:
printf("The selected number was 1");
break;
case 2:
printf("The selected number was 2");
break;
case 3:
printf("The selected number was 3");
break;
case 4:
printf("The selected number was 4");
break;
case 5:
printf("The selected number was 5");
break;
case 6:
printf("The selected number was 6");
break;
case 7:
printf("The selected number was 7");
break;
case 8:
printf("The selected number was 8");
break;
case 9:
printf("The selected number was 9");
break;
case 10:
printf("The selected number was 10");
break;
default:
printf("The selected number is not between 0 and 10.");
break;
}
}
// another alternative to this script would be checking if selectedNum is bigger or equal to 1 and smaller or equal to 10.