您的当前位置:首页正文

C++编程实例之欧阳学创编

来源:个人技术集锦
欧阳学创编

例3.13

时间:2021.03.03 创作:欧阳学 求Fibonacci数列前40个数。这个数列有如下特点:第1、2个数为1、1。从第3个数开始,每个数是其前面两个数之和。 #include #include using namespace std; int main( ) {

long f1,f2; int i; f1=f2=1;

for( i=1; i<=20; i++ ) {

//设备输出字段宽度为12,每次输出两个数

欧阳学创编

欧阳学创编

cout<//每输出完4个数后换行,使每行输出4个数 if(i%2==0) cout<f1=f1+f2; //左边的f1代表第3个数,是第f2=f2+f1; //左边的f2代表第4个数,是第}

return 0; }

例3.14

100~200间的素数 #include #include #include using namespace std; int main() {

欧阳学创编

1、2、2个数之和3个数之和 欧阳学创编

int m,k,i,n=0; bool prime;

for(m=101;m<=200;m=m+2) {

prime=true; k=int(sqrt(m));

for(i=2;i<=k;i++) if(m%i==0) {

prime =false; break; }

if(prime) {

cout <欧阳学创编

欧阳学创编

}

if(n%10==0) cout <cout <例3.15 译密码

#include using namespace std; int main() {char c;

while ((c=getchar())!='\\n') {

if((c>='a'&&c<='z')|| (c>='A'&&c<='Z')) {

欧阳学创编

欧阳学创编

c=c+4;

if(c>'Z'&&c<='Z'+4||c>'z') c=c-26; }

cout<cout<16、统计个数 #include using namespace std; int main () {char c;

int letters=0,space=0,digit=0,other=0;

欧阳学创编

欧阳学创编

cout<<\"enter one line::\"<if (c>='a' && c<='z'||c>='A' && c<='Z') letters++; else if (c==' ') space++;

else if (c>='0' && c<='9') digit++; else other++; }

cout<<\"letter:\"<digit:\"<17、求Sn=a+aa+aaa+……+aa…a(n个a)的值,n由键盘

欧阳学创编

space:\"<欧阳学创编

输入。

#include using namespace std; int main () {

int a,n,i=1,sn=0,tn=0; cout<<\"a,n=:\"; cin>>a>>n; while (i<=n) {

tn=tn+a; //赋值后的tn为i个a组成数的值 sn=sn+tn; //赋值后的sn为多项式前i项之和 a=a*10; ++i; }

cout<<\"a+aa+aaa+...=\"<欧阳学创编

欧阳学创编

return 0; }

18、.求1!+2!……+20!、 #include using namespace std; int main () {float s=0,t=1; int n;

for (n=1;n<=20;n++) {

t=t*n; // 求n!

s=s+t; // 将各项累加 }

cout<<\"1!+2!+...+20!=\"<欧阳学创编

欧阳学创编

19、求“水仙花数”例153=13+33+53 #include using namespace std; int main () {int i,j,k,n;

cout<<\"narcissus numbers are:\"<j=n/10-i*10; k=n%10;

if (n == i*i*i + j*j*j + k*k*k) cout<cout<欧阳学创编

欧阳学创编

}

20、找出1000之内所有的完数例如6的因子是1.2.3而6=1+2+3,所以6是完数 #include using namespace std; int main() {int m,s,i;

for (m=2;m<1000;m++) {s=0;

for (i=1;i{cout<if (m%i==0) cout<欧阳学创编

欧阳学创编

} } return 0; }

21、2/1, 3/2, 5/3, 8/5, 13/8, 21/13,…前20项之和 #include using namespace std; int main() {int i,t,n=20;

double a=2,b=1,s=0; for (i=1;i<=n;i++) {s=s+a/b; t=a;

a=a+b; // 将前一项分子与分母之和作为下一项的分子

b=t; // 将前一项的分子作为下一项的分母 }

欧阳学创编

欧阳学创编

cout<<\"sum=\"<24、输出图形 #include using namespace std; int main() {int i,k;

for (i=0;i<=3;i++) // 输出上面4行*号 {for (k=0;k<=2*i;k++)

cout<<\"*\"; // 输出*号

cout<for (i=0;i<=2;i++) // 输出下面3行*号 {for (k=0;k<=4-2*i;k++) cout<<\"*\"; // 输出*号

欧阳学创编

欧阳学创编

cout<1、求最大公约数和最小公倍数,用主函数条用两个函数 #include using namespace std; int main() {

int hcf(int,int); int lcd(int,int,int); int u,v,h,l; cin>>u>>v; h=hcf(u,v);

cout<<\"H.C.F=\"<欧阳学创编

欧阳学创编

l=lcd(u,v,h);

cout<<\"L.C.D=\"<int hcf(int u,int v) { int t,r; if (v>u)

{t=u;u=v;v=t;} while ((r=u%v)!=0) {u=v; v=r;} return(v); }

