chapter one
1.5 Please refer to the example in this chapter to write a C program and output the following information:
**************************
Very good!
**************************
Solution:
Encourage ()
{ printf(" * * * * * * * * * * * * * * * * * * * * * * *);
printf(" \ n ");
Printf ("Very good! \ n ");
printf(" \ n ");
printf(" * * * * * * * * * * * * * * * * * * * * * * *);
}
1.6 Write a program, input three values of A, B and C, and output the maximum value.
Solution:
Encourage ()
{int a,b,c,max
Printf ("Please enter three numbers A, B, C: \ n");
Scanf("%d, %d, %d ",& one, & c);
max = a;
if(max & lt; b)
max = b;
if(max & lt; c)
max = c;
Printf ("Maximum quantity is"% d ",max);
}
chapter three
3.6 Write the results of the following procedures.
Master ()
{char c 1='a ',c2='b ',c3='c ',c4='\ 10 1 ',C5 = ' \ 1 16 ';
printf("a%cb%c\tc%c\tabc\n ",c 1,c2,C3);
printf("\t\b%c %c ",c4,C5);
}
Solution:
aaㄩbbㄩㄩㄩccㄩㄩㄩㄩㄩㄩabc
AㄩN
3.7 Translate "China" into a password, and the decoding rule is: replace the original letter with the fourth letter after the original letter. For example, the fourth letter after the letter "A" is "E". "e" replaced "a" So "China" should be translated as "Glmre". Please write a program to make the values of five variables C 1, c2, c3, c4 and c5' c',' h',' i',' n' and' a' respectively by assigning initial values. After the operation, c 1, c2, c3, c4 and c5 will be' g' and' respectively.
Solution:
# include & ltstdio.h & gt
Master ()
{ char c 1='C ',c2='h ',c3='i ',c4='n ',c5 = ' a
c 1+= 4;
C2+= 4;
C3+= 4;
C4+= 4;
C5+= 4;
Printf ("password is% c% c% c% c \ n", C 1, C2, C3, C4, C5);
}
Running results:
The password is Glmre
3.9 Find the value of the following arithmetic expression.
( 1)x+a%3*(int)(x+y)%2/4
Let x = 2.5, a = 7 and y = 4.7.
(2)(float)(a+b)/2+(int)x%(int)y
Let a = 2, b = 3, x = 3.5, y = 2.5.
( 1)2.5
(2)3.5
3. 10 Write the result of the program running.
Master ()
{int i,j,m,n;
I = 8;
j = 10;
m = ++ I;
n = j++;
printf("%d,%d,%d,%d ",I,j,m,n);
}
Solution:
9, 1 1,9, 10
3. 12 Write the value of a after the following expression operation, so that the original a= 12. Let a and n be defined as integer variables.
( 1)a+= a(2)a-= 2(3)a * = 2+3(4)a/= a+a
(5) a%=(n%=2), and the value of n is equal to 5.
(6)a+=a-=a*=a
Solution:
( 1) 24 (2) 10 (3) 60 (4) 0 (5) 0 (6) 0
chapter four
4.4 If a=3, b=4, c=5, x= 1.2, y=2.4, z=-3.6, u=5 1274, n= 128765, C/kloc-.
a=_3_ _b=_4_ _c=_5
x= 1.200000,y=2.400000,z=-3.600000
x+y = _ 3.600 _ _ y+z =- 1.20 _ _ z+x =-2.40
c 1 =ˇaˇ_ or _ 97(ASCII)
c2=ˊbˊ_or_98(ASCII)
Master ()
{int a=3,b=4,c = 5;
long int u=5 1274,n = 128765;
float x= 1.2,y=2.4,z = 3.6
char c 1='a ',c2 = ' b
printf("a=%2d b=%2d c=%2d\n ",a,b,c);
printf("x=%f,y=%f,z=%f\n ",x,y,z);
printf(" x+y = % 5.2f y+z = % 5.2f z+x = % 5.2f \ n ",x+y,y+z,z+x);
printf("u=%6ld n=%9ld\n ",u,n);
Printf("%s %s %d%s\n ","c 1='a' ","or ",c 1," (ASCII)"); ");
Printf("%s %s %d%s\n ","c2='a' ","or ",c2," (ASCII)"); ");
}
4.7 Use the following function scanf to input data, so that a=3, b=7, x=8.5, y=7 1.82, C1= ˇˇˇˇˇˇˇˇˇˇˇˇˇˇGˇˇˇG711 How to enter data on the keyboard?
Master ()
{
int a,b; Floating point x, y; char c 1 C2;
Scanf("a=%d_b=%d ",& i, & b);
scanf("_x=%f_y=%e ",& ampx & amp; y);
scanf("_c 1=%c_c2=%c ",& ampc 1; C2);
}
a=3_b=7
_x=8.5_y=7 1.82
_c 1=A_c2=a
4.8 Let the radius of a circle r= 1.5 and the height of a cylinder h=3, and find the circumference, area, surface area, volume and volume of a sphere. Use scanf to input data and output calculation results. Text description is required when outputting, and two decimal places are taken. Please program.
Master ()
{float r,h,C 1,Sa,Sb,Va,Vb;
scanf("%f,%f ",& ampr & amp; h);
c 1 = 2 * 3. 14 * r;
sa = 3. 14 * r * r;
Sb = 4 * Sa
va = 4 * 3. 14 * r * r * r/3;
VB = Sa * h;
printf("C 1=%.2f\n ",c 1);
Printf(" Sa =%. 2f \ nSb =%. 2f \ A Nv =%.2f\nVb=%.2f\n ",Sa, Sb, Va, VB);
}
4.9 Input Fahrenheit temperature and output Celsius temperature. The formula is
c=5(F-32)/9
The output needs a text description with two decimal places.
Master ()
{float F,c;
scanf("%f ",& ampf);
c = 5 *(F-32)/9;
printf("c=%.2f ",c);
}
4. 10 programming, read two characters to c 1 and c2 with getchar function, and then output these two characters with function and function respectively. And consider the following questions: (1) should the variables c 1 and c2 be defined as character type or plastic type? Can you suppress both? (2) What about the ASCII code that needs to output c 1 and c2 values? Use putchar function or printf function? (3) Can plastic variables and character variables be substituted for each other under any circumstances? For example:
char c 1,C2;
and
int c 1,C2;
Is it unconditional equivalence?
# contains "stdio.h"
Master ()
{char c 1,C2;
c 1 = getchar(); C2 = getchar();
putchar(c 1); putchar(' \ n '); putchar(C2); putchar(' \ n ');
File://C |/Documents and Settings/Administrator/Desktop/C Language Programming Third Edition Tan Haoqiang After-class Exercise Answers Full Edition. Txt (page119) [2010-5-109:14:.
File://C |/Documents and Settings/Administrator/Desktop/C Language Programming Third Edition Tan Haoqiang After-class Exercise Answers Full Edition. Textfile (textfile)
1.5 Please refer to the example in this chapter to write a C program and output the following information:
**************************
Very good!
**************************
Solution:
Encourage ()
{ printf(" * * * * * * * * * * * * * * * * * * * * * * *);
printf(" \ n ");
Printf ("Very good! \ n ");
printf(" \ n ");
printf(" * * * * * * * * * * * * * * * * * * * * * * *);
}
1.6 Write a program, input three values of A, B and C, and output the maximum value.
Solution:
Encourage ()
{int a,b,c,max
Printf ("Please enter three numbers A, B, C: \ n");
Scanf("%d, %d, %d ",& one, & c);
max = a;
if(max & lt; b)
max = b;
if(max & lt; c)
max = c;
Printf ("Maximum quantity is"% d ",max);
}
chapter three
3.6 Write the results of the following procedures.
Master ()
{char c 1='a ',c2='b ',c3='c ',c4='\ 10 1 ',C5 = ' \ 1 16 ';
printf("a%cb%c\tc%c\tabc\n ",c 1,c2,C3);
printf("\t\b%c %c ",c4,C5);
}
Solution:
aaㄩbbㄩㄩㄩccㄩㄩㄩㄩㄩㄩabc
AㄩN
3.7 Translate "China" into a password, and the decoding rule is: replace the original letter with the fourth letter after the original letter. For example, the fourth letter after the letter "A" is "E". "e" replaced "a" So "China" should be translated as "Glmre". Please write a program to make the values of five variables C 1, c2, c3, c4 and c5' c',' h',' i',' n' and' a' respectively by assigning initial values. After the operation, c 1, c2, c3, c4 and c5 will be' g' and' respectively.
Solution:
# include & ltstdio.h & gt
Master ()
{ char c 1='C ',c2='h ',c3='i ',c4='n ',c5 = ' a
c 1+= 4;
C2+= 4;
C3+= 4;
C4+= 4;
C5+= 4;
Printf ("password is% c% c% c% c \ n", C 1, C2, C3, C4, C5);
}
Running results:
The password is Glmre
3.9 Find the value of the following arithmetic expression.
( 1)x+a%3*(int)(x+y)%2/4
Let x = 2.5, a = 7 and y = 4.7.
(2)(float)(a+b)/2+(int)x%(int)y
Let a = 2, b = 3, x = 3.5, y = 2.5.
( 1)2.5
(2)3.5
3. 10 Write the result of the program running.
Master ()
{int i,j,m,n;
I = 8;
j = 10;
m = ++ I;
n = j++;
printf("%d,%d,%d,%d ",I,j,m,n);
}
Solution:
9, 1 1,9, 10
3. 12 Write the value of a after the following expression operation, so that the original a= 12. Let a and n be defined as integer variables.
( 1)a+= a(2)a-= 2(3)a * = 2+3(4)a/= a+a
(5) a%=(n%=2), and the value of n is equal to 5.
(6)a+=a-=a*=a
Solution:
( 1) 24 (2) 10 (3) 60 (4) 0 (5) 0 (6) 0
chapter four
4.4 If a=3, b=4, c=5, x= 1.2, y=2.4, z=-3.6, u=5 1274, n= 128765, C/kloc-.
a=_3_ _b=_4_ _c=_5
x= 1.200000,y=2.400000,z=-3.600000
x+y = _ 3.600 _ _ y+z =- 1.20 _ _ z+x =-2.40
c 1 =ˇaˇ_ or _ 97(ASCII)
c2=ˊbˊ_or_98(ASCII)
Master ()
{int a=3,b=4,c = 5;
long int u=5 1274,n = 128765;
float x= 1.2,y=2.4,z = 3.6
char c 1='a ',c2 = ' b
printf("a=%2d b=%2d c=%2d\n ",a,b,c);
printf("x=%f,y=%f,z=%f\n ",x,y,z);
printf(" x+y = % 5.2f y+z = % 5.2f z+x = % 5.2f \ n ",x+y,y+z,z+x);
printf("u=%6ld n=%9ld\n ",u,n);
Printf("%s %s %d%s\n ","c 1='a' ","or ",c 1," (ASCII)"); ");
Printf("%s %s %d%s\n ","c2='a' ","or ",c2," (ASCII)"); ");
}
4.7 Use the following function scanf to input data, so that a=3, b=7, x=8.5, y=7 1.82, C1= ˇˇˇˇˇˇˇˇˇˇˇˇˇˇGˇˇˇG711 How to enter data on the keyboard?
Master ()
{
int a,b; Floating point x, y; char c 1 C2;
Scanf("a=%d_b=%d ",& i, & b);
scanf("_x=%f_y=%e ",& ampx & amp; y);
scanf("_c 1=%c_c2=%c ",& ampc 1; C2);
}
a=3_b=7
_x=8.5_y=7 1.82
_c 1=A_c2=a
4.8 Let the radius of a circle r= 1.5 and the height of a cylinder h=3, and find the circumference, area, surface area, volume and volume of a sphere. Use scanf to input data and output calculation results. Text description is required when outputting, and two decimal places are taken. Please program.
Master ()
{float r,h,C 1,Sa,Sb,Va,Vb;
scanf("%f,%f ",& ampr & amp; h);
c 1 = 2 * 3. 14 * r;
sa = 3. 14 * r * r;
Sb = 4 * Sa
va = 4 * 3. 14 * r * r * r/3;
VB = Sa * h;
printf("C 1=%.2f\n ",c 1);
Printf(" Sa =%. 2f \ nSb =%. 2f \ A Nv =%.2f\nVb=%.2f\n ",Sa, Sb, Va, VB);
}
4.9 Input Fahrenheit temperature and output Celsius temperature. The formula is
c=5(F-32)/9
The output needs a text description with two decimal places.
Master ()
{float F,c;
scanf("%f ",& ampf);
c = 5 *(F-32)/9;
printf("c=%.2f ",c);
}
4. 10 programming, read two characters to c 1 and c2 with getchar function, and then output these two characters with function and function respectively. And consider the following questions: (1) should the variables c 1 and c2 be defined as character type or plastic type? Can you suppress both? (2) What about the ASCII code that needs to output c 1 and c2 values? Use putchar function or printf function? (3) Can plastic variables and character variables be substituted for each other under any circumstances? For example:
char c 1,C2;
and
int c 1,C2;
Is it unconditional equivalence?
# contains "stdio.h"
Master ()
{char c 1,C2;
c 1 = getchar(); C2 = getchar();
putchar(c 1); putchar(' \ n '); putchar(C2); putchar(' \ n ');
Switch (position)
{Case 5: printf("%d, %d, %d, %d, %d ",ten _ thousand, thousand, hundred, ten, indiv);
Printf ("\ nThe reciprocal is;" );
Printf ("%d% d% d% d \ n", indiv, ten, bain, thousand, ten _ thousand);
Break;
Case 4: printf("%d, %d, %d, %d ",thousands, hundreds, tens, indiv);
Printf ("\ nThe reciprocal is:");
Printf ("%d% d% d \ n", indiv, ten, hundred, thousand);
Break;
Case 3: printf("%d, %d, %d ",100, 10, indiv);
Printf ("\ nThe reciprocal is:");
printf("%d%d%d\n ",indiv,ten,bain);
Break;
Case 2: printf("%d, %d ",ten, indiv);
Printf ("\ nThe reciprocal is:");
printf("%d%d\n ",indiv,ten);
Break;
case 1: printf("%d ",indiv);
Printf ("\ nThe reciprocal is:");
printf("%d\n ",indiv);
Break;
}
}
chapter five
5.8 Bonuses issued by enterprises should be based on profits. When the profit I is less than or equal to 6,543,800 yuan, the bonus of 654.38+ 00% can be deducted; The profit is higher than 654.38 million yuan and lower than 200,000 yuan (100000)