网友您好, 请在下方输入框内输入要搜索的题目:

题目内容 (请给出正确答案)

阅读以下说明和C语言函数,将应填入(n)处。

【说明】

已知1900年1月1日是星期一,下面的函数count_5_13(int year)用于计算给定的年份year中有几个“黑色星期五”。“黑色星期五”指既是13日又是星期五的日期。

函数count_5_13(int year)首先算出年份year的1月13日是星期几,然后依次计算每个月的13日是星期几,若是星期五,则计数。

程序中使用了函数isLeapYear(int year),其功能是判断给定年份是否为闰年,返回值为1(或0)表示year是(或不是)闰年。

【C语言函数】

int count_5_13(int year)

{

int date; /*date为0表示星期日,为1~6分别表示星期一至星期六*/

long days=0; /*days记录天数*/

int m,y,c=0; /*c用于表示黑色星期五的个数*/

if (year<1900) return-1;

/*计算从1900年1月1日起至给定年份year的1月13日间隔的天数*/

days=12;

for (y= 1900; y < year; y++) {

days +=365;

if (isLeapYear(y))(1);

}

date=((days%7) +1) %7; /*算出给定年份year的1月13日是星期几*/

c=((2)) ?1:0;

for(m=1;(3);m++) {

switch (m) {

case 1:case 3: case 5: case 7:case 8:case 10:case 12:

days=31; break;

case 4: case 6: case 9: case 11:

days=30; break;

case 2:days=28;

if((4)) days=29;

break;

}/*end of switch*/

date=((days%7)+ (5) )%7;

if (date==5) c++;

} /*end of for*/

return c;

}


参考答案

更多 “ 阅读以下说明和C语言函数,将应填入(n)处。【说明】已知1900年1月1日是星期一,下面的函数count_5_13(int year)用于计算给定的年份year中有几个“黑色星期五”。“黑色星期五”指既是13日又是星期五的日期。函数count_5_13(int year)首先算出年份year的1月13日是星期几,然后依次计算每个月的13日是星期几,若是星期五,则计数。程序中使用了函数isLeapYear(int year),其功能是判断给定年份是否为闰年,返回值为1(或0)表示year是(或不是)闰年。【C语言函数】int count_5_13(int year){int date; /*date为0表示星期日,为1~6分别表示星期一至星期六*/long days=0; /*days记录天数*/int m,y,c=0; /*c用于表示黑色星期五的个数*/if (year<1900) return-1;/*计算从1900年1月1日起至给定年份year的1月13日间隔的天数*/days=12;for (y= 1900; y < year; y++) {days +=365;if (isLeapYear(y))(1);}date=((days%7) +1) %7; /*算出给定年份year的1月13日是星期几*/c=((2)) ?1:0;for(m=1;(3);m++) {switch (m) {case 1:case 3: case 5: case 7:case 8:case 10:case 12:days=31; break;case 4: case 6: case 9: case 11:days=30; break;case 2:days=28;if((4)) days=29;break;}/*end of switch*/date=((days%7)+ (5) )%7;if (date==5) c++;} /*end of for*/return c;} ” 相关考题
考题 阅读以下说明和C语言函数,将应填入(n)处的语句写在对应栏内。【说明】设串s和串t采用顺序存储结构,编写函数实现串s和串t的比较操作,要求比较结果包括大于、小于和等于3种情况。【函数】int StrCompare(SStrType s, SStrType t){int n=s.length, m=(1), i,j,tag;i=0; j=0;while((2)){if((3)){i++;j++;}else if(s.str[i]>t.str[j]){tag=1;return tag;}else{tag=-1;return tag;}}if(n==m)tag=0;else if((4))tag=1;else if(n<m)tag=-1;(5);}

考题 阅读以下说明和C语言函数,将应填入(n)处的字句写在对应栏内。[说明]完成以下中序线索化二叉树的算法。[函数]Typedef int datatype;Typedef struct node {Int ltag, rtag;Datatype data;*lchild,* rchild;}bithptr;bithptr pre;void inthread ( p );{if{inthread ( p->lchild );if ( p->lchild==unll ) (1);if ( P->RCHILD=NULL) p->rtag=1;if (2){if (3) pre->rchild=p;if ( p->1tag==1 )(4);}INTHREAD ( P->RCHILD );(5);}}

