填空题下列给定程序中函数fun()的功能是计算正整数num的各位上的数字之平方和。
例如:输入352,则输出应该是38;若输入328,则输出应该是77。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include <stdio.h>
#include <conio.h>
long fun(long num)
{
/*+**+*+*+*found************/
long k=1;
do
{
k+=(num%10)*(num%10);
num/=10;
/*********+found*+**+*+******/
}while(num)
return(k);
}
main()
{
long n;
clrscr();
printf("/Please enter a number:");
scanf("%ld",&n);
printf("/n%ld/n",fun(n));
}
填空题下列给定程序中,已建立一个带头结点的单向链表,链表中的各结点按结点数据域中的数据递增有序链接。函数fun的功能是:把形参x的值放入一个新结点并插入链表中,使插入后备结点数据域中的数据仍保持递增有序。
请在下划线处填入正确的内容并将下划线删除,使程序得出正确的结果。
注意
:部分源程序给出如下。
不得增行或删行,也不得更改程序的结构!
试题程序:
#include<stdio.h>
#include<stdlib.h>
#define N 8
typedef struct list
{int data;
struct list *next;
}SLIST;
void fun(SLIST *h,int x)
{SLIST *p,*q,*s;
s=(SLIST *)malloc(sizeof(SLIST));
/********found********/
s->data=______;
q=h;p=h->next;
while(p!=NULL
p=p->next;
}
s->next=p;
/********found********/
q->next=______;
}
SLIST *creatlist(int *a)
{SLIST *h,*p,*q;int i;
h=p=(SLIST *)malloc(sizeof(SLIST));
for(i=0;i<N;i++)
{q=(SLIST *)malloc(sizeof(SLIST));
q->data=a[i];p->next=q;p=q;
}
p->next=0;
return h;
}
void outlist(SLIST /h)
{SLIST *p;
p=h->next;
if(p==NULL)
printf("/nThe list is NULL!/n");
else
{printf("/nHead");
do
{printf("->%d",p->data);
p=p->next;
}while(p!=NULL);
printf("->End/n");
}
}
main()
{SLIST *head;int x;
int a[N]={11,12,15,18,19,22,25,29};
head=creatlist(a);
printf("/nThe list before inserting:/n");
outlist(head);
printf("/nEnter a number:");
scanf("%d",
fun(head,x};
printf("/nThe list after inserting:/n");
outlist(head);
}
填空题若有定义int a[4][4]={1,2,3,4},{0},{4,6,8,10},{1,3,5,7}},则初始化后,a[1][1]得到的初值是______。
填空题若有程序
main( )
{ int i,j;
scanf("i=%d,j=%d",
printf("i=%d,j=%d/n ",i,j);
}
要求给i赋10,给j赋20,则应该从键盘输入{{U}} 【7】 {{/U}}。
填空题下面程序的功能是将一个字符串str的内容倒序,请填空。 #inelude <stdio.h> #include <strins.h> main() int i,j, 【15】 ; charstr[]="1234567"; for(i=0,j=strlen(str) 【16】 ;i<j; i++,j--) k=str[i];str[i]=str[j];str[j]=k; printf("%s/n",str);
填空题下列给定程序中,函数fun的功能是:将形参s所指字符串中的所有字母字符顺序前移,其他字符顺序后移,处理后将新字符串的首地址作为函数值返回。
例如,若s所指字符串为“asd123fgh543df”,处理后新字符串为“asdfghdf123543”。
请在下划线处填入正确的内容,使程序得出正确的结果。
注意:部分源程序给出如下。
不得增行或删行,也不得更改程序的结构!
试题程序:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
char*fun(char*s)
{int i,j,k,n;char*p,*t;
n=strlen(s)+1;
t=(char*)malloc(n*sizeof(char));
P=(char*)malloc(n*sizeof(char));
j=0;k=0;
for(i=0;i<n;i++)
{if(((s[i]>="a")&&(s[i]<="z"))||((s[i]>="A")&&(s[i]<="Z"))){
/********found********/
t[j]=______;j++;}
else
{p[k]=s[i];k++;}
}
/********found********/
for(i=0;i<______;i++)
t[j+i]=p[i];
/********found********/
t[j+k]=______;
return t;
}
main()
{char s[80];
printf("Please input:");
scanf("%s",s);
printf("/nThe result is:%s/n",fun (s));
}
填空题请补充main函数,该函数的功能是:从键盘输入两上字符串并分别保存在字符数组str1和str2中,用字符串str2替换字符串str1前面的所有字符,注意,str2的K度不大于str1,否则需要重新输入。
例如,如果输入strl;=“abced”,str2=“fk”,则输出“fkced”。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仪在 main函数的横线上填入所编写的若干表达式或语句。
试题程序:
#include<stdio.h>
#include<string. h>
main ()
{
char strl [ 81], str2 [ 81 ];
char *pl=strl, *p2=str2;
clrscr ();
do
{
printf(" Input strl tn");
gets (strl);
printf(" Input str2 In");
gets (str2);
}while({{U}}【1】{{/U}});
while({{U}}【2】{{/U}})
*p1++=*p2++;
printf(" Display strl /n");
puts ({{U}}【3】{{/U}})
}
填空题以下程序运行后输入:3,abcde<回车>,则输出结果是 【17】 。 #include<string.h> move(char *str,int n) char temp;int i; temp=str[n-1]; for(i=n-1;i>0;i--)str[i]=str[i-1]; str[0]=temp; main() char s[50];int n,i,z; scanf("%d,%s",i<=n;i++)move(s,z); printf("%s/n",s);
填空题下列程序的运行结果是______。 #include<stdio.h> func(a,b) static int m=0,i=2; i+=m+1; m=i+a+b; return(m); main() int k=5,m=3,p; p=func(k,m); printf("%d",p); p=func(k,m); printf("%d/n",p);
填空题有以下程序
#include
int fun(int n)
{ if(n == 0) return(1);
return(fun(n - 1) * n);
}
main()
{ int t;
t = fun(3); printf("%d\n", t);
}
程序运行后输出结果是U [14] /U。
填空题以下程序运行后的输出结果是 【18】 。 fun(int x) if(x/2>0)fun(x/2); printf("%d",x); main() fun(6);
填空题有以下程序,请在______处填写正确语句,使程序可正常编译运行。 #include<stdio.h> ______; main() (double x, y, (*p)(); scanf("%1f%1f", &x, &y); p=avg; printf("%f/n", (*p)(x, y)); double avg(double a, double b) return((a+b)/2);
填空题以下程序的输出结果是______。 #include main() int a[5]=2,4,6,8,10, *p; p=a; p++; printf("%d",*p);
填空题以下程序的功能是建立一个带有头结点的单向链表,链表结点中的数据通过键盘输入,当输入数据为-1时,表示输入结束(链表头结点的data域不放数据,表空的条件是ph->next==NULL),请填空。
#include <stdio.h>
struct list { int data;struct list *next;};
struct list *creatlist( )
{ struct list *p,*q,*ph;int a;ph=(struct list*)malloc(sizeof(struct list));
p=q=ph;printf("Input an integer number;entre-1 to end:/n");
scanf("%d",&a);
while(a!=-1)
{ p=(struct list*)malloc(sizeof(struct list));
______=a;q->next=p;______=p;scanf("%d",&a);}
p->next='/0';return(ph);}
main( )
{stuct list * head;head=creatlist();}
填空题设Y是int型变量,请写出判断Y为奇数的关系表达式 【7】 。
填空题下列程序的输出结果是【 】。
#include <stdio.h>
void fun(int x)
{
if(x/2>0) fun(x/2);
printf("%d",x);
}
main()
{
fun(3);printf("\n");
}
填空题有关系模式:学生S(学号,姓名,性别,年龄,身份证号),课程C(课号,课名),其中两个关系模式的主键分别是学号和课号,则关系模式选课SC可定义为SC(学号,______,成绩)。
填空题若有语句
int i=17:j=i++%4;
printf("%d/n",j);
则输出结果是______。
填空题设在主函数中有以下定义和函数调用语句,且fun函数为void类型,请写出fun函数的首部 【13】 。要求形参名为b。 main() double s[10] [22]; int n; ┆ fun(s); ┆
填空题下列程序的功能是:将字符数组a中下标值为偶数的元素从小到大排列,其他元素不变。请填空。 #include <string.h> mare() chara[]="clanguage",t; int i,j,k; k=strlen(a); for(i=0;i<=k-2;i+=2) for (j=i+2;j<=k;______) if( ) t=a[i];a[i]:a[j];a[j]=t; put s(a) printf("/n");
