C语言程序编辑题库

上传人:油条 文档编号:2657525 上传时间:2017-07-26 格式:DOCX 页数:45 大小:49.02KB
返回 下载 相关 举报
C语言程序编辑题库_第1页
第1页 / 共45页
C语言程序编辑题库_第2页
第2页 / 共45页
C语言程序编辑题库_第3页
第3页 / 共45页
C语言程序编辑题库_第4页
第4页 / 共45页
C语言程序编辑题库_第5页
第5页 / 共45页
点击查看更多>>
资源描述

《C语言程序编辑题库》由会员分享,可在线阅读,更多相关《C语言程序编辑题库(45页珍藏版)》请在金锄头文库上搜索。

1、实验一 C+程序的运行环境和运行一个 C+程序的方法实验目的了解所用的计算机系统的基本操作方法,学会独立使用该系统。实验二 数据类型与表达式实验目的(1) 掌握 C+语言的数据类型,熟悉如何定义变量以及对它们赋值的方法。(2) 学会使用 C+有关算术运算符,以及包含这些运算符的表达式。(3) 进一步熟悉 C+程序的结构。(4) 进一步熟悉 C+程序的编辑、编译、连接和运行的过程。实验内容和步骤(1) 输入并运行下面的程序:#include using namespace std;int main()int a,b;char c1,c2;cinab;c1=+a;c2=b+;coutusing n

2、amespace std;int main()int i,j,m,n;i=8;j=10;m=+i+j+;n=(+i)+(+j)+m;cout#include using namespace std;int main() double a=123.456,b=3.14159,c=-3214.67; cout#include #include using namespace std;int main()double a,b,c;coutabc;if (a+bc & b+ca & c+ab)double s,area;s=(a+b+c)/2;area=sqrt(s*(s-a)*(s-b)*(s-c)

3、;cout#include using namespace std;int main ( )float h,r,l,s,sq,vq,vz;const float pi=3.1415926; coutrh;l=2*pi*r;s=r*r*pi;sq=4*pi*r*r;vq=3.0/4.0*pi*r*r*r;vz=pi*r*r*h;cout /输入一个正整数,判断它是否为素数。如不是,则输出其所有正约数。#include using namespace std;int main()int prime(int x);int i,j,k;couti;j=prime(i);if(j=0) coutusin

4、g namespace std;int main ()int p,r,n,m,temp;coutnm; if (nusing namespace std;int main ()int i,j,k,n;cout/验证哥德巴赫猜想#include using namespace std;int main()void godbaha(int);int n;coutn;godbaha(n);return 0;void godbaha(int n) int prime(int);int a,b;for(a=3;ak) return 1;else return 0;思考问题无参函数能否进行递归调用,为什么

5、?选做实验二 指针应用实验目的(14) 掌握指针的定义。(15) 掌握变量与指针的关系。(16) 掌握数组与指针的关系。实验准备要求:windows7/xp/2000/2003 操作系统,配置 vc+6.0/vs2008/vs2010 运行环境。 实验内容严格按要求完成下列题目:C+程序设计(第 2 版)P1921. 输入 3 个整数,按由小到大的顺序输出。具体要求:除主函数外,还要写两个函数,其中一个代表输入,另外一个使用指针变量作为函数参数;2. 输入 3 个字符串,按由小到大的顺序输出。具体要求:除主函数外,还要写两个函数,其中一个代表输入,另外一个使用指针变量作为函数参数;3. 输入

6、10 个整数,将其中最小的数与第 1 个数对换,把最大的数与最后一个数对换。写 3 个函数: 输入 10 个数; 进行处理; 1 2输出 10 个数。 3思考问题使用数组元素作为函数参数和使用指针作为函数参数的优缺点比较。参考代码(注:没有采用输入函数,而是直接使用 cin):第 1 题#include using namespace std;int main()void swap(int *p1,int *p2);int n1,n2,n3;int *p1,*p2,*p3;coutn1n2n3;p1=&n1;p2=&n2;p3=&n3;if(n1n2) swap(p1,p2);if(n1n3)

7、 swap(p1,p3);if(n2n3) swap(p2,p3);cout#include using namespace std;int main() void swap(char *,char *);char str120,str220,str320;cout0) swap(str1,str2);if(strcmp(str1,str3)0) swap(str1,str3);if(strcmp(str2,str3)0) swap(str2,str3);coutusing namespace std;int main() void input(int *number); void max_m

8、in_value(int *number); void output(int *number);int number10;input(number); / 调用输入 10 个数的函数 max_min_value(number); / 调用交换函数 output(number); / 调用输出函数 return 0;void input(int *number) / 输入 10 个数的函数 int i;coutnumberi;void max_min_value( int *number) / 交换函数 int *max,*min,*p,temp;max=min=number;for (p=nu

9、mber+1;p*max) max=p; / 将大数地址赋给 max else if (*pusing namespace std;int main()int length(char *p);int len;char str20;coutstr;len=length(str);coutusing namespace std;int main() void sort (char *p,int m);int i,n;char *p,num20;coutn;coutnumi;p=&num0;sort(p,n);coutusing namespace std;int main() char str50

10、,*pstr;int i,j,k,m,e10,digit,ndigit,a10,*pa;cout=0) & (*(pstr+i)0)digit=*(pstr+i-1)-48; /将个数位赋予digitk=1;while (k0) /以数字结尾字符串的最后一个数据 digit=*(pstr+i-1)-48; /将个数位赋予digitk=1;while (kusing namespace std;int main() int i,j,upper,lower,digit,space,other;char text380;upper=lower=digit=space=other=0;for (i=0

11、;i=A& textij=a & textij=0 & textijusing namespace std;int main()const n=10;int i; char an,temp;coutai;for(i=0;iusing namespace std;int main()void move(int *);int a33,*p,i;coutai0ai1ai2;p=&a00;move(p);cout#include using namespace std;const int n=5;struct student char num6;char name8;int score4;stun;i

12、nt main()void print(student stu6);int i,j;for (i=0;istui.num;coutstui.name;for (j=0;jstui.scorej;cout#include using namespace std;const int n=10;struct student char num6;char name8;int score4;float avr; stun;int main() int i,j,max,maxi,sum;float average;for (i=0;istui.num;coutstui.name;for (j=0;jstu

13、i.scorej;coutmax)max=sum;maxi=i; average/=n;coutarrayp+1)temp=arrayp;arrayp=arrayp+1;arrayp+1=temp;/以下算法为求众数的出现频率for(ix=0;ixmax)max=cnt;/求出所有的众数for(ix=0;ixusing namespace std;int main()void convert(int n);int number;coutnumber; cout#include using namespace std;#define S(a,b,c) (a+b+c)/2#define AREA

14、(a,b,c) sqrt(S(a,b,c)*(S(a,b,c)-a)*(S(a,b,c)-b)*(S(a,b,c)-c)int main()float a,b,c;coutabc;if (a+bc & a+cb & b+ca)cout#include using namespace std;int main()const int n=11;int i,j,ann;for (i=1;iusing namespace std;int main()int i,j,upper,lower,digit,space,other;char text380;upper=lower=digit=space=other=0;for (i=0;i=A& textij=a & textij=0 & textijusing namespace std;int main() const n=10;int i;char an,temp;coutai;for(i=0;i#include using namespace std;int main() string a;int i,n;char temp;couta;n=a.size();for(i=0;iusing namespace std;int main()

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 行业资料 > 其它行业文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号