ImageVerifierCode 换一换
格式:DOCX , 页数:14 ,大小:148.43KB ,
资源ID:3740262      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/3740262.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(C语言学习由入门到精通经典实例集合.docx)为本站会员(b****4)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

C语言学习由入门到精通经典实例集合.docx

1、C语言学习由入门到精通经典实例集合C语言学习由入门到精通(经典实例集合)第一章:C语言概述test1-1:求两数之和#include void main() int a,b,sum; a=123; b=456; sum=a+b; printf(Sum is %dn,sum);运行结果:test1-2:求两数中的较大者#include void main() int max(int x,int y); int a,b,c; scanf(%d,%d,&a,&b); c=max(a,b); printf(max=%dn,c);int max(int x,int y) int z; if(xy) z=

2、x; else z=y; return(z);运行结果:tset1-3:输出指定的信息#include void main() int i,j; for(i=0;i=40;i+) printf(*); printf(n C语言学习开篇!n); for(j=0;j=40;j+) printf(*);运行结果:第二章:数据的存储与运算test2-1;鸡兔同笼一个笼子养着一些鸡和兔子,现在知道鸡子和兔子总共16只,它们总脚数为40,问鸡子和兔子各有多少只?#include void main() int x,y,m,n; m=16; n=40; y=(n-2*m)/2; x=m-y; printf(

3、cock=%dnrabbit=%dn,x,y);运行结果:test2-2:分期付款计算贷款额为324500元,每月准备还3245元,月利率为0.8%,问几个月可以还完?#include #include void main() int d=324500,p=3245; double r=0.008,m; m=(log10(p)-log10(p-d*r)/log10(1+r); printf(month=%fn,m);运行结果:test2-3:逐个输出英文字母CHINA;然后反序逐个输出ANIHC。#include void main() char a=C,b=H,c=I,d=N,e=A; pr

4、intf(%c%c%c%c%cn,a,b,c,d,e); printf(%c%c%c%c%cn,e,d,c,b,a);运行结果:test2-4:求圆的面积和周长已知圆的半径r,分别求圆的周长c,圆面积s,圆球的体积v。、#include #include #define PI 3.1415926void main() double r,c,s,v; r=3.67; c=2*PI*r; s=PI*pow(r,2); v=4.0/3.0*PI*pow(r,3); printf(Circumference=%fnArea=%fnVolume=%fn,c,s,v);运行结果:test2-5:强制类型转

5、换#include void main() float f=3.38; int i; i=(int)f; printf(f=%fni=%dn,f,i);运行结果:第三章:顺序结构设计test3-1:先后输出几个字符#include void main() char a,b,c; a=B;b=O;c=Y; putchar(a); putchar(b); putchar(c); printf(n);运行结果:test3-2:输入一个字符#include void main() char a; a=getchar(); putchar(a); printf(n);运行结果:test3-3:由“海伦公

6、式”求三角形面积#include #include void main() double s,a,b,c,area; scanf(%lf,%lf,%lf,&a,&b,&c); s=(a+b+c)/2.0; area=sqrt(s*(s-a)*(s-b)*(s-c); printf(Area=%lfn,area);运行结果:test3-4:求方程ax2+bx+c=0的根#include #include void main() double a,b,c,disc,m,n,x1,x2; scanf(a=%lf,b=%lf,c=%lf,&a,&b,&c); disc=b*b-4*a*c; m=-b/

7、(2*a); n=sqrt(disc)/(2*a); x1=m+n; x2=m-n; printf(x1=%fnx2=%fn,x1,x2);运行结果:第四章:条件判断test4-1:由高到低输出三个数#include void main() float a,b,c,t; scanf(%f,%f,%f,&a,&b,&c); if(ab) t=a;a=b;b=t; if(ac) t=a;a=c;c=t; if(bc) t=b;b=c;c=t; printf(%f,%f,%fn,a,b,c);运行结果:test4-2:由三边长求三角形面积#include #include void main() f

8、loat a,b,c,s,area; scanf(%f,%f,%f,&a,&b,&c); s=(a+b+c)/2; if(a+bc&b+ca&a+cb) area=sqrt(s*(s-a)*(s-b)*(s-c); printf(Area=%fn,area); else printf(This not a triangle !n);运行结果:test4-3:商品打折 50件以上优惠5%,100件以上优惠7.5%,300件以上优惠10%,500件以上优惠15%,输入数量和单价计算应付款。#include void main() float discount,total,price; int nu

9、mber; printf(Please enter price and number :); scanf(%f,%d,&price,&number); if(number=500) discount=0.15; else if(number=300) discount=0.10; else if(number=100) discount=0.075; else if(number=50) discount=0.05; else discount=0; total=number*price*(1-discount); printf(商品总价格是:%f元。n,total);运行结果:test4-4

10、:判断闰年 #include void main() int year; printf(PLease enter a year :n); scanf(%d,&year); if(year%400=0|(year%4=0&year%100!=0) printf(The year is a leap year !n); else printf(The year is not a leap year !n);运行结果:test4-5:Switch的简单应用#include void main() float p,t,w,discount; int c,s; printf(Please enter p

11、rice/weight and space :); scanf(%f,%f,%d,&p,&w,&s); if(s=3000) c=12; else c=s/250; switch(c) case 0:discount=0;break; case 1:discount=1;break; case 2: case 3:discount=2;break; case 4: case 5: case 6: case 7:discount=8;break; case 9: case 10: case 11:discount=10;break; case 12:discount=15;break; t=p*

12、w*s*(1-discount/100.0); printf(The total is %f.n,t);运行结果:第五章:循环结构程序设计Test5-1:求1到100之间所有数字的和#include void main() int i=1,sum=0; while(i=100) sum=sum+i; i+; printf(1到100数字和为:%dn,sum);运行结果:tset5-2: 慈善基金准备募捐10000元,有如感人捐献,每输入一次捐款计算机将显示总共捐款总额,超过10000则结束捐款并显示捐款结果。#include void main() float sum=0,amount; pr

13、intf(Start enter donation :n); do scanf(%f,&amount); sum=sum+amount; while(sum10000); printf(sum=%fn,sum);运行结果:test5-3:国王的小麦 #include void main() double p=1,t=1,v; int i; for(i=1;i=63;i+) p=p*2; t=t+p; v=t/1.42e8; printf(Total=%en,t); printf(Volume=%en,v);运行结果:test5-4:人口增长预测2005年我国人口130756万,人口年增长率为1

14、%,计算哪一年中国人口超过15亿。#include void main() double p=1.30756e9,r=0.01; int y; for(y=2005;p1.5e9;y+) p=p*(1+r); printf(The year is %d.n,y);运行结果:test5-5:统计各班(不超过30人)学生的平均成绩 #include void main() int i,n; float score,sum=0,ave; for(i=1;i31;i+) scanf(%f,&score); if(score0) break; sum=sum+score; n=i-1; ave=sum/n; printf(学生人数为:%dn平均成绩为:%fn,n,ave);运行结果:第六章:利用数组处理批量数据test6-1:引用数组元素 利用循环给数组元素a0-a9赋值09,然后按逆序进行输出;#include void main() int i,a10; for(i=0;i=0;i-) printf(%d,ai); 运行结果:Test6-2:冒泡法排序

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1