8.1.c
#include <stdio.h>
int main(void) {
int ch;
int ct = 0;
while ((ch = getchar()) != EOF)
++ct;
printf("%d characters read\n", ct);
return 0;
}
8.2.c
#include <stdio.h>
int main(void) {
int ch, ct;
ct = 0;
while((ch = getchar()) != EOF) {
if(c...
(汇总)C Primer Plus 第6版 编程练习答案
C Primer Plus 第6版 电子书下载链接:https://down.bccn.net/10742.html
C Primer Plus 第6版 编程练习答案(第一章):https://blog.bccn.net/%E5%A4%8F%E5%A4%A9q/67573
C Primer Plus 第6版 编程练习答案(第二章):https://blog.bccn.net/%...
7.1.c
#include <stdio.h>
int main(void) {
char ch;
int sp_ct = 0;
int nl_ct = 0;
int other = 0;
while ((ch = getchar()) != '#') {
if (ch == ' ')
sp_ct++;
else if (ch == '\n')
nl_ct++;
else
other++;
}
printf("spaces: %d, newlines: %d, others: %d\n", sp_ct,...
6.1.c
#include <stdio.h>
int main(void)
{
char letter[26];
int i;
for(i = 0; i < 26; i++)
{
letter[i] = 'a' + i;
printf("%c ", letter[i]);
}
return 0;
}
6.2.c
#include <stdio.h>
int main(void)
{
int rows, chars;
for(rows = 0; rows < 5; rows++)
...
5.1.c
#include <stdio.h>
#define PER 60
int main(void) {
int minute, second, hour;
printf("Please enter minutes.\n");
scanf("%d", &minute);
while(minute > 0) {
hour = minute / PER;
second = minute % PER;
printf("%d minutes is %d hours and %d seconds.\n", minute...
4.1.c
#include <stdio.h>
int main(void) {
char first_name[20], last_name[20];
printf("Please enter your first name.\n");
scanf("%s", first_name);
printf("Please enter your last name.\n");
scanf("%s", last_name);
printf("%s,%s", first_name, last_name);
return 0;
}
...
3.1.c
#include <stdio.h>
int main(void) {
int int_max = 2147483647 ;
printf("%d %d\n",int_max,int_max+1);
float float_max = 3.40e38;
printf("%f %f\n",float_max,float_max+1);
float float_min = 3.40e-38;
printf("%f %f\n",float_min,float_min-1);
return 0;
}
...
2.1.c
#include <stdio.h>
int main(void) {
printf("Gustav Mahler\n");
printf("Gustav\nMahler\n");
printf("Gustav ");
printf("Mahler");
return 0;
}
2.2.c
#include <stdio.h>
int main(void) {
printf("name: Gustav Mahler\n");
printf("address: China\n")...
1.1.c
#include <stdio.h>
#define INCH_PER_CM 2.54
int main(void) {
double inch, cm;
printf("Enter an inch value:");
scanf("%lf", &inch);
cm = inch * INCH_PER_CM;
printf("The cm value is:%lf\n", cm);
return 0;
}