2017华南理工大学网络教育《高级语言程序设计C++》平时作业

更新时间:2023-09-16 23:40:01 阅读量: 高中教育 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

一、分析程序,写输出结果

1. #include201709

#include void main() {int m, k, i ;

for( m=1; m<=10; m+=2 ) { k = m/3;

for( i=2; i<=k; i++ )

if( m%i ) cout << m << \ } } 7 9

2. #include

void fun(); void main() {int i;

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

void fun() { static int a; int b=2; a += 2 ;

cout<< a+b <<'\\t'; }

4 6 8 10

3. #include

int fun(int n) { if(n==0) return 1; return 2*fun(n-1); }

void main() { int a=5;

cout<

32

4. #include

void main() { char *cp=\

for (int i=0 ; i<4; i++ ) cout<

Word ord rd d

二、.根据程序功能填空。

1. 程序把10个数存储到一维数组a中,并求该数组中最大值。

#include void main() { int max;

int a[10]={76,55,95,87,85,83,65,90,77,85};

int *p= a ; max=*p;

for( ; p< &a[10] ; p++) if( *p>max ) max= *p ; cout<<\}

2.下面程序的功能是输出1至100之间每位数字的乘积大于每位数的和的数。例如,45两位数字的乘积为4×5=20,和为4+5=9。

#include void main()

{ int n, k=1, s=0, m; for(n=1; n<=100; n++) { k=1; s=0;

1m=n ; }

while( 2m ) { k*=m; s+=m;

3m/=10 ; }

if(k>s) cout<

}

3.程序对输入的n求s = 1 + 1/23 + 1/33 + … + 1/n3 。 #include void main()

{double s; int i, n; cout<<\ s = 0;

for (i=1; i

4.函数create从键盘输入整数序列,以输入0为结束。按输入顺序建立单向链表并返回表头。

struct node{int data; node * next;};

node * create()

{

node *head, *p, *q; p = new node; head = p; cin>>p->data;

while( p->data != 0 ) {

q = p;

p = new node ; q->next = p; cin>>p->data; }

if (head == p) head = NULL;

else q->next = p ; if (head == NULL) delete p ; return head; }

5.以下程序求方程的全部整数解:

3x + 2y - 7z = 5 ( 0 ≤ x, y, z ≤ 100 )

#include void main() { int x, y, z ;

for( x=0; x<=100; x++ ) for( y=0; y<=100; y++ ) { if( ( z=3*x+2*y-5 ) % 7 )

break ;

//求出z的值

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

if( z<=100&&z>=0 ) //检查z的范围

cout << \ } }

三、程序设计

1. 编写函数输出以下形状的图形,其中构成图形的数字和输出的行数通过参数传送。

1 2 2 2 3 3 3 3 3 4 4 4 4 4 4 4

#include void main() {

int i,n;

for (i=0;i<5; i++){ for (n=0;n<2*i-1;n++){ cout<

cout<

2. 请编程序,输入两个正整数啊a和b(a

the factors of 6 : 2 3

the factors of 7 : no factor

the factors of 8 : 2 4

#include using namespace std; void printFactor(int i); void main() {

int numA,numB;

cout<<\Two Numbers:\

cin>>numA>>numB;

for (int i=numA;i<=numB;i++)

{

printFactor(i);

} }

void printFactor(int i) {

cout<<\FACTORS OF \ int *fact=new int(); int n=0;

for (int k=2;k

if (i%k==0) {

fact[n]=k; n++; } }

if (n==0)

{

cout<<\FACTOR\

} else {

for (int j=0;j

本文来源:https://www.bwwdw.com/article/ysoh.html

Top