欢迎来到天天文库
浏览记录
ID:60775420
大小:4.48 MB
页数:231页
时间:2020-12-17
《PTA程序设计答案.docx》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、PTA所有答案工业gc1601学习小组一、判断题二、选择题三、函数题4-3求m到n之和(10分)答案:intsum(intm,intn){ints=0,i;for(i=m;i<=n;i++)s+=i;returns;}4-34简单输出整数(10分)答案:voidPrintN(intN){inti;for(i=1;i<=N;i++)printf("%d",i);}4-36简单求和(10分)答案:intSum(intList[],intN){inti,s=0;for(i=0;i2、constintN){inti,s=1;if(N<0)return0;elseif(N==0)return1;else{for(i=1;i<=N;i++)s*=i;returns;}}4-43找两个数中最大者(10分)答案:intmax(inta,intb){intmax;if(a>=b)max=a;elsemax=b;returnmax;}4-44数字金字塔(15分)答案:voidpyramid(intn){inti,j,space;for(i=1;i<=n;i++){space=n-i;for(j=0;j3、tf("%-2d",i);printf("");}}4-45判断奇偶性(10分)答案:inteven(intn){if(n%2==0)return1;elsereturn0;}4-46使用函数求奇数和(15分)答案:inteven(intn){if(n%2==0)return1;elsereturn0;}intOddSum(intList[],intN){inti;intoddsum=0;for(i=0;i4、doublex1,doubley1,doublex2,doubley2){doubled;d=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));returnd;}4-48使用函数求素数和(20分)答案:intprime(intp){inti,j,count=0;for(j=2;j0&&p!=1)return1;elsereturn0;}intPrimeSum(intm,intn){inti,sum=0;for(i=m;i<=n;i++)if(prime(i)==1)sum=sum+i;r5、eturnsum;}4-20使用函数输出水仙花数(20分)答案:intnarcissistic(intnumber){inti,j,digit,power,powerSum,integer,count,flag;count=0;integer=number;while(integer>0){integer=integer/10;count++;}powerSum=0;integer=number;for(i=0;i6、git;powerSum=powerSum+power;}if(powerSum==number)flag=1;elseflag=0;returnflag;}voidPrintN(intm,intn){inti;for(i=m+1;ie){count++;if(count%2!=0)7、{cj=1;for(j=1;j<=i;j++)cj=cj*j;d=pow(x,i)/cj;sum=sum+d;i+=2;}else{cj=1;for(j=1;j<=i;j++)cj=cj*j;d=pow(x,i)/cj;sum=sum-d;i+=2;}}returnsum;}4-49分类统计字符个数(15分)答案:voidStringCount(chars[]){inti;intn1=0,n2=0,n3=0,
2、constintN){inti,s=1;if(N<0)return0;elseif(N==0)return1;else{for(i=1;i<=N;i++)s*=i;returns;}}4-43找两个数中最大者(10分)答案:intmax(inta,intb){intmax;if(a>=b)max=a;elsemax=b;returnmax;}4-44数字金字塔(15分)答案:voidpyramid(intn){inti,j,space;for(i=1;i<=n;i++){space=n-i;for(j=0;j3、tf("%-2d",i);printf("");}}4-45判断奇偶性(10分)答案:inteven(intn){if(n%2==0)return1;elsereturn0;}4-46使用函数求奇数和(15分)答案:inteven(intn){if(n%2==0)return1;elsereturn0;}intOddSum(intList[],intN){inti;intoddsum=0;for(i=0;i4、doublex1,doubley1,doublex2,doubley2){doubled;d=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));returnd;}4-48使用函数求素数和(20分)答案:intprime(intp){inti,j,count=0;for(j=2;j0&&p!=1)return1;elsereturn0;}intPrimeSum(intm,intn){inti,sum=0;for(i=m;i<=n;i++)if(prime(i)==1)sum=sum+i;r5、eturnsum;}4-20使用函数输出水仙花数(20分)答案:intnarcissistic(intnumber){inti,j,digit,power,powerSum,integer,count,flag;count=0;integer=number;while(integer>0){integer=integer/10;count++;}powerSum=0;integer=number;for(i=0;i6、git;powerSum=powerSum+power;}if(powerSum==number)flag=1;elseflag=0;returnflag;}voidPrintN(intm,intn){inti;for(i=m+1;ie){count++;if(count%2!=0)7、{cj=1;for(j=1;j<=i;j++)cj=cj*j;d=pow(x,i)/cj;sum=sum+d;i+=2;}else{cj=1;for(j=1;j<=i;j++)cj=cj*j;d=pow(x,i)/cj;sum=sum-d;i+=2;}}returnsum;}4-49分类统计字符个数(15分)答案:voidStringCount(chars[]){inti;intn1=0,n2=0,n3=0,
3、tf("%-2d",i);printf("");}}4-45判断奇偶性(10分)答案:inteven(intn){if(n%2==0)return1;elsereturn0;}4-46使用函数求奇数和(15分)答案:inteven(intn){if(n%2==0)return1;elsereturn0;}intOddSum(intList[],intN){inti;intoddsum=0;for(i=0;i4、doublex1,doubley1,doublex2,doubley2){doubled;d=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));returnd;}4-48使用函数求素数和(20分)答案:intprime(intp){inti,j,count=0;for(j=2;j0&&p!=1)return1;elsereturn0;}intPrimeSum(intm,intn){inti,sum=0;for(i=m;i<=n;i++)if(prime(i)==1)sum=sum+i;r5、eturnsum;}4-20使用函数输出水仙花数(20分)答案:intnarcissistic(intnumber){inti,j,digit,power,powerSum,integer,count,flag;count=0;integer=number;while(integer>0){integer=integer/10;count++;}powerSum=0;integer=number;for(i=0;i6、git;powerSum=powerSum+power;}if(powerSum==number)flag=1;elseflag=0;returnflag;}voidPrintN(intm,intn){inti;for(i=m+1;ie){count++;if(count%2!=0)7、{cj=1;for(j=1;j<=i;j++)cj=cj*j;d=pow(x,i)/cj;sum=sum+d;i+=2;}else{cj=1;for(j=1;j<=i;j++)cj=cj*j;d=pow(x,i)/cj;sum=sum-d;i+=2;}}returnsum;}4-49分类统计字符个数(15分)答案:voidStringCount(chars[]){inti;intn1=0,n2=0,n3=0,
4、doublex1,doubley1,doublex2,doubley2){doubled;d=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));returnd;}4-48使用函数求素数和(20分)答案:intprime(intp){inti,j,count=0;for(j=2;j
0&&p!=1)return1;elsereturn0;}intPrimeSum(intm,intn){inti,sum=0;for(i=m;i<=n;i++)if(prime(i)==1)sum=sum+i;r
5、eturnsum;}4-20使用函数输出水仙花数(20分)答案:intnarcissistic(intnumber){inti,j,digit,power,powerSum,integer,count,flag;count=0;integer=number;while(integer>0){integer=integer/10;count++;}powerSum=0;integer=number;for(i=0;i6、git;powerSum=powerSum+power;}if(powerSum==number)flag=1;elseflag=0;returnflag;}voidPrintN(intm,intn){inti;for(i=m+1;ie){count++;if(count%2!=0)7、{cj=1;for(j=1;j<=i;j++)cj=cj*j;d=pow(x,i)/cj;sum=sum+d;i+=2;}else{cj=1;for(j=1;j<=i;j++)cj=cj*j;d=pow(x,i)/cj;sum=sum-d;i+=2;}}returnsum;}4-49分类统计字符个数(15分)答案:voidStringCount(chars[]){inti;intn1=0,n2=0,n3=0,
6、git;powerSum=powerSum+power;}if(powerSum==number)flag=1;elseflag=0;returnflag;}voidPrintN(intm,intn){inti;for(i=m+1;ie){count++;if(count%2!=0)
7、{cj=1;for(j=1;j<=i;j++)cj=cj*j;d=pow(x,i)/cj;sum=sum+d;i+=2;}else{cj=1;for(j=1;j<=i;j++)cj=cj*j;d=pow(x,i)/cj;sum=sum-d;i+=2;}}returnsum;}4-49分类统计字符个数(15分)答案:voidStringCount(chars[]){inti;intn1=0,n2=0,n3=0,
此文档下载收益归作者所有