Question
1) Write a C program based on the output and given infor. Below: Part a) - keep on reading and processing input, until an integer
1) Write a C program based on the output and given infor. Below:
Part a) - keep on reading and processing input, until an integer -2000 is read.
- use scanf ("%d %c", ..) to read inputs.
- define a Boolean function isDigit(char c) to determine if c represents a digit. We mentioned in class that ANSI-C does not have a type `boolean, instead it uses 0 to represent false, and use non-zero integer to represent true. So, as a general practice in C, your function should return a non-zero number (usually 1) if c is a digit and returns 0 otherwise. Note that you should NOT use if c=='0' c=='1' c=='2' c=='3' c=='9'. Instead, use the one-statement trick that we discussed in class.
- Note that in getting the numerical value of a digit character such as '3', you should NOT use if c=='0' c=='1' c=='2' c=='3' c=='9'. Instead, use the one statement trick that we discussed in class.
- put the definition (implementation) of function isDigit after your main function. and display the prompt and output as shown below:
Enter an integer and a character separated by blank>10 d
Character d is not a digit
Enter an integer and a character separated by blank>20 5
Character '5' is a digit. Total of 20 and 5 is 25
Part b) Uses getchar and putchar to read from the Standard input, and outputs (duplicates) the characters to the Standard output.
- use getchar() and a loop to read characters.
- use putchar() to print the input characters on the standard output.
- do NOT use any other C library functions. Do your own checking and conversion. However, you should NOT use if c=='A' c=='B' c=='C' c=='D' c=='Z'. Instead, use the one-statement trick discussed in class.c
output:
What You Doing?
WHAT YOU DOING?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started