浙江省计算机二级c语言上机考试真题(三)程序编写
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
(三)程序编写
1,求3元方程解
设计程序:统计满足条件x*x+y*y+z*z==2000的所有解的个数,并将统计结果以格式"%d"输出。说明:若a、b、c是1个解,则a、c、b也是1个解,等等。*/
#include "stdio.h"
int main()
{
int x,y,z,k=0;
/*
* 考生在这里添加代码
*/
return 0;
}
∙#include
∙int main()
∙{
∙int x,y,z,k=0;
∙for(x=0;x<=50;x++)
∙ {
∙ for(y=0;y<=50;y++)
∙ {
∙ for(z=0;z<=50;z++)
∙ {
∙ if(x*x+y*y+z*z==2000)
∙ {k++;}
∙ }
∙ }
∙ }
∙printf("%d",k);
∙}
2,求距离和
设计程序:x[i],y[i]分别表示平面上一个点的坐标,求下列10个点与点(1.0,1.0)的距离
的总和,并将结果以格式"%.6f"输出。
#include
#include "math.h"
int main()
{
int i;
float x[10]={-1.5,2.1,6.3,3.2,-0.7,7.0,5.1,3.2,4.5,7.6};
float y[10]={3.5,7.6,8.1,4.5,6.0,1.1,1.2,2.1,3.3,4.4};
float s=0.0;
/*
* 考生在这里添加代码
*/
return 0;
}
∙#include
∙#include
∙int main()
∙{ int i;
∙ float x[10]={-1.5,2.1,6.3,3.2,-0.7,7.0,5.1,3.2,4.5,7.6};
∙ float y[10]={3.5,7.6,8.1,4.5,6.0,1.1,1.2,2.1,3.3,4.4};
∙ float s=0.000004;
∙ float sx,sy;
∙ for(i=0;i<10;i++)
∙ {
∙ sx=(x[i]-1.0)*(x[i]-1.0);
∙ sy=(y[i]-1.0)*(y[i]-1.0);
∙ s+=sqrt(sx+sy);
∙ }
∙ printf("%.6f",s);
∙ return 0;
∙}
3,字符权重
设计程序:在正整数中找出1个最小的、被3、5、7、9除余数分别为1、
3、5、7的数,将该数以格式"%d"输出。
#include "stdio.h"
#include "math.h"
int main()
int n=1,k=1;
/*考生在这里添加代码
*/
printf("%d\n",n);
return 0;
}
∙#include
∙#include
∙int main()
∙{int j=1;
∙ while(1)
∙ if(j%3==1&&j%5==3&&j%7==5&&j%9==7) ∙ {
∙ printf("%d\n",j+1);break;
∙ }
∙ else j++;
∙}
4,pow
设计程序:将满足条件pow(1.05,n)<1e6
值以格式"%d,%.0f"输出
#include "stdio.h"
#include "math.h"
int main()
{ float y=1.05; int n=1; FILE *p;
/*
* 考生在这里添加代码
*/
printf("%d,%.0f",n,pow(1.05,n));
return 0;
}
∙#include
∙#include
∙int main()
∙{ float y=1.05; int n=1,p;
∙ while((pow(y,n)<1e6))
∙ {
∙ n++;
∙ }
∙ n--;
∙ printf("%d,%.0f",n,pow(1.05,n));
∙ return 0;
∙}
5,sin多项式
设计程序:计算多项式
a0+a1*sin(x)+a2*sin(x*x)+a3*sin(x*x*x)+……+a9*sin(x*x*x*x*x*x*x*x*x)的值,并将其值
格式"%.6f"输出*/
#include "stdio.h"
#include "math.h"
void main()
{
int i; float x=2.345,t=1.0,y=0.0;
float a[10]={1.2,-1.4,-4.0,1.1,2.1,-1.1,3.0,-5.3,6.5,-0.9};
/*
* 考生在这里添加代码
*/
}
∙#include
∙#include
∙int main()
∙{ int i; float x=2.345,t=1.0,y=0.0;
∙ float a[10]={1.2,-1.4,-4.0,1.1,2.1,-1.1,3.0,-5.3,6.5,-0.9};
∙ y=y+a[0];
∙p=fopen("design.dat","w");
∙for(i=1;i<10;i++)
∙{ t=t*x;
∙y+=a[i]*sin(t);}
∙fprintf(p,"%.6f",y);
∙fclose(p);
∙}