Knowee
Questions
Features
Study Tools

A C program contains the following statements:#include <stdio.h>char a, b , c;( a ) Write appropriate getchar statements that will allow values for a, b and c to be entered into the computer.(b) Write appropriate putchar statements that will allow the current values of a, b and c to be written out ofthe computer (i.e., to be displayed).

Question

A C program contains the following statements:#include <stdio.h>char a, b , c;( a ) Write appropriate getchar statements that will allow values for a, b and c to be entered into the computer.(b) Write appropriate putchar statements that will allow the current values of a, b and c to be written out ofthe computer (i.e., to be displayed).

🧐 Not the exact question you are looking for?Go ask a question

Solution

To allow values for variables a, b, and c to be entered into the computer, you can use the getchar() function. Here's how you can do it:

(a)

  1. Declare variables a, b, and c of type char.
  2. Use the getchar() function to read the input for each variable.
  3. Assign the input value to the respective variable.

Here's an example code snippet:

#include <stdio.h>

int main() {
    char a, b, c;

    printf("Enter value for a: ");
    a = getchar();

    printf("Enter value for b: ");
    b = getchar();

    printf("Enter value for c: ");
    c = getchar();

    // Rest of the code...

    return 0;
}

(b) To display the current values of variables a, b, and c, you can use the putchar() function. Here's how you can do it:

  1. Use the putchar() function to display the value of each variable.
  2. Pass the variable as an argument to the putchar() function.

Here's an example code snippet:

#include <stdio.h>

int main() {
    char a = 'A', b = 'B', c = 'C';

    putchar(a);
    putchar(b);
    putchar(c);

    // Rest of the code...

    return 0;
}

Note: In the above example, I have assigned initial values to variables a, b, and c for demonstration purposes. You can replace them with the actual values you want to display.

This problem has been solved

Similar Questions

Suppose that in a C program snippet, followings statements are used

What does the following statement in C signify?

Structure of a C Program:

What is the output of the following C Program?

Which of these loop statements exist in C?

1/4

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.