# c programming book after school answers

### c language programming Tian Shuqing version of the post-course exercise answers

#include<stdio.h>

intmain(){

doublemark[4][3],aver[4],high[3]={0};

inti,j;

for(i=0;i<4;i++){

doubleall=0.0;

printf(“Please enter %c’s three grades:\n”,’A’+i);

for(j=0;j<3;j++){

scanf(“%lf”,& mark[i][j]);

high[j]=high[j]<mark[i][j]?mark[i][j]:high[j];

all+=mark[i][j];

}

printf(“The average grade of the students in %c is: %.2lf \n”,’A’+i,all/3);

}

printf(“The highest scores in the three subjects are: %.2lf%.2lf%.2lf%.2lf”,high[0],high[1],high[2]);

return0;

}

### C Programming for answers. Million thanks!

First question’s:

#include<stdio.h>

intmain()

{

charc;

scanf(“%c”,&c);

if(‘a'<=c&amp. &c<=’z’)

printf(“%c\n”,char(c-32));

elseif(‘A'<=c&&c<=’Z’)

printf(“%c\n”,char(c+32));

else

printf(“whatyouinputisnotaletter!”);

return0;

}

The second question’s:

#include<stdio.h>

intmain()< /p>

{intx,y;

printf(“Pleaseinputyournumberx:\n”);

scanf(“%d”,&x);

if(x>-1)

y=2*x;

elseif(x& lt;-1)

y=4+x;

elsey=3;

printf(“%d”,y);

return0;

}

Question 3:

#include<stdio.h>

intmain()

{

intn;

printf(“Pleaseinputaintegernumber:\n”);

scanf(“%d”,&n);

(n%2==0)? (printf(“%disEven\n”,n)):(printf(“%disOdd\n”,n));

return0;

}

Fourth question’s:

#include<stdio.h>

intmain()

{

floatx,y;

printf(“Please enter the employee’s performance amount (10,000 yuan):\n”);

scanf(“%f”,&x);

if(x<1)

y=1.03*x;

elseif(x>=1&&x<5)

y=1.1*x;

elseif(x>=5&&x<20)

y=1.5*x;

elsey=1.2*x;

printf(“The number of bonuses for this employee is %g million \n”,y);

return0;

}

### c language programming tan ho keung 4th edition chapter 3 after class questions answers

Chapter 3 Partial Answers

3.6 Write the result of running the following program.

main()

{charc1=’a’,c2=’b’,c3=’c’,c4= ‘\101′,c5=’\116’;

printf(“a%cb%c\tc%c\tabc\n”,c1,c2, c3);

printf(“\t\b%c%c%c”,c4,c5);

}

Solution:

aa securitiesbbb securities securitiescc securities securitiesabc

AㄩN

3.7 To decrypt ” China” into a cipher, the decoding rule is to replace the original letter with the fourth letter after the original letter. For example, the fourth letter after the letter “A” is “E”. E” instead of “A”. Therefore, “China” should be translated as “Glmre”. Write a program that assigns initial values to five variables, cl, c2, c3, c4, c5, so that the values of each variable are, respectively, ‘C’, ‘h’, ‘i’, ‘n’, ‘i’, ‘n’, ‘a’, and after arithmetic operations, so that c1, c2, c3, c4, c5 become, respectively, ‘G’, ‘l ‘, ‘m’, ‘r’, ‘e’ and output.

Solution:

#include<stdio.h>

main()

{charc1=’C’,c2=’h’,c3= ‘i’,c4=’n’,c5=’a’;

c1+=4;

c2+=4;

c3+=4;<

c4+=4;

c5+=4;

printf(“Password is %c%c%c%c%c%c\n”,c1,c2,c3,c4,c5);

}

Run the result:

Password is Glmre

3.9 Find the value of the following arithmetic expression.

(1) x+a%3*(int)(x+y)%2/4

Set x=2.5,a=7,y=4.7

(2)(float)(a+b)/2+(int)x%(int)y

Set a=2,b=3,x=3.5,y=2.5

(1) 2.5

(2) 3.5

3.10 Write the result of running the program.

main()

{inti,j,m,n;

i=8;

j=10;

m=++i;

n=j++;

printf(“%d,%d,%d,%d “,i,j,m,n);

}

Solution:

9,11,9,10

3.12 Write down the value of a after the operation of the following expression, setting the original a=12. Let both a and n have been defined as integer variables.

(1) a+=a (2) a-=2 (3) a*=2+3 (4) a/=a+a

(5) a%=(n%=2), the value of n is equal to 5

(6) a+=a-=a*=a

Solutions:

(1) 24 (2) 10 (3) 60 (4) 0 (5) 0 (6) 0