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).
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)
- Declare variables a, b, and c of type char.
- Use the getchar() function to read the input for each variable.
- 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:
- Use the putchar() function to display the value of each variable.
- 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.
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.