Warm up: Variables, input, and casting
(1) Prompt the user to input an integer, a double, a character, and a string, storing each into separate variables. Then, output those four values on a single line separated by a space.
Note: This zyLab outputs a newline after each user-input prompt. For convenience in the examples below, the user's input value is shown on the next line, but such values don't actually appear as output when the program runs.
Enter integer: 99 Enter double: 3.77 Enter character: Z Enter string: Howdy 99 3.770000 z Howdy
(2) Extend to also output in reverse.
Enter integer: 99 Enter double:
3.77 Enter character: z Enter string: Howdy 99 3.770000 z Howdy Howdy z 3.770000 99
(3) Extend to cast the double to an integer, and output that integer.
Enter integer: 99 Enter double: 3.77 Enter character: Z Enter string: Howdy 99 3.770000 z Howdy Howdy z 3.770000 99 3.770000 cast to an integer is 3 LAB ACTIVITY 2.29.1: LAB: Warm up: Variables, input, and casting 0/5 main.c Load default template... 1 #include 2 3 int main(void) { 4 int user Int; double userDouble; // FIXME: Define char and string variables similarly printf("Enter integer: \n"); scanf("%d", &user Int); // FIXME
(1): Finish reading other items into variables, then output the four values on a single line separated by a space 19 11 12 13 14 15 16 17 18 // FIXME
(2): Output the four values in reverse // FIXME (3): Cast the double to an integer, and output that integer

Respuesta :

Answer:

#include <stdio.h>

int main()

{

   int userInt;

   double userDouble;

   char userChar;

   char userString[50];

   

   printf("Enter integer: \n");

   scanf("%d", &userInt);

   

   printf("Enter double: \n");

   scanf("%lf", &userDouble);

   

   printf("Enter character: \n");

   scanf(" %c", &userChar);

   

   printf("Enter string: \n");

   scanf("%s", userString);

   

   printf("%d %lf %c %s \n", userInt, userDouble, userChar, userString);

   printf("%d %lf %c %s %s %c %lf %d \n", userInt, userDouble, userChar, userString, userString, userChar, userDouble, userInt);

   printf("%d %lf %c %s %s %c %lf %d %lf cast to an integer is %d \n", userInt, userDouble, userChar, userString, userString, userChar, userDouble, userInt, userDouble, (int)userDouble);

   return 0;

}

Explanation:

In addition to int and double, declare the char and string

In addition to the int, ask the user to enter the double, char and string

Print the variables in the same order as they entered

In addition to entered order, also print the variables in reverse order - type the variables in reverse order

In addition to reverse order, print the casting value of the double as int - to cast a double to an int put (int) before the variable name