int lcd(int u,int v,int h) {return(u*v/h);

欧阳学创编

欧阳学创编

}

3、判别素数的函数 #include using namespace std; int main() {

int prime(int); /* 函数原型声明 */ int n;

cout<<\"input an integer:\"; cin>>n; if (prime(n))

cout<cout<欧阳学创编

欧阳学创编

int prime(int n) {

int flag=1,i;

for (i=2;i4、.求a!+b!+c!的值,用一个函数fac(n)求n!。#include using namespace std; int main()

{int fac(int); int a,b,c,sum=0; cout<<\"enter a,b,c:\"; cin>>a>>b>>c;

欧阳学创编

4 欧阳学创编

sum=sum+fac(a)+fac(b)+fac(c);

cout<int fac(int n) { int f=1;

for (int i=1;i<=n;i++) f=f*i; return f; }

7、.验证哥德巴赫猜想:一个不小于6的偶数可以表示为两个素数之和。7 #include #include using namespace std; int main()

欧阳学创编

欧阳学创编

{void godbaha(int); int n;

cout<<\"input n:\"; cin>>n; godbaha(n); return 0; }

void godbaha(int n) {int prime(int); int a,b;

for(a=3;a<=n/2;a=a+2) {if(prime(a)) {b=n-a; if (prime(b))

cout<欧阳学创编

欧阳学创编

}

int prime(int m) {int i,k=sqrt(m); for(i=2;i<=k;i++) if(m%i==0) break; if (i>k) return 1; else return 0; }

11、用递归方法求f(n)=12+22+……+n2 #include using namespace std; int main() {

int f(int); int n,s;

cout<<\"input the number n:\";

欧阳学创编

欧阳学创编

cin>>n; s=f(n);

cout<<\"The result is \"<int f(int n) {

if (n==1) return 1; else

return (n*n+f(n-1)); }

例5.2 用数组Fibonacci数列 #include #include using namespace std;

欧阳学创编

欧阳学创编

int main () {int i;

int f[20]={1,1}; for(i=2;i<20;i++) f[i]=f[i-2]+f[i-1]; for(i=0;i<20;i++)

{if(i%5==0)cout<cout<例5.3用冒泡法对10个数排序 #include using namespace std; int main( )

欧阳学创编

欧阳学创编

{

int a[10]; int i,j,t;

cout<<\"input 10 numbers :\"<for (i=0;i<10;i++) //输入a[0]~a[9]

cin>>a[i]; cout<for (j=0;j<9;j++) //共进行9趟比较

for(i=0;i<9-j;i++) //在每趟中要进行(10-j)次两两比较

if (a[i]>a[i+1]) //如果前面的数大于后面的数 {t=a[i];a[i]=a[i+1];a[i+1]=t;} //交换两个数的位置,使小数上浮

cout<<\"the sorted numbers :\"<for(i=0;i<10;i++) //输出10个数 cout<欧阳学创编

欧阳学创编

return 0;

}例5.4将二维数组行列元素互换,存到另一个数组中 a=1 2 3 5 6 b=1 4 2 5 3 6

#include using namespace std; int main()

{ int a[2][3]={{1,2,3},{4,5,6}}; int b[3][2],i,j;

cout<<\"array a:\"<欧阳学创编

欧阳学创编

}

cout<cout<<\"array b:“<例5.5求 3×4 二维数组中最大元素值及其行列号 #include using namespace std; int main() {

欧阳学创编

欧阳学创编

int i,j,row=0,colum=0,max;

int a[3][4]={{5,12,23,56},{19,28,37,46},{-12,-34,6,8}}; max=a[0][0]; //使max开始时取a[0][0]的值

for(i=0;i<=2;i++) //从第0行~第2行 for(j=0;j<=3;j++) //从第0列~第3列 if(a[i][j]>max) //如果某元素大于max { max=a[i][j]; //max将取该元素的值 row=i; //记下该元素的行号i colum=j; //记下该元素的列号j }

cout<<\"max=

\"<\

\ return 0; }

例5.7用选择法对数组中10个整数按由小到大排序 #include

欧阳学创编

欧阳学创编

using namespace std; int main( ) {

void select_sort(int array[],int n); //函数声明 int a[10],i;

cout<<\"enter the originl array:\"<for(i=0;i<10;i++) //输入10个数 cin>>a[i]; cout<select_sort( a ,10); //函数调用,数组名作实参

cout<<\"the sorted array:\"<for(i=0;i<10;i++) //输出10个已排好序的数

cout<欧阳学创编

欧阳学创编

}

void select_sort(int array[],int n) //形参array是数组名 {

int i,j,k,t;

for(i=0;ifor(j=i+1;jt=array[k];array[k]=array[i];array[i]=t; } } 习题:

6、打印出杨辉三角(要求打印出10行) #include #include

欧阳学创编

欧阳学创编

using namespace std; int main() {const int n=11; int i,j,a[n][n]; for (i=1;ifor (i=3;ia[i][j]=a[i-1][j-1]+a[i-1][j]; for (i=1;icout<欧阳学创编

欧阳学创编

cout<C语言部分

1. 编程计算1, 1+2, 1+2+3, …, 1+2+3+…+n各项值的积 答案:

#include using namespace std; void main() {

int i,n,mul=1,sum=0; cout<<\"Please input n:\"; cin>>n;

for (i=1;i<=n;i++) {

sum+=i;

欧阳学创编

欧阳学创编

mul*=sum; }

cout<<\"The multiple is:\"<2. 编写重载函数Max可分别求取两个整数,三个字符,两个浮点型数,三个双精度数的最大值。 答案:

int max(int i,int j) { if (i>j) return i; else return j; }

char max(char c1,char c2,char c3) { char ch;

欧阳学创编

欧阳学创编

if (c1>c2) ch=c1; else ch=c2; if (c3>ch) ch=c3; return ch; }

float max(float x,float y) { if (x>y) return x; else return y; }

double max(double x1,double x2,double x3)

欧阳学创编

欧阳学创编

{

double y; if (x1>x2) y=x1; else y=x2; if (x3>y) y=x3; return y; }

3.请编写一个函数int find(char s[],char t[]),该函数在字符串s中查找字符串t,如果找到,则返回字符串t在字符串s中的位置(整数值);

否则返回-1。注意:用数组方式及两重循环来实现该函数。 答案:

int find(char s[],char t[])

欧阳学创编

欧阳学创编

{

int i,j,slen,tlen; slen=strlen(s); tlen=strlen(t); i=0;j=0;

while (iif (s[i]==t[j]) { i++; j++; } else { i=i-j+1; j=0;

欧阳学创编

欧阳学创编

} }

if (j>=tlen) return i-tlen+1; else return -1; }

4.写一程序,将字符串a的所有字符传送到字符串b中,要求每传送3个字符后放一个空格,例如,字符串a为”abcdefg”,则b为”abc deg g”。 答案:

#include #include #define N 40

void fun(char s[],char t[]) {

int i=0,j=0;

欧阳学创编

欧阳学创编

while(s[i]) {

t[j]=s[i]; i++; j++;

if ((i)%3==0) { t[j]=' '; j++; } } t[j]='\\0'; } main() {

char a[N],b[N];欧阳学创编

欧阳学创编

printf(\"请输入原始字符串a: \"); gets(a); fun(a,b);

printf(\"加入空格后的字符串b: \"); puts(b); }

5. 编程判断一个数是否为素数。 答案:

#include #include using namespace std; int prime(int m) {

int i,flag=1;

for (i=2;i<=int(sqrt(m));i++) if (m%i==0)

欧阳学创编

欧阳学创编

{flag=0;break; } return flag; }

int main(void) { int n;

cout<<\"请输入一个整数:\"; cin>>n; if (prime(n))

cout<cout<6.编程打印九九乘法表: 1×1=1

欧阳学创编

欧阳学创编

1×2=2 2×2=4

1×3=3 2×3=6 3×3=9 …. 答案:

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

for (i=1;i<=9;i++) {

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

printf(\"%1d*%1d=%2d \ printf(\"\\n\"); } }

欧阳学创编

欧阳学创编

7.请编写一个程序,程序的功能是打印以下图案。 * *** ***** ******* ***** *** * 答案:

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

for (i=1;i<=4;i++) {

欧阳学创编

欧阳学创编

for (j=1;j<=4-i;j++) cout<<' ';

for (j=1;j<=2*i-1;j++) cout<<'*'; cout<for (i=3;i>=1;i--) {

for (j=1;j<=4-i;j++) cout<<' ';

for (j=1;j<=2*i-1;j++) cout<<'*'; cout<8. 写出下面程序的运行结果:

欧阳学创编

欧阳学创编

#include void average(float*p, int n) { int i;

float sum=0;

for(i=0;ivoid main() {

float score[2][2]={ {1,2},{3,4} }; average(*score, 4); } 答案: 2.5

欧阳学创编

欧阳学创编

C++部分

1.定义一个满足如下要求的Date类。 (1)用下面的格式输出日期:日/月/年 (2)可运行在日期上加一天操作; (3)设置日期。 答案:

#include using namespace std; extern int i = 0; class Date { public:

set(int y,int m, int d); add(); print(); private:

欧阳学创编

欧阳学创编

int year; int month; int day; };

Date::set(int y, int m, int d) {

year = y; month = m; day = d; }

Date::add() {

switch(month) { case 1: case 3:

欧阳学创编

欧阳学创编

case 5: case 7: case 8:

case 10: if(day < 31) day += 1; else if(day == 31) {

day = 1; month += 1; }

break;

case 12: if(day < 31) day += 1; else if(day == 31) {

day = 1;

欧阳学创编

欧阳学创编

month = 1; year += 1; }

break; case 4: case 6: case 9:

case 11: if(day < 30) day += 1;

else if(day == 30) {

day = 1; month += 1; } break;

case 2: if(year % 4 == 0 && year % 100 != 0 || year % 400 == 0)

欧阳学创编

欧阳学创编

{

if(day < 29) day += 1;

else if(day == 29) {

day = 1; month+= 1; } } else {

if(day < 28) day += 1;

else if(day == 28) { day = 1;

欧阳学创编

欧阳学创编

month += 1; } } break; } }

Date::print() {

cout << day << \"/\" << month << \"/\" << year << endl; }

void main() {

Date d1; int year; int month; int day;

欧阳学创编

欧阳学创编

cout << \"请输入年月日:\"; cin >> year >> month >> day; d1.set(year, month, day); d1.print(); d1.add();

cout << \"下一天是:\" ; d1.print(); }

2.定义一个时间类Time,能提供和设置由时、分、秒组成的时间,并编出应用程序,定义时间对象,设置时间,输出该对象提供的时间。 答案: //Time.h class Time { public: Time();

欧阳学创编

欧阳学创编

~Time();

bool SetTime(int h,int m,int s); void GetTime(int &h,int &m,int &s); void Print(); private:

int iHour,iMinute,iSecond; };

/***********************************/ //Time.cpp

#include #include \"Time.h\" using namespace std; Time::Time() {

iHour=1;iMinute=1;iSecond=1; }

欧阳学创编

欧阳学创编

Time::~Time(){}

bool Time::SetTime(int h,int m,int s) {

if((h<0)||(h>23)) return false; if((m<0)||(m>59)) return false; if((s<0)||(s>59)) return false;

iHour =h;iMinute= m;iSecond =s;return true; }

void Time::GetTime(int &h,int &m,int &s) {

h=iHour;m=iMinute;s=iSecond; }

void Time::Print() {

cout<欧阳学创编

欧阳学创编

/**********************************/ //mainfunction.cpp #include #include \"Time.h\" using namespace std; void main() { Time t;

t.SetTime(23,44,59); t.Print(); }

3. 编写一个矩形的类,要求类中具有长和宽2个数据成员,具有构造函数、计算矩形的面积即及周长这3个成员函数。 答案:

class rectangle {

欧阳学创编

欧阳学创编

float width; float heigth; public:

rectangle(float w, float h) {width=w;heigth=h;}

float area(){return width*heigth;}

float circulm(){return 2*(width+heigth);} };

4. 设计一个人的类,要求包含姓名、身份证号、年龄、以及人的总数和所有人的平均年龄这5个数据成员,然后编写一个测试程序,输入n个人的

信息(姓名、身份证号和年龄),要求输出这些人的信息和平均年龄。 答案:

#include #include using namespace std;

欧阳学创编

欧阳学创编

const int n=3; class Person {

private:

char name[20]; char id[18]; int age; public:

static int count; //人数 static float aveage; Person(void){}

Person(const char* names,char *ids,int ages) {

strcpy(name,names);//初始化姓名 strcpy(id,ids);

age = ages;//初始化年龄

欧阳学创编

欧阳学创编

aveage+=age; count++; }

void display() {

cout<<\"姓名:\"<friend void ModifyAveage();//修改平均年龄的友元函数 };

int Person::count = 0; float Person::aveage=0; void ModifyAveage() {

Person::aveage=Person::aveage/Person::count;

欧阳学创编

欧阳学创编

}

void main() {

int ages,i;

char namestr[20],idstr[18]; Person per[n]; for (i=0;icout<<\"请输入姓名:\"; cin>>namestr;

cout<<\"请输入身份证号码:\"; cin>>idstr;

cout<<\"请输入的年龄:\"; cin>>ages;

Person temp(namestr,idstr,ages); per[i]=temp;

欧阳学创编

欧阳学创编

}

ModifyAveage(); for (i=0;icout<<\"人的数量:\"<5. 编写一个圆的类,再使用派生类的机制,编写一个圆柱的类,求每个类都包含具有初始化功能的构造函数和相关数据的输出函数。 答案:

#include #define pi 3.1416 using namespace std; class circle {

protected:

欧阳学创编

欧阳学创编

float r; float area; public:

circle() {r=0;}

circle(float radius){r=radius;} void print() {

area=r*r*pi;

cout<<\"r=\"<class column:circle {

protected: float h; float v;

欧阳学创编

欧阳学创编

public :

column(float radius,float height):circle(radius) {h=height;} void print() {

circle::print();

cout<<\"h=\"<void main() {

column col (3.0,2.0); col.print(); }

6.重载一个函数模板,要求它可以返回两个值中的较大者,也可以求三个数的最大值。 答案:

欧阳学创编

欧阳学创编

// 求两个任意类型值中的最大者 template

inline T const& max (T const& a, T const& b) {

return a < b ? b : a; }

// 求3个任意类型值中的最大者 template

inline T const& max (T const& a, T const& b, T const& c) {

return ::max (::max(a,b), c); }

7.下面是整型安全数组类的一部分:试完善类的定义,使下段程序能够正常运行且不会出现内存泄漏。 #include class Array{ public:

欧阳学创编

欧阳学创编

Array(int x){ count=x;

p=new int[count]; }

int & operator [](int x){return *(p+x);} protected: int count; int *p; } 答案:

#include class Array{ public: Array(int x); Array(Array &);

欧阳学创编

欧阳学创编

~Array();

void SetAt(int pos, int value); int GetAt(int pos); protected: int count; int *p; };

Array::Array(int x) {

count=x;

p=new int[count]; }

Array::Array(Array &a){ int i;

count=a.count;

欧阳学创编

欧阳学创编

p=new int[count]; for (i=0;iArray::~Array() {

delete p; }

void Array::SetAt(int pos, int value) {

*(p+pos)=value; }

int Array::GetAt(int pos) {

return *(p+pos); }

欧阳学创编

欧阳学创编

8、编写类String 的构造函数、析构函数和赋值函数 已知类String 的原型为: class String { public:

String(const char *str = NULL); // 普通构造函数 String(const String &other); // 拷贝构造函数 ~ String(void); // 析构函数

String & operate =(const String &other); // 赋值函数 private:

char *m_data; // 用于保存字符串 };

请编写String 的上述4 个函数。 答案:

String::String(const char *str) {

欧阳学创编

欧阳学创编

cout<<\"构造函数被调用了\"<m_data=new char[1]; *m_data='\\0'; } else {

int length=strlen(str);

m_data=new char[length+1]; strcpy(m_data,str); } }

String::~String(void) {

delete m_data;

欧阳学创编

欧阳学创编

cout<<\"析构函数被调用了\"<String::String(const String &other) {

cout<<\"赋值构造函被调用了\"<String & String::operator =(const String &other) {

if(this==&other) {

return *this; }

delete []m_data;

欧阳学创编

欧阳学创编

int length=strlen(other.m_data); m_data=new char[length+1]; strcpy(m_data,other.m_data); return *this; };

9、写出下面程序的运行结果: #include class A { public:

A(){cout<<\"A\";} ~A(){cout<<\"A\";} };

void main() { A a[5];

欧阳学创编

欧阳学创编

} 答案:

AAAAAAAAAA

10、写出下面程序的运行结果: #include class A{ public:

virtual void show(){cout<<\"A\"<class D:public A{ public:

virtual void show(){cout<<\"D\"<void fun(A& a){a.show();} void main(){ D d;

欧阳学创编

欧阳学创编

fun(d); } 答案: D

1设计一个类string要求string类包括私有成员函数,char *str,在构造函数中初始化这个数据。写出它的两个构造函数(有参和拷贝),

析构函数,并能显示的声明和是调用构造函数(使用数组作为数据成员不给分) #include using namespace std; class String { private: char *str; int len; public:

欧阳学创编

欧阳学创编

void showstr() {

cout<<\"String:\"<String(char *p) {

len=strlen(p); if(len!=0)

{str=new char[len+1];strcpy(str,p); }

欧阳学创编

欧阳学创编

cout<<\"构造函数\"<~String() {

if(str!=NULL) {delete[]str; str=NULL; len=0;}

cout<<\"析构函数\"<String(const String &r) {

len=r.len; if(len!=0) {

str=new char[len+1];

欧阳学创编

欧阳学创编

strcpy(str,r.str); }

cout<<\"拷贝构造函数\"<void main() {

String s1(\"nihao\"); s1.showstr(); String s2=s1; s2.showstr(); }

2编写 一个求两个正整数m和n最大公约数的程序并测试程序。

#include void main() {

欧阳学创编

欧阳学创编

int m,n,t,r; cin>>m>>n; while (n!=0) { r=m%n; m=n; n=r; }

cout<<\"最大公约数是:\"<3编写一个求一个整形数组a[n]最大值所在下标的函数,并在主函数中调用该函数 1---------------------------- #include #define n 5

int max(int a[],int l) {

int i,k,m;

欧阳学创编

欧阳学创编

m=a[0];k=0; for(i=0;ivoid main() {

int a[n],i,M; for (i=0;i>a[i]; M=max(a,n); cout<4将fibnacial 序列1,1,2,3,5,a[n]中,并显示出相应的元素 #include #include

欧阳学创编

的前20项存放在……欧阳学创编

void main() {

int i,a[20]={1,1}; for (i=2;i<20;i++) a[i]=a[i-1]+a[i-2]; for (i=0;i<20;i++) {if(i%5==0) cout<cout<cout<5设计一个类person要求person类包括私有成员函数,char *Name,在构造函数中初始化这个数据。写出它的两个构造函数(一般参数和对

象的引用),析构函数,并能显示的声明和是调用构造函数(使用数组作为数据成员不给分)

欧阳学创编

欧阳学创编

#include using namespace std; class Person { private: char *Name; int len; public:

void showName() {

cout<<\"Person:\"<Person () { len=0;

Name=NULL;

欧阳学创编

欧阳学创编

}

Person (char *x) {

len=strlen(x); if(len!=0)

{Name=new char[len+1]; strcpy(Name,x); }

cout<<\"构造函数\"<~Person () {

if(Name!=NULL) {delete[]Name; Name=NULL; len=0;

欧阳学创编

欧阳学创编

}

cout<<\"析构函数\"<Person (Person &xm) {

len=xm.len; if(len!=0) {

Name=new char[len+1]; strcpy(Name,xm.Name); }

cout<<\"拷贝构造函数\"<void main() {

欧阳学创编

欧阳学创编

Person s1(\"Liming\"); s1.showName (); Person s2=s1; s2.showName(); }

6 输出100~200之间能被3整除,但不能被7整除的数及其个数。

#include #include void main() {

int i,j,count;int a[100]; count=0;

for(i=100,j=0;i<=200 && j<100;i++) if (i%3==0 && i%7!=0) { a[j]=i;

欧阳学创编

欧阳学创编

j++; count++; }

for (i=0;iif(i%6==0)cout<cout<cout<<”个数为:”<7 完成下列函数,实现将a[n]中的元素按逆序重新存放。 1---------------------------- #include #include #define N 5

欧阳学创编

欧阳学创编

void swap(int a[],int n) { int i,t;

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

int a[N],i; for(i=0;i>a[i]; swap(a,N); cout<欧阳学创编

欧阳学创编

2-------------------------- #include #include #define n 5 void main() {

int a[n],i,t; for(i=0;i>a[i];

for (i=0;i{t=a[i];a[i]=a[n-i-1];a[n-i-1]=t;} for (i=0;i时间:2021.03.03 创作:欧阳学 欧阳学创编

因篇幅问题不能全部显示,请点此查看更多更全内容