Selections: Demo

Variables and data types
  • Ses2Operators Source Code

    #include <stdio.h>

    #include <stdlib.h>

     

    int main(int argc, char *argv[]) {

        int x = 10;

        int y = 3;

        printf("If demo\n");

        if (x > y) {

            printf("x is greater than y\n");

        }

        printf("If else demo\n");

        if (x < y) {

            printf("x is smaller than y\n");

        } else {

            printf("x is greater than or equal to y\n");

        }

        printf("If else if demo\n");

        if (x < y) {

            printf("x is smaller than y\n");

        } else if (x == y) {

            printf("x is equal to y\n");

        } else {

            printf("x is greater than y\n");

        }

        return 0;

    }

  • Ses2SwitchCase Source Code

    #include <stdio.h>

    #include <stdlib.h>

     

    /* run this program using the console pauser or add your own getch, system("pause") or input loop */

     

    int main(int argc, char *argv[]) {

        int x;

        printf("Please input the fan speed (1, 2, 3), or 0 to stop: ");

        scanf("%d", &x);

        switch (x) {

            case 0:

                printf("The fan is off\n");

                break;

            case 1:

                printf("The fan is running with speed one\n");

                break;

            case 2:

                printf("The fan is running with speed two\n");

                break;

            case 3:

                printf("The fan is running with speed three\n");

                break;

            default:

                printf("Invalid input\n");

                break;

        }

        return 0;

    }