C语言作业总结简单入门Word格式.docx

上传人:b****2 文档编号:3758236 上传时间:2023-05-02 格式:DOCX 页数:23 大小:17.80KB
下载 相关 举报
C语言作业总结简单入门Word格式.docx_第1页
第1页 / 共23页
C语言作业总结简单入门Word格式.docx_第2页
第2页 / 共23页
C语言作业总结简单入门Word格式.docx_第3页
第3页 / 共23页
C语言作业总结简单入门Word格式.docx_第4页
第4页 / 共23页
C语言作业总结简单入门Word格式.docx_第5页
第5页 / 共23页
C语言作业总结简单入门Word格式.docx_第6页
第6页 / 共23页
C语言作业总结简单入门Word格式.docx_第7页
第7页 / 共23页
C语言作业总结简单入门Word格式.docx_第8页
第8页 / 共23页
C语言作业总结简单入门Word格式.docx_第9页
第9页 / 共23页
C语言作业总结简单入门Word格式.docx_第10页
第10页 / 共23页
C语言作业总结简单入门Word格式.docx_第11页
第11页 / 共23页
C语言作业总结简单入门Word格式.docx_第12页
第12页 / 共23页
C语言作业总结简单入门Word格式.docx_第13页
第13页 / 共23页
C语言作业总结简单入门Word格式.docx_第14页
第14页 / 共23页
C语言作业总结简单入门Word格式.docx_第15页
第15页 / 共23页
C语言作业总结简单入门Word格式.docx_第16页
第16页 / 共23页
C语言作业总结简单入门Word格式.docx_第17页
第17页 / 共23页
C语言作业总结简单入门Word格式.docx_第18页
第18页 / 共23页
C语言作业总结简单入门Word格式.docx_第19页
第19页 / 共23页
C语言作业总结简单入门Word格式.docx_第20页
第20页 / 共23页
亲,该文档总共23页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

C语言作业总结简单入门Word格式.docx

《C语言作业总结简单入门Word格式.docx》由会员分享,可在线阅读,更多相关《C语言作业总结简单入门Word格式.docx(23页珍藏版)》请在冰点文库上搜索。

C语言作业总结简单入门Word格式.docx

某月多少天(switch)

intyear,month;

请输入年份:

year);

请输入月份:

month);

switch(month)

case1:

case3:

case5:

case7:

case8:

case10:

case12:

printf("

31天\n"

break;

case4:

case6:

case9:

case11:

30天\n"

case2:

if(year%4==0&

&

year%100!

=0||year%400==0)

29天\n"

elseprintf("

28天\n"

最少运费应用题(switch)

intk,s;

floatp,w,d,f;

请输入距离(km):

s);

请输入单价($):

%f"

p);

请输入货物重量(kg):

w);

if(s>

3000)

k=12;

elsek=s/250;

switch(k)

case0:

d=0;

break;

d=2;

case2:

case3:

d=5;

case4:

case5:

case6:

case7:

d=8;

case8:

case9:

case10:

case11:

d=10;

case12:

d=15;

f=p*w*s*(1-d/100);

f);

水仙花数163页

intm,i,j,k;

m=100;

while(m<

=999)

i=m/100;

j=(m-100*i)/10;

k=m-100*i-10*j;

if(m==i*i*i+j*j*j+k*k*k)

%d\n"

m);

m++;

及格的成绩输出例一15页

intn;

floatscore;

n=1;

请输入10个学生的成绩:

\n"

while(n<

=10)

score);

if(score>

=60)

printf("

%.1f\n"

score);

n++;

输出8个数中最大数例三16页

intx,max,i;

i=1;

请输入8个整数:

max=x;

while(i<

=8)

if(x>

=max)

max=x;

i++;

最大数是:

max);

统计字符串中的各元素个数83页第十题

charc;

intletters=0,space=0,digit=0,other=0;

请输入字符串:

while((c=getchar())!

='

\n'

if(c>

a'

c<

z'

||c>

A'

Z'

letters++;

elseif(c=='

'

space++;

elseif(c>

0'

9'

digit++;

elseother++;

字母:

%d,空格:

%d,数字:

%d,其他字符:

letters,space,digit,other);

4/3,7/4,11/7,18/11……前18项求和

intt,n;

floata,b,sum,x;

sum=0;

a=4;

b=3;

x=4/3;

for(n=1;

n<

=18;

n++)

sum+=x;

t=a;

a=a+b;

b=t;

x=a/b;

%f\n"

sum);

a+aa+aaa+aaaa=

inti,n,a;

longints=0,t=0;

请输入a,n:

%d%d"

n);

for(i=1;

i<

=n;

i++)

t=t+a;

s=s+t;

a=a*10;

a+aa+aaa+......=%ld\n"

s);

输出10到100的素数

inti,n;

