苏小鬟
[i=s] 本帖最后由 苏小鬟 于 201

本帖最后由 苏小鬟 于 2013-5-31 13:06 编辑

//(5。30更新)我先把位置占上慢慢写,肯定会把题答全的,现在先把第一题贴上

//因为平时上课就是用英文写的备注,所以我投稿的时候还是基本都用英文写的,见谅……

参与人ID(UID): 苏小鬟(311070)

参与类型: A 编程题目类

答案:

1. [mw_shl_code=c,true]#include <stdio.h>

#define MIN 1

#define MAX 1000

int main(void){

int i,j,sum;

printf("The perfect numbers between 1 and 1000 are: ");

for ( j = MIN; j< MAX; j++){

sum = 0;

for (i = MIN; i < j; i++){

if (j%i == 0){

sum += i;

if (sum == j){

printf("\t%d",j);

}

}

}

}

printf("\n");

return 0;

}[/mw_shl_code]

第二题:[mw_shl_code=c,true]#include <stdio.h>

int main(void){

double high = 100;//The atitude the ball is

double rebound = 0;//total rebound

int i;//counter

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

rebound += 1.5*high;

high *= 0.5;

}

printf("The total distance the ball went is %lf, it rebounds at 10 times %lf",rebound,high);

return 0;

}

~ [/mw_shl_code]

第六题 //不知道怎么优化空间,反正就按实现功能写了一下

[mw_shl_code=c,true]#include <stdio.h>

#define MAX 20

//prototypes

char*swap(char* str, int length);//a function that exchange the first elemrnt and the last

char* printout(char* str, int length);//printf the chars in array ^_^!

char*swap (char*str, int length){

char temp = 0;

char* first = str;

char* last = str+length-1;

while (last > first){

temp = *first;

*first = *last;

*last = temp;

first ++;

last --;

}

return str;

}

char* printout(char*str, int length){

int i = 0;//counter

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

printf("%c",str);

}

printf("\n");

}

int main(void){

char array1[MAX] = {"moc.00ng"};

printf("The original string is: ");

printout(array1,8);

swap(array1,8);

printf("The string has been swaped is: ");

printout(array1,8);

return 0;

}[/mw_shl_code]

第七题

[mw_shl_code=c,true]#include <stdio.h>

int main() {

long int i;

int bonus1,bonus2,bonus4,bonus6,bonus10,bonus;

printf("Plz inter the interst of this month: ");

scanf("%ld",&i);

bonus1=100000*0.1;bonus2=bonus1+100000*0.75;

bonus4=bonus2+200000*0.5;

bonus6=bonus4+200000*0.3;

bonus10=bonus6+400000*0.15;

if(i<=100000)

bonus=i*0.1;

else if(i<=200000)

bonus=bonus1+(i-100000)*0.075;

else if(i<=400000)

bonus=bonus2+(i-200000)*0.05;

else if(i<=600000)

bonus=bonus4+(i-400000)*0.03;

else if(i<=1000000)

bonus=bonus6+(i-600000)*0.015;

else

bonus=bonus10+(i-1000000)*0.01;

printf("bonus=%d\n",bonus);

return 0;

}

[/mw_shl_code]