考题 阅读以下说明和c++码,将应填入(n)处的字名写在的对应栏内。[说明] 以下函数完成求表达式的值,请填空使之完成此功能。float sum ( float x ){ float s=0.0;int sign = 1;(1);for(inti=1;(2); i+ +){t=t*x;s=s+(3);sign = - sign;(4);}

考题 阅读以下函数说明和C语言函数,将应填入(n)处的字句写在对应栏内。【说明】给定函数fun的功能是:将从键盘上输入的每个单词的第一个字母转换为大写字母,输入时各单词必须用空格隔开,用“.”结束输入。【函数】int fun(char *c,int status){if((1)=='')return 1;else{if((2)(3)(4))(5)='A'-'a';return 0;}}main(){int flag=1;char ch;printf("请输入一字符串,用点号结束输入!\n");do {ch=getchar();flag=fun(ch,flag);putchar(ch);}while(ch!='.');printf("\n");}

考题 阅读以下说明和C语言函数,将应填入(n)处的字句写在对应栏内。[说明]编写一个函数,输入为偶数时,调用函数求1/2+?/+…+1/n,当输入n为奇数时,调用函数1/1+1/3+…+1/n (利用指针函数)。[函数]include "stdio. h",main(){float peven (),podd (),dcall ();float sum;int n;while (1){scanf("%d",n);if (n>1)break;}if(n%2==0){printf("Even="):(1);}else{pfinff("Odd=");(2);}printf("%f",sum);}float peven (int n){float s;int is=1;for(i=2;i<=n;i+=2)(3);return (s);}float podd (n)int n;{float s;int i;s=0;for(i=1 i<=n;i+=2)(4);return (s);}float dcall(fp,n)float (*fp) ();int n;{float s;(5);returu (s);}

考题 阅读以下函数说明和C语言函数,将应填入(n)处的字句写在对应栏内。【说明】有n个整数,使其前面各数顺序向后移m个位置,最后m个数变成最前面的m个数。【函数】main(){int number[20],n,m,i;printf("the total numbers is:");scanf("%d",n);printf("back m:");scanf("%d",m);for(i=0;i<=n-1;i)scanf("%d,",number[i]);(1);for(i=0;i<=n-1;i)printf("%d,",number[i]);}move(array,n,m)int n,m,array[20];{int *p,array_end;array_end=(2);for(p=array[n-1];(3);p--)*p=(4);*array=array_end;m--;if(m>0) (5);}

考题 阅读以下函数说明和C语言函数,将应填入(n)处的字句写在答题纸的对应栏内。【函数2.1说明】递归函数sum(int a[], int n)的返回值是数组a[]的前n个元素之和。【函数2.1】int sum (int a[],int n){if(n>0) return (1);else (2);}【函数2.2说明】有3个整数,设计函数compare(int a,int b,int c)求其中最大的数。【函数2.2】int compare (int a, int b, int c ){ int temp, max;(3) a:b;(4) temp:c;}【函数2.3说明】递归函数dec(int a[],int n)判断数组a[]的前n个元素是否是不递增的。不递增返回 1,否则返回0。【函数2.3】int dec( int a[], int n ){if(n<=1) return 1;if(a[0]<a[1]) return 0;return (5);}

考题 阅读以下函数说明和C语言函数,将应填入(n)处的字句写在对应栏内。[说明]已知r[1...n]是n个记录的递增有序表,用折半查找法查找关键字为k的记录。若查找失败,则输出“failure",函数返回值为0;否则输出“success”,函数返回值为该记录的序号值。[C函数]int binary search(struct recordtype r[],int n,keytype k){ intmid,low=1,hig=n;while(low<=hig){mid=(1);if(k<r[mid].key) (2);else if(k==r[mid].key){printf("succesS\n");(3);}else (4);}printf("failure\n");(5);}

考题 试题三(共 15 分)阅读以下说明和 C 程序,将应填入 (n) 处的字句写在答题纸的对应栏内。

考题 ()阅读下列说明和C语言程序,将应填入 (n)处的语句写在答题纸的对应栏内。[说明]下面程序是一个带参数的主函数,其功能是显示在命令行中输入的文本文件内容。[C语言函数]#include"stdio.h"main(argc,argv) int argc; char *argv[]; { (1) ; if((fp=fopen(argv[1],”r’’))== (2) ) { printf(”file not open!\n”);exit(0);} while( (3) ) putchar( (4) ); (5); }