作业题答案

发布 2022-07-18 04:07:28 阅读 4543

一、填空题。

1.函数pi的功能是根据以下近似公式求π值:

请将下面函数的空白处填写正确,以完成求π的功能。

#include

using namespace std;

#include

double pi(long n)

double s=0.0;

long k;

for(k=1;k<=n;k++)

s=s+1.0/(k*k);

return(sqrt(6*s));

2.下列程序的输出结果是。

#include

using namespace std;

void f(int x,int y,int cp,int dp=8)

cp=x*x+y*y;

dp=x*x-y*y;

int main()

int a=4,b=3,c=5,d=6;

f(a,b,c);

cout<}

3.以下程序输出的最后一个值是。

#include

using namespace std;

int ff(int n)

static int f=1;

f=f*n;

return f;

int main()

int i;

for(i=1;i<=5;i++)

cout<}

4.以下函数的功能是:求x的y次方,请填空。

double fun(double x,int y)

int i;double z;

for(i=1,z=x;iz=z*x;

return z;

5.以下程序的输出结果是_246___

#include

using namespace std;

void fun()

static int a=0;

a+=2;cout<}

int main()

int cc;

for(cc=1;cc<4;cc++)

fun();

cout<}

6.下面程序的输出结果是_9___

#include

using namespace std;

long sum(int n)

long s;

if(n==1||n==2)

s=2;else

s=n+sum(n-1);

return s;

int main()

long x;

x=sum(4);

cout<}

7.以下程序的运行结果是。

#include

using namespace std;

void main()

int i=1,j=2,k=3;

cout<

cout<}

8.以下程序的运行结果是。

#include

using namespace std;

int main()

int x=5,y=10;

for(int k=1;k<=2;k++)

int m=0,n=0;

m++;x++;

n+=x+y;

cout<<”m=”<

9.以下程序的运行结果是_max=6___

/文件1:#include

using namespace std;

int a=5,b=6;//定义全局变量a、b

extern int max(int x,int y);

void main()

int c;

c=max(a,b);

cout<<”max=”<

/文件2:int max(int x,int y)

int z;

z=x>y?x:y;

return z;

static int a=8,b=7;//定义静态局部变量a、b

10.若下列程序运行时输出结果为。

1,a,10.1

2,b,3.5

请将程序补充完整。

#include

#include

using namespace std;

int main()

void test(int,char,double=3.5);

test(1,'a',10.1);

test(2,'b');

system("pause");

return 0;

void test(int a,char b,double c)

cout<11.在一个函数的定义或声明前加上关键字inline时,该函数就声明为内联函数。

二、编程题。

1.编写程序,要求在主函数中输入一个整数,利用自定义的函数prime()判断该整数是否为素数,若是素数,函数返回1,否则返回0。

#include

#include

using namespace std;

int prime(int n)

int i;

for(i=2;n%i;i++)

return (n==i);

int main()

int x;

cout<<"请输入x的值 ";cin>>x;

if(prime(x))

cout< else

cout

return 0;

2.编写程序分别求500到600之间能被7整除的数之和、800到900之间能被3整除的数之和。

提示:设计函数int fun(int a,int b,int n)求a到b之间能被n整除4 数之和。

#include

#include

using namespace std;

int fun(int a,int b,int n)

int sum=0,i;

for(i=a;i<=b;i++)

if(i%n==0)sum+=i;

return (sum);

int main()

cout< cout

return 0;

作业题答案

第一次 1 3章 作业 1 如何认识和正确处理资本主义两类不同性质的基本矛盾?对我国改革有何意义?资本主义的基本矛盾是生产资料的私人占有同社会化大生产的矛盾。但其发展也是不平衡的,在不同阶段 不同领域,矛盾的性质也不同。在垄断阶段或垄断领域,其矛盾是私有垄断与其社会化大生产的矛盾,垄断阻碍发展,其矛...

作业题答案

library ieee use entity mywork is port cl,clk0 in std logic out1 out std logic end mywork architecture rtl of mywork is signal q std logic beginproces...

作业题答案

2011 2012 1 5 ip 在eda技术的应用和发展中的意义是什么?答 ip是知识产权或知识产权模块的意思,在eda技术开发中具有十分重要的地位。它是用于asic或fpga中预先设计好的功能模块。当前ip核是为了易于重用而按嵌入式应用专门设计的。ip核按照 四最 目标进行优化的 芯片面积最小,...