问题 多项选择题

[说明]
假定用一个整型数组表示一个长整数,数组的每个元素存储长整数的一位数字,则实际的长整数m表示为:
m=a[k]×10k-2+a[k-1]×10k-3+…+a[3]×10+a[2]
其中a[1]保存该长整数的位数,a[0]保存该长整数的符号:0表示正数、1表示负数。
运算时先决定符号,再进行绝对值运算。对于绝对值相减情况,总是绝对值较大的减去绝对值较小的,以避免出现不够减情况。注意,不考虑溢出情况,即数组足够大。
[函数]
int cmp(int *LA, int *LB);
/*比较长整数LA与LB的绝对值大小*/
/*若LA绝对值较大返回正值,LA较小返回负值,相等则返回0*/
int ADD (int *LA, int *LB, int *LC)
/*计算长整数LA与LB的和,结果存储于LC中*/
/*注意:正数与负数的和相当于正数与负数绝对值的差*/
/*数据有误返回0,正常返回1*/

if(LA == NULL || LB == NULL || LC == NULL)return 0;
int *pA, *pB, i, N, carry, flag;
flag = LA[0] + LB[0];
switch(flag) /*根据参与运算的两个数的符号进行不同的操作*/
case 0:
case 2:
Lc[0] = LA[0];/*LA与LB同号,结果符号与LA(LB)相同*/
pA = LA;
pB = LB;
(1) ;
break;
case 1: /*LA与LB异号*/
/*比较两者的绝对值大小,结果符号与较大者相同*/
flag = (2) ;
if(flag > 0) /*LA较大*/
LC[0] = LA[0];
pA = LA;
pB = LB;

else if(flag < 0)(/*LB较大*/
LC[0] = LB[0];
pA = LB;
pB = LA;

else/*LA与LB相等*/
LC[0] = 0;
LC[1] = 0;
return 1;

flag = -1;
break;
default:
return 0;
break;
/*switch*/
/*绝对值相加减*/
/*注意对于减法pA指向较大数,pB指向较小数,不可能出现不够减情况*/
(3) ;
N = LA[1] > LB[1] LA[1] : LB[1];
for(i = 0; i < N; i++)
if(i >= pA[1])/*LA计算完毕*/
carry += flag * pB[i+2];

else if(i >= pB[1])/*LB计算完毕*/
carry += pA[i+2];

else
carry += pA[i+2] + flag * pB[i+2];

LC[i+2] = carry % 10;
carry /= 10;
if( (4) )/*需要借位,针对减法*/
LC[i+2] += 10;
carry--;

/*for*/
if( (5) )/*最高进位,针对加法*/
LC[i+2] = carry;
i++;

if(LC[i+1] == 0) i--; /*若最高位为零,针对减法*/
LC[1] = i;
return 1;
;/*ADD*/

答案

参考答案:cmp(LA,LB)

阅读理解

阅读理解。

      

       Peter has five dollars and he wants to buy a birthday present (礼物) for his sister, Mary. Mary will

be six years old next Saturday. Peter is in a toy shop now.    

       He looks at books, paints  and  soccers. However, he  doesn't think they are right presents for his

sister. He is ready to leave when a tall shop assistant stops him.

       "Can I help you?"the shop assistant asks.    

       "I'm looking for a present for my sister,"  Peter answers. "but I can't find anything nice. "    

       "There are some kites in the boxes, " the shop assistant says and points to some boxes in the

corner. "They are popular this season. Would you like to have a look at them?"    

       The kites are really great, and they cost only $ 41. 30. Peter thinks he finds the best present. He

buys a green kite with a fish on it. He knows it will make Mary happy.

1.Where does this story happen?    

A. In a school.  

B. In a kitchen.  

C. In a playground. 

D. In a shop.

2. How does Peter find the kite?    

A. It is in the window.              

B. A boy is flying one.     

C. A shop assistant shows it to him. 

D. He sees it near the balls.

3. What is on the green kite?

A. A dog.     

B. A fish.     

C. A soccer.  

D. A plane.

4. How much does Peter still have after he buys the kite?   

A. $4.30.    

B. $0.70.    

C. $5.00.    

D. $9.30.

5. Which is the best title for this story?    

A. Mary's birthday    

B. A toy shop    

C. A present          

D. A shop assistant

选择题