Lab8 王晨旭Word格式文档下载.docx
- 文档编号:20639285
- 上传时间:2023-01-24
- 格式:DOCX
- 页数:11
- 大小:189.92KB
Lab8 王晨旭Word格式文档下载.docx
《Lab8 王晨旭Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《Lab8 王晨旭Word格式文档下载.docx(11页珍藏版)》请在冰豆网上搜索。
(2)Definestructurevariable,andinitializethevariable.
(3)sumallthenumberofdaysintheyearstoredinthevariablesum,ifmeetingaleapyear,sum=sum+1;
#include〈stdio.h〉
structdate
{
intyear;
intmonth;
intday;
};
voidmain()
structdated;
intsum=0;
printf("
\ninputthedate:
\n"
);
scanf("
%d%d%d"
&
d.year,&
d.month,&
d.day);
switch(d.month)
{
case1:
sum=0;
break;
case2:
sum=31;
case3:
sum=31+28;
case4:
sum=31+28+31;
case5:
sum=31+28+31+30;
case6:
sum=31+28+31+30+31;
case7:
sum=31+28+31+30+31+30;
case8:
sum=31+28+31+30+31+30+31;
case9:
sum=31+28+31+30+31+30+31+31;
case10:
sum=31+28+31+30+31+30+31+31+30;
case11:
sum=31+28+31+30+31+30+31+31+30+31;
case12:
sum=31+28+31+30+31+30+31+31+30+31+30;
}
sum+=d.day;
/*天数累加*/
if(d.month>
2)/*闰年处理*/
if(d.year%400==0||d.year%100!
=0&
&
d.year%4==0)
sum+=1;
Total:
%d\n"
sum);
}
Runtheprogram:
(1)Inputalegal(合理的)date,PrintScreenofResult:
(2)Inputadatewithanillegal(不合理的)month,PrintScreenofResult:
(3)Inputadatewithanillegalday,PrintScreenofResult:
(4)Rewritetheprogram,soitcangivetherightresultunderanycondition.重编,满足所有情况
PrintScreenofcode:
if(d.month<
=12){
else
printf(“error”);
PART3Inputandoutputofthestructure.
Fillintheblank.Writeaprogramtoinitialize初始化anarrayofstructuresthrough来自keyboard键盘
andthenoutputthevalueofthearray.输出值
#include<
stdio.h>
string.h>
main()
{structdate
{intyear;
};
structstu
{charnum[12];
charname[20];
charsex;
intage;
structdatebirthday;
};
typedefstructstuSTU;
STUstudent[3];
inti;
/**********program*******************************/
/***usingforlooptoinputthethreeelements**/
/**********end*********************************/
for(i=0;
i<
3;
i++)
{printf("
\nstudent[%d]num:
%s;
name:
sex:
%c;
age:
%d;
birthday:
%d.%d.%d"
i,student[i].num,student[i].name,student[i].sex,student[i].age,student[i].birthday.year,student[i].birthday.month,student[i].birthday.day);
getch();
PART4PassingArraysofstructures.
Whatdoesthefollowingprogramprint?
structinfo
charitem[20];
doublecost;
};
voidsomeFunction(structinfo[]);
intmain(void)
structinfodata[4]={{"
nut"
0.50},{"
bolt"
0.75}};
someFunction(data);
for(i=0;
i<
4;
i++)
printf("
%s,%.2f\n"
data[i].item,data[i].cost);
voidsomeFunction(structinfovalues[])
2;
if(values[i].cost>
0.60)
strcpy(values[i+2].item,"
washer"
);
values[i+2].cost=0.40;
else
hammer"
values[i+2].cost=12.00;
PART5TypeConversions.
(1)Automaticconversions
main()
{
inta,b=−550;
charc='
7'
;
floatf1=3.142,f2;
a=b/c;
/*integerdividedbyacharacter*/
printf(“a=%d\n”,a);
a=f1;
/*floattointegerconversion*/
f1=%f……a=%d\n"
f1,a);
f1=b;
/*integertofloatconversion*/
b=%d……f1=%f\n"
b,f1);
f2=b/50.0;
/*integerdividedbyafloat*/
b=%d,f2=%f\n"
b,f2);
(2)Typecasting
{floatx;
inti;
x=3.6;
i=(int)x;
printf(“x=%f,i=%d”,x,i);
}
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Lab8 王晨旭
![提示](https://static.bdocx.com/images/bang_tan.gif)