Skip to content

Instantly share code, notes, and snippets.

@oykelrae
Last active December 13, 2019 13:20
Show Gist options
  • Save oykelrae/5d6671f74f74be7d2d02cd0c81333b46 to your computer and use it in GitHub Desktop.
Save oykelrae/5d6671f74f74be7d2d02cd0c81333b46 to your computer and use it in GitHub Desktop.
Switch statement. "Whether a entered number is divisible by 6" program
#include <stdio.h>
int main(void) {
printf("Let's see if your number is divisible by 6.\nEnter a number: ");
int num;
scanf("%d",&num);
switch (num%3) {
case 0 :
switch (num%2) {
case 0 : printf("YES\n"); break;
case 1 : printf("NO\n"); break;
}
break;
case 1 :
case 2 : printf("NO\n\n"); break;
}
return 0;
}
Let's see if your number is divisible by 6.
Enter a number: 136
NO
Program ended with exit code: 0
@oykelrae
Copy link
Author

This program was created based on the listing 7 from YoungCoder.ru: http://youngcoder.ru/lessons/6/switch.php.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment