题目
请补充函数fun(),该函数的功能是建立一个带头结点的单向链表并输出到文件“out98.dat”和屏幕上,各结点的值为对应的下标,链表的结点数及输出的文件名作为参数传入。
注意:部分源程序给出如下。
请勿改动主函数main 和其他函数中的任何内容,仪在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
include<stdio. h>
include<conio. h>
include<stdlib. h>
typedef struct ss
{
int data;
struct ss *next;
} NODE;
void fun(int n,char*filename)
{
NODE *h,*p, *s;
FILE *pf;
int i;
h=p= (NODE *) malloc (sizeof (NODE));
h->data=0;
for (i=1; i {
s=(NODE *)malloc (sizeof (NODE));
s->data=【 】;
【 】;
p=【 】
}
p->next=NULL;
if ((pf=fopen (filename, "w") ) ==NULL)
{
printf {"Can not open out9B.clat! ");
exit (0);
}
p=h;
fprintf (pf, "\n***THE LIST***\n");
print f ("\n***THE LIST***\n")
while (p)
{
fprintf (pf, "%3d", p->data)
printf ("%3d",p->data);
if (p->next ! =NULL)
{
fprintf (pf, "->");
printf ("->");
}
p=p->next;
}
fprintf (pf, "\n");
printf ("\n");
fclose (pf);
p=h;
while (p)
{
s=p;
p=p->next;
free (s);
}
}
main()
{
char * filename="out98. dat";
int n;
clrscr ();
printf (" \nInput n: ");
scanf ("%d", &n);
fun (n, filename);
}
第1题
请补充fun()函数,该函数的功能是:把字符的ASCII码中为奇数的字符从字符串str中删除,结果仍然保存在字符串str中,字符串str从键盘输人,其长度作为参数传人fun()函数。
例如,输入“abcdef”,则输出“bdf”。
注意:部分源程序给出如下。
请勿改动main()函数和其他函数中的任何内容,仅在mare()函数的横线上填入所编写的若干表达式或语句。
试题程序:
第2题
请补充fun函数,该函数的功能是:判断一个年份是否为闰年。
例如,1900年不是闰年,2004是闰年。
[注意] 部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的横线上填入所编写的若干表达式或语句。
[试题源程序]
include<stdio.h>
include<conio.h>
int fun(int n)
{
int fiag=0;
if(n%4==0)
{
if((1) )
fiag=1;
}
if((2) )flag=1;
return (3) ;
}
void main()
{
int year;
clrscr();
printf("Input the year:");
scanf("%d", &year);
if(fun(year))
printf("%d is a leap year.\n", year);
else
printf("%d is not a leap year.\n", year);
}
第3题
请补充函数fun(),该函数的功能是:返回字符数组中指定子符的个数,指定字符从键盘输入。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
include <stdio.h>
define N 80
int fun (char s[],char ch)
{
int i=0, n=0;
while(【 】)
{
if(【 】)
n++;
i++;
}
【 】;
}
main ()
{
int n;
char str[N], ch;
clrscr ();
printf ("\nInput a string: \n");
gets (str);
printf ("\nInput a charactor: \n" ;
scanf ("%c", &ch);
n=fun (str, ch);
printf("\nnumber of %c:%d", ch, n);
}
第4题
请补充函数fun(),该函数的功能是:判断某一个年份是否为闰年。
例如,1900年不是闰年,2004是闰年。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
include<stdio.h>
include<conio.h>
int fun(int n)
{
int flag=0;
if (n%4=0)
{
if (【 】)
flag=1;
}
if (【 】)
flag=1;
return【 】;
}
main()
{
int year;
clrscr();
printf("Input the year:");
scanf("%d", &year);
if (fun(year))
printf("%d is a leap year. \n", year);
else
printf("%d is not a leap year.\n",
year);
}
第5题
请补充函数fun(char *s),该函数的功能是把字符串中的内容逆置。
例如:字符串中原有的字符串为abcde,则调用该函数后,串中的内容变为edcba。
注意;部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
$include<string.h>
include<conio.h>
include<stdio.h>
define N 81
void fun(char*s)
{
int i=0,t,n=strlen(s);
for(;【 】;i++)
{
t=*(s+i);
【 】;
【 】;
}
}
main()
{
char a[N];
clrscr();
printf("Enter a string:");
gets(a);
printf("The original string is:");
puts(a);
fun(a);
printf("\n");
printf("The string after modified:");
puts(a);
}
第6题
请补充函数fun(),该函数的功能是计算下面公式SN的值:
例如:当N=50时,SN=71.433699。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
include<conio.h>
include<stdio.h>
double fun(int n)
{
double s=1.0,S1=0.0;
int k;
for(【l】;k<=n;k++)
{
s1=s;
【 】;
}
return【 】;
}
main()
{
int k=0;
double S;
clrscr();
printf("\nPlease input N=");
scanf("%d",&k);
s=fun(k);
printf("\ns=%lf",s);
}
第7题
请补充函数fun(),该函数的功能是:依次取出字符串中所有的小写字母以形成新的字符串,并取代原字符串。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
include<stdio.h>
include<conio.h>
void fun(char *s)
{
int i=0;
char *p=s;
while(【 】)
{
if (*p>='a'&&*p<='z')
{
s[i]=*p;
【 】;
}
p++;
}
s[i]=【 】;
}
main()
{
char str[80];
clrscr();
printf("\nEnter a string:");
gets(str);
printf("\n\nThe string is:\%s\n",str);
fun(str);
printf("\n\nThe string of changing
is:\%s\n",str);
}
第8题
请补充函数fun(),该函数的功能是判断一个数是否为回文数。当字符串是回文时,函数返回字符申:yes!,否则函数返回字符串:no!,并在主函数中输出。所谓回文即正向与反向的拼写都一样,例如:abcba。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
include<string.h>
include<stdio.h>
char *fun(char*str)
{
char *p1,*p2;
int i, t=0;
p1=str;p2=str+strlen(str)-1;
for (i=0;【 】;i++)
if(【 】)
{
t=1;
break;
}
if (【 】)
return("yes!");
else
return("no!");
}
main()
{
char str[50];
printf("Input;");
scanf("%s",str);
printf("%s\n",fun(str));
}
第9题
●试题四
请补充函数fun(),该函数的功能是将字符串tt中的大写字母都改为对应的小写字母,其他字符不变。例如,若输入"Are you come from Sichuan?",则输入"are you come from sichuan?"。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdio.h>
#include<string.h>
#include<conio.h>
char *fun(char tt[])
{
int i;
for(i=0;tt[i];i++)
{
if((tt[i]>=′A′)&&((1) ))
(2) ;
}
return ((3) ) ;
}
main()
{
char tt[81];
printf("\nPlease enter a string:");
gets(tt);
printf("\nThe result string is: \n%s",
fun(tt));
}
第10题
请补充函数fun(),该函数的功能是:求100(不包括100)以内能被2或5整除,但不能同时被2和5整除的自然数。结果保存在数组bb中,函数fun()返回数组比元素的个数。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
include <stdio.h>
define N 100
int fun (int bb [] )
{
int i, j;
for(【 】;i<100; i++)
if ((i%1!=0&&i%5==0)|| (i%2==0&&i%5 !=0)
【 】;
【 】;
}
main()
{
int i, n;
int bb [N];
clrscr ();
n=fun (bb);
for(i=0; i<n; i++)
{
if (i%10==0)
printf ("\n");
printf ("% 4d", bb [i]);
}
}
为了保护您的账号安全,请在“赏学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!