for(n=10;

=100;

for(i=2;

n;

{

if(n%i==0)break;

if(i==n)

n);

分数储存(一维数组)

inti,score[39],sum;

floataver;

for(i=0;

=38;

scanf("

score[i]);

sum+=score[i];

aver=sum/39.0;

if(score[i]>

=aver)

printf("

score[i]);

分数储存(二维数组)

intscore[5][3],i,j,s=0;

doubleaver[5];

=4;

for(j=0;

j<

=2;

j++)

{

scanf("

score[i][j]);

s+=score[i][j];

}

aver[i]=s/3.0;

s=0;

%4f"

aver[i]);

冒泡法对8个数降序

inti,j,a[8],t;

请输入8个数:

7;

scanf("

a[i]);

for(j=0;

for(i=0;

7-j;

if(a[i]<

a[i+1])

t=a[i+1];

a[i+1]=a[i];

a[i]=t;

排列后的数组:

%4d"

a[i]);

选择法对8个数升序

inta[8],i,j,k,x;

请输入8个数:

for(i=0;

8;

k=i;

for(j=i+1;

if(a[j]<

a[k])k=j;

if(k!

=i)

{

x=a[i];

a[i]=a[k];

a[k]=x;

}

排序后的数组:

计算字符串长度

chara[20];

inti=0;

请输入字符串:

gets(a);

while(a[i]!

\0'

i++;

字符串的长度为:

i);

合并两字符串

chari,j,a[80],b[40];

gets(b);

i=0;

j=0;

while(b[j]!

a[i]=b[j];

j++;

a[i]='

;

puts(a);

字符串输出1

char*p="

helloworld"

p=p+3;

%s\0"

p);

字符串输出2

chara[]="

*p=a;

*p='

%s\n"

字符串粘贴

string.h>

chara[80],b[80];

char*stra,*strb;

stra=a;

strb=b;

while(*stra!

){*strb=*stra;

stra++,strb++;

*strb=0;

puts(b);

字符串连接

)stra++;

while(*strb!

{*stra=*strb;

*stra=0;

puts(a);

结构体

structclassment

charname[20];

intage;

charsex;

chargf[20];

charchild[20];

}cla1;

cla1.age=21;

cla1.sex='

M'

inputnameandgfandchild:

\n"

%s%s%s"

cla1.name,&

cla1.gf,cla1.child);

name=%s\nage=%d\nsex=%c\ngf=%s\nchild=%s\n"

cla1.name,cla1.age,cla1.sex,cla1.gf,cla1.child);

结构体数组

structemployee

charname[15];

floatsalary;

}emp[3]={{"

zhouxuan"

'

m'

21,1.2},{"

zhoujianye"

21,1.4},{"

zhenlijie"

21,1.6}};

inti;

floats=0;

3;

s+=emp[i].salary;

s=%f\n"

指针访问结构体

}emp1={"

21,2000};

structemployee*pemp;

pemp=&

emp1;

name=%s\n"

(*pemp).name);

指针访问结构体数组

21,200},{"

21,1000},{"

21,1600}};

structemployee*peme;

for(peme=emp;

peme<

emp+3;

peme++)

(*peme).name);

定义函数判断素数

intfac(intn)

inti,flag;

for(i=2;

if(n%i==0)break;

if(i==n)flag=1;

elseflag=0;

return(flag);

intm;

请输入一个非零自然数:

m);

if(fac(m)==1)

该数为素数"

该数为非素数"

定义函数最大公约数和最小公倍数

intzhao(inta,intb)

intz,i;

if(a>

b)

for(i=b;

=1;

i--)

if(a%i==0&

b%i==0)

{z=i;

else

for(i=1;

=a;

if(a%i==0&

return(z);

intxiang(intc,intd)

intt,j;

d)

for(j=c;

=c*d;

if(j%c==0&

j%d==0)

{t=j;

for(j=d;

if(j%c==0&

return(t);

intm,n,x,y;

请输入两个正整数:

m,&

x=zhao(m,n);

y=xiang(m,n);

最大公约数=%d最小公倍数=%d"

输入成绩,输出各行的平均分

inti,j,sco[5][3];

ints=0,ave[5];

5;

sco[i][j]);

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

ave[i]=s/3;

ave[i]);

定义函数计算x的平方再求其阶乘(函数嵌套)

intfun1(intp);

intfun2(intp);

intfun1(intp)

intz,x;

z=p*p;

x=fun2(z);

return(x);

intfun2(intp)

intj,z=1;

for(j=1;

=p;

z=z*j;

return(z);

inti,sum=0;

=3;

sum+=fun1(i);

定义函数n的阶乘(递归调用)

longfun(intn)

longz;

if(n>

=2)

z=fun(n-1)*n;

elsez=1;

intn;

longz;

z=fun(n);

%ld"

z);

定义宏求最小值

#defineMin(a,b)(a>

b)?

b:

a

intx,y,min;

x,&

y);

min=Min(x,y);

min);

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

当前位置:首页 > 工程科技 > 能源化工

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2