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

上传人:b****4 文档编号:16645043 上传时间:2022-11-25 格式:DOCX 页数:14 大小:148.43KB
下载 相关 举报
C语言学习由入门到精通经典实例集合文档格式.docx_第1页
第1页 / 共14页
C语言学习由入门到精通经典实例集合文档格式.docx_第2页
第2页 / 共14页
C语言学习由入门到精通经典实例集合文档格式.docx_第3页
第3页 / 共14页
C语言学习由入门到精通经典实例集合文档格式.docx_第4页
第4页 / 共14页
C语言学习由入门到精通经典实例集合文档格式.docx_第5页
第5页 / 共14页
点击查看更多>>
下载资源
资源描述

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

《C语言学习由入门到精通经典实例集合文档格式.docx》由会员分享,可在线阅读,更多相关《C语言学习由入门到精通经典实例集合文档格式.docx(14页珍藏版)》请在冰豆网上搜索。

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

intz;

if(x>

y)

z=x;

elsez=y;

return(z);

tset1-3:

输出指定的信息

inti,j;

for(i=0;

i<

=40;

i++)

printf("

*"

);

\nC语言学习开篇!

\n"

for(j=0;

j<

j++)

printf("

第二章:

数据的存储与运算

test2-1;

鸡兔同笼

一个笼子养着一些鸡和兔子,现在知道鸡子和兔子总共16只,它们总脚数为40,问鸡子和兔子各有多少只?

intx,y,m,n;

m=16;

n=40;

y=(n-2*m)/2;

x=m-y;

cock=%d\nrabbit=%d\n"

x,y);

test2-2:

分期付款计算

贷款额为324500元,每月准备还3245元,月利率为0.8%,问几个月可以还完?

math.h>

intd=324500,p=3245;

doubler=0.008,m;

m=(log10(p)-log10(p-d*r))/log10(1+r);

month=%f\n"

m);

test2-3:

逐个输出英文字母CHINA;

然后反序逐个输出ANIHC。

chara='

C'

b='

H'

c='

I'

d='

N'

e='

A'

;

%c%c%c%c%c\n"

a,b,c,d,e);

e,d,c,b,a);

test2-4:

求圆的面积和周长

已知圆的半径r,分别求圆的周长c,圆面积s,圆球的体积v。

#definePI3.1415926

doubler,c,s,v;

r=3.67;

c=2*PI*r;

s=PI*pow(r,2);

v=4.0/3.0*PI*pow(r,3);

Circumference=%f\nArea=%f\nVolume=%f\n"

c,s,v);

运行结果:

test2-5:

强制类型转换

floatf=3.38;

inti;

i=(int)f;

f=%f\ni=%d\n"

f,i);

第三章:

顺序结构设计

test3-1:

先后输出几个字符

chara,b,c;

a='

B'

b='

O'

c='

Y'

putchar(a);

putchar(b);

putchar(c);

test3-2:

输入一个字符

chara;

a=getchar();

test3-3:

由“海伦公式”求三角形面积

doubles,a,b,c,area;

%lf,%lf,%lf"

b,&

c);

s=(a+b+c)/2.0;

area=sqrt(s*(s-a)*(s-b)*(s-c));

Area=%lf\n"

area);

test3-4:

求方程ax2+bx+c=0的根

doublea,b,c,disc,m,n,x1,x2;

a=%lf,b=%lf,c=%lf"

disc=b*b-4*a*c;

m=-b/(2*a);

n=sqrt(disc)/(2*a);

x1=m+n;

x2=m-n;

x1=%f\nx2=%f\n"

x1,x2);

第四章:

条件判断

test4-1:

由高到低输出三个数

floata,b,c,t;

%f,%f,%f"

if(a<

b)

{t=a;

a=b;

b=t;

c)

a=c;

c=t;

if(b<

{t=b;

b=c;

%f,%f,%f\n"

a,b,c);

test4-2:

由三边长求三角形面积

floata,b,c,s,area;

s=(a+b+c)/2;

if(a+b>

c&

&

b+c>

a&

a+c>

{

Area=%f\n"

}

else

Thisnotatriangle!

test4-3:

商品打折

50件以上优惠5%,100件以上优惠7.5%,300件以上优惠10%,500件以上优惠15%,输入数量和单价计算应付款。

floatdiscount,total,price;

intnumber;

Pleaseenterpriceandnumber:

"

%f,%d"

price,&

number);

if(number>

=500)discount=0.15;

elseif(number>

=300)discount=0.10;

=100)discount=0.075;

=50)discount=0.05;

elsediscount=0;

total=number*price*(1-discount);

商品总价格是:

%f元。

total);

test4-4:

判断闰年

#include<

intyear;

PLeaseenterayear:

%d"

year);

if(year%400==0||(year%4==0&

year%100!

=0))

Theyearisaleapyear!

else

Theyearisnotaleapyear!

test4-5:

Switch的简单应用

floatp,t,w,discount;

intc,s;

Pleaseenterprice/weightandspace:

%f,%f,%d"

p,&

w,&

s);

if(s>

=3000)

c=12;

c=s/250;

switch(c)

case0:

discount=0;

break;

case1:

discount=1;

case2:

case3:

discount=2;

case4:

case5:

case6:

case7:

discount=8;

case9:

case10:

case11:

discount=10;

case12:

discount=15;

t=p*w*s*(1-discount/100.0);

Thetotalis%f.\n"

t);

第五章:

循环结构程序设计

Test5-1:

求1到100之间所有数字的和

inti=1,sum=0;

while(i<

=100)

sum=sum+i;

i++;

1到100数字和为:

%d\n"

tset5-2:

慈善基金准备募捐10000元,有如感人捐献,每输入一次捐款计算机将显示总共捐款总额,超过10000则结束捐款并显示捐款结果。

floatsum=0,amount;

Startenterdonation:

do

{

scanf("

%f"

amount);

sum=sum+amount;

while(sum<

10000);

sum=%f\n"

test5-3:

国王的小麦

doublep=1,t=1,v;

for(i=1;

=63;

p=p*2;

t=t+p;

v=t/1.42e8;

Total=%e\n"

Volume=%e\n"

v);

test5-4:

人口增长预测

2005年我国人口130756万,人口年增长率为1%,计算哪一年中国人口超过15亿。

doublep=1.30756e9,r=0.01;

inty;

for(y=2005;

p<

1.5e9;

y++)

p=p*(1+r);

Theyearis%d.\n"

y);

test5-5:

统计各班(不超过30人)学生的平均成绩

inti,n;

floatscore,sum=0,ave;

31;

score);

if(score<

0)break;

sum=sum+score;

n=i-1;

ave=sum/n;

学生人数为:

%d\n平均成绩为:

%f\n"

n,ave);

第六章:

利用数组处理批量数据

test6-1:

引用数组元素

利用循环给数组元素a[0]-a[9]赋值0~9,然后按逆序进行输出;

inti,a[10];

10;

a[i]=i;

for(i=9;

i>

=0;

i--)

%d,"

a[i]);

Test6-2:

冒泡法排序

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 工程科技 > 材料科学

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

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