Script started on Mon Sep 30 12:43:44 2024 mweeks@air:C_ch3$ cat array_example.c /* Array of 100 ints -MCW Sept. 2024 */ #include #define ARRAY_SIZE 100 int main () { int i; int myarray[ARRAY_SIZE] = { 23, 45, 56, 67 }; for (i=0; i int main () { int number; printf("enter an int: "); scanf("%d", &number); printf("You entered %d, and mod 100 it is %d\n", number, number % 100); return 0; } mweeks@air:C_ch3$ ./a.out enter an int: 34 You entered 34, and mod 100 it is 34 mweeks@air:C_ch3$ ./a.out enter an int: 103 You entered 103, and mod 100 it is 3 mweeks@air:C_ch3$ ./a.out enter an int: 99 You entered 99, and mod 100 it is 99 mweeks@air:C_ch3$ ./a.out enter an int: 100 You entered 100, and mod 100 it is 0 mweeks@air:C_ch3$ echo "operators ++ and --" operators ++ and -- mweeks@air:C_ch3$ cp mod_example.c inc_dec_example.c mweeks@air:C_ch3$ vi inc_dec_example.c mweeks@air:C_ch3$ gcc inc_dec_example.c inc_dec_example.c:14:71: warning: unsequenced modification and access to 'number' [-Wunsequenced] ...entered %d, and ++ is %d and -- is %d\n", number, number++, number--); ~~~~~~ ^ 1 warning generated. mweeks@air:C_ch3$ vi inc_dec_example.c mweeks@air:C_ch3$ gcc inc_dec_example.c mweeks@air:C_ch3$ cat inc_dec_example.c /* mod example -MCW Sept. 2024 */ #include int main () { int number; printf("enter an int: "); scanf("%d", &number); int num2 = number; int num3 = number; printf("You entered %d, and ++ is %d and -- is %d\n", number, num2++, num3--); return 0; } mweeks@air:C_ch3$ ./a.out enter an int: 7 You entered 7, and ++ is 7 and -- is 7 mweeks@air:C_ch3$ vi inc_dec_example.c mweeks@air:C_ch3$ gcc inc_dec_example.c mweeks@air:C_ch3$ ./a.out enter an int: 7 You entered 7, and ++ is 7 and -- is 7 after 8 and 6 You entered 7, and ++ is 8 and -- is 6 mweeks@air:C_ch3$ cat inc_dec_example.c /* inc/dec example -MCW Sept. 2024 */ #include int main () { int number; printf("enter an int: "); scanf("%d", &number); int num2 = number; int num3 = number; printf("You entered %d, and ++ is %d and -- is %d\n", number, num2++, num3--); printf("after %d and %d\n", num2, num3); num2 = number; num3 = number; printf("You entered %d, and ++ is %d and -- is %d\n", number, ++num2, --num3); return 0; } mweeks@air:C_ch3$ mweeks@air:C_ch3$ mweeks@air:C_ch3$ echo "operators < > <= >= == !=" operators < > <= >= == != mweeks@air:C_ch3$ echo "precedence + - (unary) +5 -3" precedence + - (unary) +5 -3 mweeks@air:C_ch3$ echo "precedence * / %" precedence * / % mweeks@air:C_ch3$ echo "precedence + - (binary) 2+5 1-3" precedence + - (binary) 2+5 1-3 mweeks@air:C_ch3$ echo "1 - 3 * 2 1 - (6) -5" 1 - 3 * 2 1 - (6) -5 mweeks@air:C_ch3$ echo "(1 - 3) * 2" (1 - 3) * 2 mweeks@air:C_ch3$ echo " 3 - 4 + 1" 3 - 4 + 1 mweeks@air:C_ch3$ echo " 0 is false, but anything else is true" 0 is false, but anything else is true mweeks@air:C_ch3$ cd ../C_ch5 mweeks@air:C_ch5$ ls bitcount.c expr.c mweeks@air:C_ch5$ echo "ch5: logical ops && || ! " ch5: logical ops && || ! mweeks@air:C_ch5$ cat expr.c // expr1 : expr2 expr3 // Conditional operators // "?" followed by ":" // // expr1? expr2:expr3; // this means // if expr1 is true then // expr2 // else // expr3 for (i=0; i #define n 6 int main() { int a[n] = {1, 2, 3, 4, 5, 6}; int i; for (i=0; i #define n 6 int main() { int a[n] = {1, 2, 3, 4, 5, 6}; int i; for (i=0; i #define n 6 int main() { int a[n] = {101, 102, 103, 104, 105, 106}; int i; for (i=0; i int main () { for (int i=0; i<10; i++) printf("%d %% 5 is %d\n", i, (i%5)); return 0; } mweeks@air:C_ch5$ gcc modulus.c mweeks@air:C_ch5$ ./a.out 0 % 5 is 0 1 % 5 is 1 2 % 5 is 2 3 % 5 is 3 4 % 5 is 4 5 % 5 is 0 6 % 5 is 1 7 % 5 is 2 8 % 5 is 3 9 % 5 is 4 mweeks@air:C_ch5$ echo "operators and &, or |, exclusive or ^, left-shift <<, rigt-shift >>, 1s complement ~" operators and &, or |, exclusive or ^, left-shift <<, rigt-shift >>, 1s complement ~ mweeks@air:C_ch5$ echo " 0110 shift right we get 0011" 0110 shift right we get 0011 mweeks@air:C_ch5$ echo " 0110 shift left we get 1100" 0110 shift left we get 1100 mweeks@air:C_ch5$ exit exit Script done on Mon Sep 30 13:45:37 2024