/* * w3_practice.c * * Created on: Dec 10, 2021 * Author: johnsontimoj */ /////////////////////////////////////// // // program to practice types, operators and type conversion // // inputs: user values // outputs: some calculated values // ////////////////////////////////////// // // un-comment one section at a time and run the program with // various inputs - predict the outcome before checking // // remember you can select a series of lines of code // and type ctrl / to comment or un-comment the selection // ////////////////////////////////////// #include #include // make uint8_t ... available int main(void){ setbuf(stdout, NULL); // creating some variables to use later int a; int b; int c; int d; int e; int f; float l; float m; float n; uint8_t aa; uint8_t bb; uint8_t cc; int8_t ee; int8_t ff; int8_t gg; // splash printf("Welcome to my w3 programming practice\n"); // infinite loop while(1){ // //////////////////////////////////// // // int practice - show shift and multiply by 2 are same // /////////////////////////////////// // printf(">> << practice\n"); // printf("Please enter two int values: "); // scanf("%i %i", &a, &b); // printf("You entered: %i, %i\n", a, b); // c = a << b; // printf("c using << is : %i\n", c); // printf("\n"); // c = a >> b; // printf("c using >> is : %i\n", c); // printf("\n"); // //////////////////////////////////// // //////////////////////////////////// // // int8_t practice - show wrapping // // note: scanf has poor support for reading in special types // // so we read in ints and typecast // /////////////////////////////////// // printf("int8_t practice\n"); // printf("Please enter two int values: "); // scanf("%i %i", &a, &b); // ee = (int8_t)a; // ff = (int8_t)b; // printf("You entered: %i, %i\n", ee, ff); // gg = ee + ff; // printf("gg using + is : %i\n", gg); // gg = ee - ff; // printf("gg using - is : %i\n", gg); // gg = ee * ff; // printf("gg using * is : %i\n", gg); // printf("\n"); // //////////////////////////////////// // //////////////////////////////////// // // uint8_t practice - show wrapping // // note: scanf has poor support for reading in special types // // so we read in ints and typecast // /////////////////////////////////// // printf("int8_t practice\n"); // printf("Please enter two int values: "); // scanf("%i %i", &a, &b); // aa = (uint8_t)a; // bb = (uint8_t)b; // printf("You entered: %i, %i\n", aa, bb); // cc = aa + bb; // printf("cc using + is : %i\n", cc); // cc = aa - bb; // printf("cc using - is : %i\n", cc); // cc = aa * bb; // printf("cc using * is : %i\n", cc); // printf("\n"); // //////////////////////////////////// // //////////////////////////////////// // // float practice - show error when trying to use modulo (%) // /////////////////////////////////// // printf("float % practice\n"); // printf("Please enter a pair of float values: "); // scanf("%f %f", &l, &m); // printf("You entered: %f, %f\n", l, m); // n = l % m; // printf("n is : %f\n", n); // printf("\n"); // /////////////////////////////////// // //////////////////////////////////// // // assignment type conversion // /////////////////////////////////// // printf("assignment type conversion practice\n"); // printf("Please enter a pair of int values: "); // scanf("%i %i", &a, &b); // printf("Please enter a pair of float values: "); // scanf("%f %f", &l, &m); // printf("You entered: %i, %i\n", a, b); // printf("You entered: %f, %f\n", l, m); // c = m = b = l = a; // n = b = m = a = l; // printf("a b c are : %i %i %i\n", a, b, c); // printf("l m n are : %f %f %f\n", l, m, n); // printf("\n"); // /////////////////////////////////// // //////////////////////////////////// // // complex statement practice // // modify the statements below to try different // // operations // /////////////////////////////////// // printf("complex statement practice\n"); // printf("Please enter 4 of int values: "); // scanf("%i %i %i %i", &a, &b, &c, &d); // printf("Please enter a pair of float values: "); // scanf("%f %f", &l, &m); // printf("You entered: %i, %i, %i, %i\n", a, b, c, d); // printf("You entered: %f, %f\n", l, m); // e = 0; // n = 0; // /////////// // // modify this to try some operations // //e = a++ - b / c % d; // //e = a++ + --b - ++c + d--; // //e = a << b % c || d; // //e = a | b >> c + d; // //n = (int)m / a + (int)(n / b); // printf("a b c d e are : %i %i %i %i %i\n", a, b, c, d, e); // printf("l m n are : %f %f %f\n", l, m, n); // printf("\n"); // /////////////////////////////////// }// end of while return 0; }// end main