练习题
1.
(a) 1 2
(b) 0
(c) 1
(d) 0
2.
C89中不一样,C99中一样,原因见书P41中 -9 / 7 的例子
3.
不考虑C89了,直接看C99
4.
(a) 1
(b) -1
(c) -1
(d) 1
5.
不考虑C89了,直接看C99
6.
(a) 3
(b) -3
(c) 3
(d) -3
7.
8.
9.
(a) 63 8
(b) 3 2 1
(c) 2 -1 3
(d) 0 0 0
10.
(a) 12 12
(b) 3 4
(c) 2 8
(d) 6 9
11.
(a) 0 2
(b) 4 11 6
(c) 0 8 7
(d) 3 4 5 4
12.
(a) 6 16
(b) 6 -7
(c) 6 23
(d) 6 15
13.
++i
14.
(a) ((a * b) - (c * d)) + e
(b) ((a / b) % c) / d
(c) (((-a) - b) + c) - (+d)
(d) ((a * (-b)) / c) - d
15.
(a) 3 2
(b) 0 2
(c) 1 2
(d) 1 3
编程题
1.
#include<stdio.h>
int main(void)
{
int number;
printf("Enter a two-digit number: ");
scanf_s("%d", &number);
printf("The reversal is: %d%d", number % 10, number / 10);
return 0;
}
2.
#include<stdio.h>
int main(void)
{
int number;
int a, b, c;
printf("Enter a three-digit number: ");
scanf_s("%d", &number);
c = number % 10;
number /= 10;
b = number % 10;
number /= 10;
a = number % 10;
printf("The reversal is: %d%d%d", c, b, a);
return 0;
}
3.
#include<stdio.h>
int main(void)
{
int a, b, c;
printf("Enter a three-digit number: ");
scanf_s("%1d%1d%1d", &a, &b, &c);
printf("The reseral is: %d%d%d", c, b, a);
return 0;
}
4.
#include<stdio.h>
int main(void)
{
int number;
int a, b, c, d, e;
printf("Enter a number between 0 and 32767: ");
scanf_s("%d", &number);
e = number % 8;
number /= 8;
d = number % 8;
number /= 8;
c = number % 8;
number /= 8;
b = number % 8;
number /= 8;
a = number % 8;
printf("In octal, your number is: %d%d%d%d%d", a, b, c, d, e);
return 0;
}
5.
#include <stdio.h>
int main(void)
{
int d, i1, i2, i3, i4, i5, j1, j2, j3, j4, j5,
first_sum, second_sum, total;
printf("Enter the first 11 digit of a UPC: ");
scanf_s("%1d%1d%1d%1d%1d%1d%1d%1d%1d%1d%1d",
&d, &i1, &i2, &i3, &i4, &i5, &j1, &j2, &j3, &j4, &j5);
first_sum = d + i2 + i4 + j1 + j3 + j5;
second_sum = i1 + i3 + i5 + j2 + j4;
total = 3 * first_sum + second_sum;
printf("Check digit: %d\n", 9 - ((total - 1) % 10));
return 0;
}
6.
#include<stdio.h>
int main(void)
{
int a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12,
first_sum, second_sum, total;
printf("Enter the first 12 digits of an EAN: ");
scanf_s("%1d%1d%1d%1d%1d%1d%1d%1d%1d%1d%1d%1d",
&a1, &a2, &a3, &a4, &a5, &a6, &a7, &a8, &a9, &a10, &a11, &a12);
first_sum = a2 + a4 + a6 + a8 + a10 + a12;
second_sum = a1 + a3 + a5 + a7 + a9 + a11;
total = 3 * first_sum + second_sum;
printf("Check digit: %d", 9 - ((total - 1) % 10));
return 0;
}