Enter a number of integers (which can be positive, negative, or 0) to output the last 3 bits of their product. These integers are mixed with a string of uppercase letters, and your program should ignore them. Tip: Try to enter a string when executing scanf ("%d").
Problem Solving Ideas:
Find out the number multiplier in the string, note the end of the string in the calculation process and overflow the exception.
#include <stdio.h> #include <string.h> #include <ctype.h> int main () {
Char strarr[1000];
scanf ("%[^\n]s", Strarr);
int len = strlen (Strarr);
int i;
int flag = 1;
int sum = 1;
int ret = 1;
for (i = 0; i < len; i++) {flag = 1;
sum = 1;
while (!isdigit (Strarr[i]) && strarr[i]! = '-' && strarr[i]! = ' \ n ') {i++;
} if (strarr[i] = = '-') {flag =-flag;
} if (IsDigit (Strarr[i])) {sum = strarr[i]-' 0 ';
i++;
while (IsDigit (Strarr[i])) {sum%= 1000;
sum = sum * ten + strarr[i]-' 0 ';
i++;
}} RET = flag * Sum * ret% 1000;
} printf ("%d\n", ret);
return 0; }