- 1、本文档共6页,可阅读全部内容。
- 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
C常考编程题
1.输入3个整数,由小到大顺序输出
#include iostream
#include string
using namespace std;
const int n=10;
string name[n];
int num[n],score[n];
int main()
{int i;
void input_data();
input_data();
coutendlThe list of failed:endl;
for(i=0;in;i++)
if(score[i]60)
coutname[i] num[i] score[i]endl;
return 0;
}
void input_data()
{int i;
for (i=0;in;i++)
{coutinput name,number and score of student i+1:;
cinname[i]num[i]score[i];}
}
2.输入3个字符串,由小到大顺序输出
#include iostream
#include cstring
using namespace std;
int main()
{void swap(char *,char *);
char str1[20],str2[20],str3[20];
coutinput three line:endl;
gets(str1);
gets(str2);
gets(str3);
if(strcmp(str1,str2)0) swap(str1,str2);
if(strcmp(str1,str3)0) swap(str1,str3);
if(strcmp(str2,str3)0) swap(str2,str3);
coutendlNow,the order is:endl;
coutstr1endlstr2endlstr3endl;
return 0;
}
void swap(char *p1,char *p2) /* 交换两个字符串 */
{char p[20];
strcpy(p,p1);strcpy(p1,p2);strcpy(p2,p);
}
3.输入4个整数,按由小到大的顺序输出
#include iostream
using namespace std;
int main ()
{int t,a,b,c,d;
coutenter four numbers:;
cinabcd;
couta=a, b=b, c=c,d=dendl;
if (ab)
{t=a;a=b;b=t;}
if (ac)
{t=a; a=c; c=t;}
if (ad)
{t=a; a=d; d=t;}
if (bc)
{t=b; b=c; c=t;}
if (bd)
{t=b; b=d; d=t;}
if (cd)
{t=c; c=d; d=t;}
coutthe sorted sequence:endl;
couta, b, c, dendl;
return 0;
}
找出10个数中之大的整数
#include iostream
using namespace std;
class Array_max
{public:
void set_value();
void max_value();
void show_value();
private:
int array[10];
int max;
};
void Array_max::set_value()
{int i;
for(i=0;i10;i++)
cinarray[i];
}
void Array_max::max_value()
{int i;
max=array[0];
for(i=1;i10;i++)
if(array[i]max)max=array[i];
}
void Array_max::show_value()
{coutmax=max;}
int main()
{Array_max arrmax;
arrmax.set_value();
arrmax.max_value();
arrmax.show_value();
retrun 0;
}
5.写一个判别素数的函数,在主函数中输入一个整数,输出是否为素数的信息。
#include iostream
using namespace std;
int main()
{int prime(int);
文档评论(0)