当前位置:首页 > 其他范文 > 专题范文 > 写出程序 分析程序写出结果
 

写出程序 分析程序写出结果

发布时间:2019-07-29 09:34:38 影响了:

五、阅读程序(26)

(一). 写出下列程序的输出结果是(5×2) 1.#include using namespace std; int main( ) { int i=1,sum=0; do {sum += i; i++;

}while(i

cout

______sum=5050____________________________ 2. #include using namespace std; int main( )

{ char str1[ ]=”I love china!”,str2[20],*p1,*p2; p1=str1;p2=str2;

for(;*p1!=‟\0‟;p1++,p2++) *p2=*p1; *p2=‟\0‟; p1=str1;p2=str2; cout

_______str1=”I love china!”_________________________

_________str2=”I love china!”_______________________

#include using namespace std; int main()

{char c1=’a ’,c2=’d ’,c3=’f ’; c1+=2; c2+=2; c3+=2;

cout

运行结果:cfh

2. 写出下列程序的输出结果。 #include using namespace std; int i,j,m,n; int main() { i=5; j=6; m=++i+j++; n=(++i)+(++j)+m;

cout

运行结果:7 8 12

3. 写出下列程序的输出结果。

#include using namespace std; int main() {const int n=5;

int a[n]={9,6,3,4,5},i,t;

for(i=0;i

27

{t=a[i];a[i]=a[n-i-1];a[n-i-1]=t;} for(i=0;icout

运行结果:5 4 3 6 9

1.struct abc

{ int a, b, c; }; main()

{ struct abc s[2]={{1,2,3},{4,5,6}}; int t;

cout

___________3_____________________ ____________6____________________ 2.

void swap(int *p1,int *p2) { int *p;

p=p1;p1=p2;p2=p; } main()

{ int a=3,b=5; int *pt1,*pt2; pt1=&a; pt2=&b;

cout

cout

___________3.5_____________________

______________3.5__________________

1、

#include int t() {

static int i=100; i+=5; return i; }

运行结果:

i=105 i=100

2、

#include void swap1(int *p1, int *p2) { int t;

t=*p1;*p1=*p2;*p2=t; }

void swap2(int &p1, int &p2) { int *t; t=p1;p1=p2;p2=t; }

void main(void) { int x,y; int a,b; x=10,y=20; swap1(&x,&y);; a=100,b=200;

void main() {

cout

swap2(a,b);

cout运行结果是: x=20,y=10

i=110

2、

#include void main(void ) {

int i, x,num; cin>>x; while(x){ num=x%10; cout

若输入x 为145734 则输出为:437541

cout

cout

sum=fun(r1,r2);

cout

a=100,b=200

1、#include int t() {

static int i=100; i+=5; return i; }

void main() {

cout

运行结果:i=105 3#include struct s{ int m;

float x; };

void swap(s s1, s s2) { s t; t=s1; s1=s2; s2=t; }

s fun(s s1, s s2) { s t;

t.m=s1.m+s2.m; t.x=s1.x+s2.x; return t; }

void main() {

s r1={100,250.5},r2={200,350.5}; swap(r1,r2);

执行程序后输出:

r1.m=100 r1.x=250.5 r2.m=200 r2.x= 350.5 sum.m=300 sum.x=601

4、#include “iostream.h” void main() {

static char a[]=”Radio&TV University”; static int b[8]={6,8,9,2}; char *p=a; int *q; q=b; cout

coutcout

执行程序后输出:a,R,T,d

0,10,8,8

1. #include using namespace std; int main() {

char c1=’A ’,c2=’D ’,c3=’k ’; c1+=2; c2+=3;

c3-=4;

cout

_________C_____G______g__________________________

2. #include using namespace std; int main() {

int i,j,m,n; i=361;

j=i/100;m=i%10;n=(i%100)/10;

if(i==j*j*j+m*m*m+n*n*n) cout

不是水仙花数___________________________

3 #include using namespace std; int main() {

const int n=9;

int a[n]={9,6,3,4,5,45,32,78,21},i,t; for(i=0;i

{t=a[i];a[i]=a[n-i-1];a[n-i-1]=t;} for(i=0;i

cout输出结果是:21 78 32 45 5 4 3 6 9

4有如下程序:

#include using namespace std; class A {

public: A( )

{ cout

};

class B { public: B( )

{ cout

};

class C : public A { B b;

public:

C( ) { cout

int main( ) { C obj;

return 0; }

执行后的输出结果是:ABC

5.#include using namespace std; void swap(int *p1,int *p2) { int *p;

p=p1;

p1=p2; p2=p; } main()

{ int a=3,b=5; int *pt1,*pt2;

pt1=&a; pt2=&b;

cout

cout

运行结果:3,5

3,5

6.#include #include using namespace std; int main( ) {

cout.fill("*"); cout.width(6); cout.fill("#"); cout

return 0; }

运行结果:###123

3.#include using namespace std; int age(int); int main( )

{ coutint age(int n) { int c; if(n= =1)

c=8;

else

c=age(n-1)+2; return (c); }

运行结果:12 4.#include using namespace std; int main( )

{ int a[5]={3,5,7,9,6};

int i,*p=a;

for(p=a;p

cout

cout

运行结果:

3 5 7 9

1、#include

using namespace std;

int main()

{ float add(float,float); float a=12.68,b=56.45; c=add(a,b);

cout

float add(float x,float y)

{ float z;

z=x+y;

return (z);

}

运行结果sum=69.13:

2、#include

using namespace std;

int age(int);

int main( )

{ coutreturn 0;

}

int age(int n)

{ int c;

if(n= =1) c=8;

else c=age(n-1)+2;

return (c);

}

运行结果:12

3、#include

using namespace std;

int main( )

{ int a[5]={3,5,7,9,6};

int i,*p=a;

for(p=a;p

cout

cout

}

运行结果:3 5 7 return 0; } void fun(int i, int j) { int x=7; cout

1.#include using namespace std;

int main( )

{

void fun(int,int);

int i=2,x=5,j=7;

fun(j,6);

cout

输出结果是:7 6 7 2 7 5

2. 当运行以下程序时,从键盘输入

a

pple

c

at ( 表示回车 )

#include

using namespace std;

int main()

{ char s[80],*p;

cin>>s;

p=s;

while(*(++p)!= „\0‟)

if (*p==‟a ‟) peak;

else {p++; cin>>p;}

cout

return 0;

}

________at________________________

猜你想看
相关文章

Copyright © 2008 - 2022 版权所有 职场范文网

工业和信息化部 备案号:沪ICP备18009755号-3