沈工大C语言程序设计复习题 联系客服

发布时间 : 星期日 文章沈工大C语言程序设计复习题更新完毕开始阅读6fb67a8f6529647d272852c7

#include“stdio.h”

char *link(char*p1,char*p2); void main() {

char str1[100],str2[100];

printf(“Please input the first string:\\n”); gets(str1);

printf(“nPlease input the second string:\\n”); gets(str2); link(str1,str2);

printf(“\\nThe linked result is:\\n”); puts(str1); }

char*link(char*p1,char*p2) { char*p; p=p1; while(*p1) pl++; while(*p2) { *p1=*p2;

- 9 -

P1++; P2++; } *p1=?\\0?; return(p); }

9.将一个整数字符串转换为一个整数,如“-1234”转换为-1234。(实验教程P98) 解:#include

#include int chnum(char*p); void main() {

char s[6]; int n; gets(s); if(*s==?-?) n= -chnum(s+1); printf(“%d\\n”,n); }

- 10 -

chnum(char*p) {

int num=0,k,len,j; len=strlen(p); for(;*p!=?\\0?;p++) { k=*p-?0?; j=(- -len); while(j-->0) k=k*10; num=num+k; }

Return(num); }

10.编写计算个人所得税的程序输入一个纳税人的个人月收入,计算应纳的个人所得税。(程序设计教程P65)

纳税是每个公民的义务。我国的个人所得税税率表如下表所示:

级数 1 2 3 - 11 -

应纳税金额(月收入-1600) 税率% 5 10 15 不超过500元 500元~2000元 2001~5000元

4 5 6 7 8 9 解:源程序清单如下: #include”stdio.h” void main() {

double salary,s,tax;

5001~20000元 20001~40000元 40001元~60000元 60001元~80000元 80001元~100000元 超过100000元 20 25 30 35 40 45 printf(“please input your salary one month:”); scanf(“%lf”,&salary); s=salary-1600; if(s<=500) tax=s*0.05; else if(s<=2000)

tax=(s-500)*0.1+500*0.05; else if(s<=5000)

tax=(s-2000)*0.15+1500*0.1+500*0.05; else if(s<=20000)

tax=(s-5000)*0.2+3000*0.15+1500*0.1+500*0.05; else if(s<=40000)

- 12 -