更多"请补充函数fun( ),该函数的功能是建立一个带头结点的单向链表并输出"的相关试题:
[填空题]请补充函数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= 【1】 ;
【2】 ;
p= 【3】
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)
[填空题]请补充fun( )函数,fun函数的功能是求m的阶乘。
请勿改动main( )函数与其他函数中的任何内容,仅在fun( )函数的横线上填写所需的若干表达式语句。
注意:部分源程序给出如下。
试题程序:
#include<stdio.h>
long fun(int m)
{
if(______)
return(m*fun(______));
return ______;
}
void main( )
{
printf("8!=%ld/n",fun(8));
}
[填空题]请补充fun函数,该函数的功能是:将带头结点的单向链表逆置。即若原链表中从头至尾结点数据域依次为:2、4、6、8、10,逆置后,从头至尾结点数据域依次为:10、8、6、4、2。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的行线上填入所编写的若干表达式或语句。
[试题源程序]
#include<stdio.h>
#include<stdlib.h>
#define N 5
typedef struct node
int data;
struct node * next;
NODE;
void fun(NODE * h)
NODE*P,*q,*r;
p= (1) ;
if( (2) )return;
q=p->next;
p->next=NULL;
while(q)
r=q->next;
q->next=p;
p=q;
q= (3) ;
h->next=p;
NODE*creatlist(int a[])
NODE*h.*p,*q;int i;
h=(NODE*)malloc(sizeof(NODE));
h->next=NULL;
for(i=0;i<N;i++)
q=(NODE*)malloc(sizeof(NODE));
q->data=a[i];
q->next=NULL;
if(h->next==NULL)
h->next=p=q;
else
P->next=q;p=q;
return h;
void outlist(NODE*h)
NODE*P;
p=h->next;
if(p==NULL)
printf("The list is NULL!/n");
[填空题]请补充fun( )函数,该函数的功能是求m的阶乘。不要改动主函数main( )与他函数中的任何内容,仅在fun( )函数的横线上填写所需的若干表达式或语句。
注意:部分源程序如下。
#include<stdio.h>
long fun(int m)
if (1)
return(m*fun (2) );
return (3) ;
main( )
printf("8!=%ld/n",fun(8));
[填空题]请补充fun函数,fun函数的功能是求n的阶乘。
注意:部分源程序已给出。
请勿改动主函数main和其他函数中的任何内容,仅在fun函数的横线上填入所编写的若干表达式或语句
试题程序:
#include<stdio.h>
long fun(int n)
if( (1) )
return(n*fun( (2) ));
return (3) ;
main( )
printf("10!=%1d/n",fun(10));
[填空题]请补充fun函数,该函数的功能是:把一个整数转换成字符串,并倒序保存在字符数组S中。例如,当n=123时,s="321"。
注意:部分源程序已给出。
淆勿改动主函数main和其他函数中的任何内容,仅在main函数的横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdio.h>
#include<conio.h>
#define M 80
char s[M];
void fun(long int n)
int j=0;
while( (1) )
s[j]= (2) ;
n/=10;
j++;
(3) ;
main( )
long int n=1234567;
printf("The origial data/n");
printf("n=%1d",n);
fun(n);
printf("/n%s",s);
[填空题]请补充函数fun( ),函数fun( )的功能是求7的阶乘。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun( )的横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdio.h>
long fun(int n)
if( 【1】 )
return(n*fun( 【2】 );
else if( 【3】 )
return 1;
main( )
int k=7;
printf("%d!=%ld/n", k, fun(k));
[填空题]请补充函数fun( ),该函数的功能是判断一个数是否为素数。该数是素数时,函数返回字符串:yes!,否则函数返回字符串:no!,并在主函数中输出。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun( )的横线上填入所编写的若干表达式或语句。
试题程序:
#include "conio.h"
#include "stdio.h"
【1】
{
int i, m;
m=1;
for(i= 【2】 ;i<n; i++)
if ( 【3】 )
{
m=0;
break;
}
if(m==1&&n>1)
return("yes!");
else
return("no!");
}
main( )
{
int k=0;
clrscr( );
printf("Input:");
scanf("%d",&k);
printf("%s/n",fun(k));
}
[填空题]请补充函数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; 【1】 ;i++)
if( 【2】 )
t=1;
break;
if ( 【3】 )
return("yes!");
else
return("no!");
main( )
char str[50];
printf("Input;");
scanf("%s",str);
printf("%s/n",fun(str));