Question 8
Back to Exercise
What is the output of the following C program?
#include <ctype.h>
#include <stdio.h>
int main(void) {
const char *s = "c23 rocks!";
int digits = 0;
for (int i = 0; s[i]; i++) {
if (isdigit((unsigned char) s[i]))
digits++;
putchar(toupper((unsigned char) s[i]));
}
printf(" %d\n", digits);
return 0;
}
- A C23 ROCKS! 2 Correct
- B C23 ROCKS! 0
- C c23 rocks! 2
- D C ROCKS! 2
Correct Answer: Option A
toupper changes only lowercase letters; digits and punctuation pass through unchanged. Two characters are digits.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!