Script started on Fri Sep 9 12:18:45 2022 cascade:c++files> cat hello_example.c /* hello world */ #include int main () { printf("hello world.\n"); return 0; } cascade:c++files> gcc hello_example.c -o hello_example cascade:c++files> ./hello_example hello world. cascade:c++files> cascade:c++files> cat switch_example.c /* Simple example showing a switch statement -MCW Sept. 2022 */ #include int main () { // Go through all possibilities for (int number=0; number<4; number++) { switch (number) { case 0: printf("Zero\n"); break; case 1: printf("One\n"); break; case 2: printf("Two\n"); break; default: printf("Expecting number to be 0, 1, or 2.\n"); } } return 0; } cascade:c++files> gcc switch_example.c -o switch_example cascade:c++files> ./switch_example Zero One Two Expecting number to be 0, 1, or 2. cascade:c++files> cascade:c++files> cascade:c++files> cat scanf_example.c /* Simple example showing a scanf statement (user input) -MCW Sept. 2022 */ #include int main () { int number; // Give a prompt, so the user knows what to do. printf("Enter an integer: "); // "%d" says that we want a decimal number (integer) // The ampersand is important, and we'll talk about it in detail. scanf("%d", &number); // Just use number normally here, without the ampersand. printf("You entered %d \n", number); return 0; } cascade:c++files> gcc scanf_example.c -o scanf_example cascade:c++files> ./scanf_example Enter an integer: 3 You entered 3 cascade:c++files> ./scanf_example Enter an integer: 54321 You entered 54321 cascade:c++files> ./scanf_example Enter an integer: -98.7 You entered -98 cascade:c++files> ./scanf_example Enter an integer: I am not following directions You entered 180969526 cascade:c++files> cascade:c++files> cascade:c++files> cascade:c++files> ls -l rand*.c -rw-r--r-- 1 mweeks staff 6588 Nov 24 1992 rand.c -rw-r--r-- 1 mweeks staff 1069 Sep 9 12:06 random_example.c cascade:c++files> cascade:c++files> cat random_example.c /* Simple random number example -MCW Sept. 2022 */ #include // input, output #include // for random, srandom #include // for floor function #include // for time function int main () { // Call srandom to "seed" the random number generator. // See // https://stackoverflow.com/questions/16569239/how-to-use- // function-srand-with-time-h // for more detail about srandom and time. // Basically, time returns a different value each time we run it. // Use it to give us a non-predictable sequence of random numbers. unsigned int mytime; // get the current time mytime = time(NULL); // Seed the random number generator srandom(mytime); // random() returns a long integer. // Make sure to use random() instead of rand(). // Use % (modulus) to reduce it to something manageable, // in this case < 100. long r1 = random() % 100; // %li is for a long integer. %ld works too. printf("A random integer is %li.\n", r1); return 0; } cascade:c++files> gcc random_example.c -o random_example cascade:c++files> ./random_example A random integer is 26. cascade:c++files> ./random_example A random integer is 91. cascade:c++files> ./random_example A random integer is 72. cascade:c++files> exit exit Script done on Fri Sep 9 12:21:59 2022