正在加载图片...
第一部分c语言程序设计上机指导 87 int fcom(d) iangle d 4.输入年、月、日后,计算它是该年的第几天 struct date int month static int day tab[2][13]={{0,31,28,31,30,31,30,31, 31,30,31,30,31},{0,31,29,31,30,31,30,31,31,30,31,30,31}}; i int i, leap struct date *pd; printf("Enter year/month/day: " scanf(”d/器d/暑d",&(*pd).year,&(*pd). month,&(*pd.day) 1eap=pd→year4=0&pa→year暑1001=0lpd→year8400==0 pd-yesterday= for (i=0; i<pd-month; i++) pd-yesterday+=day tab[leap] [i] printf("The year passed day=id\n ", pd-yesterday)i 5打印某一学生的成绩。 #include <stdio. h> struct studentinf [long student num har name [10] int age. float score char addr [30]i void print score(struct studentinfo *st printf("852f", st->score);I [struct studentinfo stu=(20050506, "Li",18,'M, 86.,"Rm305 Bldg4")第一部分 C 语言程序设计上机指导 ·87· ·87· } int fcom(d) struct triangle d; { float p,s; p=d.a+d.b+d.c; p=p/2; s=p*(p-d.a)*(p-d.b)*(p-d.c); s= ; printf(“perimeter=%f,area=%f”,p,s); } 4. 输入年、月、日后,计算它是该年的第几天。 #include <stdio.h> struct date { int day; int month; int year; int yesterday; char mon_name[3]; }; static int day_tab[2][13]={{0,31,28,31,30,31,30,31, 31,30,31,30,31},{0,31,29,31,30,31,30,31,31,30,31,30,31}}; main( ) { int i, leap; struct date *pd; printf(“Enter year/month/day:”): scanf(“%d/%d/%d”,&(*pd).year,&(*pd).month,&(*pd.day); leap=pd→year%4==0&&pd→year%100!=0¦¦pd→year%400==0; pd→yesterday=____________; for(i=0;i<pd→month;i++) pd→yesterday+=day_tab[leap][i]; printf(“The year passed day=%d\n”,pd→yesterday); } 5. 打印某一学生的成绩。 #include <stdio.h> struct studentinfo {long student_num; char name[10]; char sex; int age; float score; char addr[30]; }; void print_score(struct studentinfo *st) {printf(“%5.2f”,st->score);} main() {struct studentinfo stu={20050506, “Li”,18, ‘M’,86.5, “Rm305 Bldg4”};
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有