题目内容 (请给出正确答案)
[主观题]

阅读以下说明和C语言程序,将应填入(n)处的字句写在对应栏内。【说明】 Fibonacci数列A={1,1,2,2,5,8

阅读以下说明和C语言程序,将应填入(n)处的字句写在对应栏内。

【说明】

Fibonacci数列A={1,1,2,2,5,8,…)有如下性质:

a0=a1=1

ai=ai-1+ai-2,i>1

对于给定的n,另外有一个由n个元素组成的数列xn,该数列中各元素的值为:

xi=ai/ai+1,i=0,1,…,n

现要求对xn中的元素按升序进行排序,然后以分数形式输出排序后的xn。例如n=5时,排序前的xn={1/1,1/2,2/3,3/5,5/8},排序后的xn={1/2,3/5,5/8,2/3,1/1}。程序中函数make()首先生成排序前的xn,然后调用函数sort()进行排序,最后输出所求结果。

【程序】

include <stdio.h>

include <stdlib.h>

include <malloc.h>

struct fact

{

long m,n;

};

void sort(int n,struct fact *p)

{

int a;

long s,t,u,v;

struct fact *q,*end;

for(end=p+(n-1),a=1;a;end--)

for(a=0,q=p;q<end;p++)

{

s=q->m;

t=q->n;

u=(q+1)->m;

v=(q+1)->n;

if((1) )

{

q->m=u;

(2)

(3)

(q+1)->n=t;

a=1;

}

}

}

void make(int n)

{

int i;

long a,b,c;

struct fact *x,*y;

x=(struct fact *)malloc(sizeof(struct fact)*n);

x->m=1:

x->n=1;

for(a=1,b=1,i=2;i<=n;i++)

{

(4)

a=b;

b=c;

(x+(i-1))->m=a;

(x+(i-1))->n=b;

}

(5)

printf("x%d={%1d/%1d",n,x->m,x->n);

for(y=x+1;y<x+n;y++)

printf(",%1d/%1d",y->m,y->n);

printf("}\n");

free(x);

}

void main()

{

int n;

printf("input n:");

scanf("%d",&n);

make(n);

}

提问人:网友i8i800 发布时间:2022-01-06
参考答案
查看官方参考答案
如搜索结果不匹配,请 联系老师 获取答案
更多“阅读以下说明和C语言程序,将应填入(n)处的字句写在对应栏内…”相关的问题
第1题
阅读以下函数说明和C语言函数,将应填入(n)处的字句写在对应栏内。 【程序2.1说明】 求所有满足如下

阅读以下函数说明和C语言函数,将应填入(n)处的字句写在对应栏内。

【程序2.1说明】

求所有满足如下条件的三位数:它除以11得的商等于它各位数字的平方和。例如 550,除以11商为50,50=52+52+02。

【程序2.1】

void main()

{

int i, j,n,s;

for(i=100;i<=999;i++)

{

n=i;

j=n/11;

s=0;

while((1))

{

(2)

n/=10;

}

if((3))

printf("%d\t",i);

}

}

【程序2.2说明】

本程序输入一字符串,将其中的大写字母改变成小写字母。

【程序2.2】

void main()

{

int i=0;

char s[120];

scanf("%s",s);

while((4))

{

if((5))

s[i]=s[i]- 'A'+'a';

i++;

}

printf("%s\n",s);

}

点击查看答案
第2题
阅读以下函数说明和C语言函数,将应填入(n)处的字句写在对应栏内。 [说明1] 本程序输入一字符串,

阅读以下函数说明和C语言函数,将应填入(n)处的字句写在对应栏内。

[说明1]

本程序输入一字符串,并将其中的大写字母变成小写字母。

[C函数1]

include<stdio.h>

void main()

{ int i=0;

char s[120];

printf("Enter a string.\n");

scanf("%s",s);

while((1) ){

if((2) )

s[i]=s[i]-'A'+'a';

i++;

}

printf("%s\n",S);

}

[说明2]

本程序用二分法,在已按字母次序从小到大排序的字符数组list[len]中,查找字符c,若c在数组中,函数返回字符c在数组中的下标,否则返回-1。

[C函数2]

int search(char list[],char c,int len)

(intlow=0,high=len-1,k;

while((3) );

k=(10w+high)/2;

if((4) ) return k;

else if((5) )high=k-1;

else low=k+1;

return -1;

}

点击查看答案
第3题
阅读以下说明和C语言函数,将应填入(n)处的字句写在对应栏内。【说明】 下面的程序构造一棵以二叉链

阅读以下说明和C语言函数,将应填入(n)处的字句写在对应栏内。

【说明】

下面的程序构造一棵以二叉链表为存储结构的二叉树算法。

【函数】

BTCHINALR *createbt (BTCHINALR *bt )

{

BTCHINALR *q;

struct node1 *s [30];

int j,i;

char x;

printf ("i,x =" ); scanf ("%d,%c",&i,&x );

while (i!=0 && x!='$')

{ q = (BTCHINALR* malloc (sizeof (BTCHINALR )); //生成一个结点

(1);

q->1child = NULL;

q->rchild = NULL;

(2);

if((3);)

{j=i/2 //j为i的双亲结点

if(i%2==0

(4) //i为j的左孩子

else

(5) //i为j的右孩子

}

printf ("i,x =" ); scanf ("%d,%c",&i,&x ); }

return s[1]

}

点击查看答案
第4题
阅读以下说明和C语言函数,将应填入(n)处的语句写在对应栏内。【说明】 下面的程序构造一棵以二叉链

阅读以下说明和C语言函数,将应填入(n)处的语句写在对应栏内。

【说明】

下面的程序构造一棵以二叉链表为存储结构的二叉树。

【函数】

BitTree *createbt(BitTree *bt)

{

BitTree *q;

struct node *s[30];

int j,i;

char x;

printf("i,x=");

scant("%d,%c",&i,&x);

while(i!=0 && x!='$')

{

q=(BitTree *}malloc(sizeof(BitTree));//生成一个结点

(1);

q->lchild=NULL;

q->rchild=NULL;

(2) ;

if ((3))

{

j=i/2; // j为i的双亲结点

if(i%2==0)

(4); //i为j的左孩子

else

(5); //i为j的右孩子

}

printf("i,x=");

scanf("%d,%c",&i,&x);

}

return s[i];

}

点击查看答案
第5题
阅读以下函数说明和C语言函数,将应填入(n)处的字句写在对应栏内。 【程序2.1说明】 已知一个排好序

阅读以下函数说明和C语言函数,将应填入(n)处的字句写在对应栏内。

【程序2.1说明】

已知一个排好序的数组,现输入一个数,要求按原来的顺序规律,将它插入到数组中。

【程序2.1】

include <stdioh>

define N 100

void main()

{

float a[N+l],x;

int i,p;

printf("输入已经排好序的数列: ");

for(i=0; i<N; i++)

scanf(%f",&a[i]);

printf("输入要插入的数:");

scanf("%f",&x);

for(i=0,p=N; i<N; i++)

if(x<a[i])

{

(1)

break;

}

for(i=N-1; i>=p; i--)

(2)

(3)

for(i=0; i<=N; i++)

prinff("%f\t",a[i]);

}

【程序2.2说明】

本程序用变量count统计文件中字符的个数。

【程序2.2】

include <stdio.h>

include <stdlib.h>

void main()

{

FILE *fp;

long count=0;

if((fp=fopen("letter.txt","r"))==NULL)

{

printf("can not open file\n");

exit(0);

}

while(!feof(fp))

{

(4)

count++;

}

printf("count=%d\n",count);

(5)

}

点击查看答案
第6题
阅读以下函数说明和C语言函数,将应填入(n)处的字句写在对应栏内。【说明】 实现矩阵(3行3列)的转置(

阅读以下函数说明和C语言函数,将应填入(n)处的字句写在对应栏内。

【说明】

实现矩阵(3行3列)的转置(即行列互换)。

例如,输入下面的矩阵:

100 200 300

400 500 600

700 800 900

程序输出:

100 400 700

200 500 800

300 600 900

【函数】

int fun(int array[3][3])

{

int i,j,t;

for(i=0;(1);i++)

for(j=0;(2);j++)

{

t=array[i][j];

(3);

(4);

}

}

}

main()

{

int i,j;

int array[3][3]={{100,200,300},{400,500,600},{700,800,900}};

clrscr();

for (i=0;i<3;i++)

{

for(j=0;j<3;j++)

printf("%7d",array[i][j]);

printf("\n");

}

fun((5));

printf("Converted array:\n");

for(i=0;i<3;i++)

{

for(j=0;j<3;j++)

printf("%7d",array[i][j]);

printf("\n");

}

}

点击查看答案
第7题
阅读以下函数说明和C语言函数,将应填入(n)处的语句写在对应栏内。 【函数1.1说明】 本程序可以打印

阅读以下函数说明和C语言函数,将应填入(n)处的语句写在对应栏内。

【函数1.1说明】

本程序可以打印出如下图形(菱形):

*

***

*****

*******

*****

***

*

【函数2.1】

main()

{

int i,j,k;

for(i=0;i<=3;i++)

{

for(j=0;j<=2-i;j++)

printf(" ");

for((1))

printf("*");

printf("\n");

}

for(i=0;i<=2;i++)

{

for((2))

printf(" ");

for(k=0;k<=4-2*i;k++)

printf("*");

printf("\n");

}

}

【函数2.2说明】

通过本程序,可以从键盘输入一个字符串,将小写字母全部转换成大写字母,然后输出到一个磁盘文件“CsaiWgm”中保存,输入的字符串以“!”结束。

【函数2.2】

include "stdio.h"

main()

{

FILE *fp;

char str[100],filename[10];

int i=0;

if((fp=fopen("CsaiWgm","w"))==NULL)

{

printf("cannot open the file\n");

exit(0);

}

printf("please input a string:\n");

gets(str);

while((3))

{

if(str[i]>='a'&&str[i]<='z')

str[i]=(4);

fputc(str[i],fp);

(5);

}

fclose(fp);

fp=fopen("CsaiWgm","r");

fgets(str,stden(str)+1,fp);

printf("%s\n",str);

fclose(fp);

}

点击查看答案
第8题
阅读以下说明和C语言程序,将应填入(n)处的字句写在对应栏内。【说明】 计算n的合数。一个整数n可以有

阅读以下说明和C语言程序,将应填入(n)处的字句写在对应栏内。

【说明】

计算n的合数。一个整数n可以有多种划分,使其划分的一列整数之和为n。例如,整数5的划分为:

5

4 1

3 2

3 1 1

2 2 1

2 1 1 1

1 1 1 1 1

共有7种划分。这种划分的程序如下所示。

【程序】

include <stdio.h>

int n[1000],m,k;

void output sum()

{

int j;

for(j=0;n[j]!=0;j++)

printf("%d\t",n[j]);

printf("\n");

}

void sum(int i)

if(m-n[i]<n[i])

{ m=m-n[i];

(1)

i++;

n[i+1]=0;

}

else

{

(2)

m-=n[i];

i++;

}

if(m!=n[i])

sum(i);

else

output_sum();

if(n[i]>1)

{

n[i]--;

(3)

}

else

{

while((n[i]==1)&&(i>O))

{

i--;

(4)

}

if(i!=0)

{

(5)

sum(i);

}

}

}

void main()

{

int i;

scanf("%d",&n[0]);

m=k=n[0];

for(i=1;i<=k;i++)

n[i]=0;

while(n[0]!=1)

{

n[0]--;

i=0;

sum(0);

m=k;

}

}

点击查看答案
第9题
阅读下列函数说明和C代码,将应填入(n)处的字句写在对应栏内。 【说明2.1】 以下C语言函数用二分插

阅读下列函数说明和C代码,将应填入(n)处的字句写在对应栏内。

【说明2.1】

以下C语言函数用二分插入法实现对整型数组a中n个数的排序功能。

【函数2.1】

void fun1 (int a[])

{ int i,j,k,r,x,m;

for(i=2;i<=n;i++)

{ (1);

k=1;r=i-1;

while(k<=r)

{ m=(k+r)/2;

if(x<a[m])r=m-1;

else (2);

}

for(j=i-1;j>=k;j--)

a[j+l]=a[j];

(3);

}

}

【说明2.2】

以下程序可以把从键盘上输入的十进制数(long型)以二~十六进制形式输出。

【程序2.2】

include<stdio.h>

main()

{ charb[16]={'0','l','2','3 ,4,'5','6','7','8','9','A','B','C','D','E','F'};

int c[64],d,i=0,base;

long n;

printf("enter a number:\n");

scanf("%1d",&n);

printf("enter new basc:\n");

scanf("%d", &base);

do

{ c[i]=(4);

i++; n=n/base;

} while(n!=0);

printf("transmite new base:\n");

for(--i;i>=0;--i)

{ d=c[i];

printf("%c",(5));

}

}

点击查看答案
第10题
()阅读下列说明和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); }

点击查看答案
第11题
阅读以下说明和C语言程序,将应填入(n)处的字句写在对应栏内。 【说明】 以字符流形式读入一个文件,

阅读以下说明和C语言程序,将应填入(n)处的字句写在对应栏内。

【说明】

以字符流形式读入一个文件,从文件中检索出6种C语言的关键字,并统计、输出每种关键字在文件中出现的次数。本程序中规定:单词是一个以空格或'\t'、'\n'结束的字符串。其中6种关键字在程序中已经给出。

【程序】

include <stdio.h>

include <stdlib.h>

FILE *cp;

char fname[20], buf[100];

int NUM;

struct key

{ char word[10];

int count;

}keyword[]={ "if", 0, "char", 0, "int", 0,

"else", 0, "while", 0, "return", 0};

char *getword (FILE *fp)

{ int i=0;

char c;

while((c=getc(fp))!= EOF &&(1));

if(c==EOF)

return (NULL);

else

buf[i++]=c;

while((c=fgetc(fp))!=EOF && c!="&& c!='\t' && c!='\n' )

buf[i++]=c;

buf[i]='\0';

return(buf);

}

void lookup(char *p)

{ int i;

char *q, *s;

for(i=0; i<NUM; i++)

{ q=(2);

s=p;

while(*s && (*s==*q))

{ (3))

if((4))

{ keyword[i].count++;

break;

}

}

return;

}

void main()

{ int i;

char *word;

printf("lnput file name:");

scanf("%s", fname);

if((cp=fopen(fname, "r"))==NULL)

{ printf("File open error: %s\n", fname);

exit(0);

}

NUM=sizeof(keyword)/sizeof(struct key);

while((5))

lookup(word);

fclose(cp);

for(i=0;i<NUM;i++)

printf("keyword:%-20s count=%d\n",keyword[i].word,keyword[i].count);

}

点击查看答案
账号:
你好,尊敬的用户
复制账号
发送账号至手机
密码将被重置
获取验证码
发送
温馨提示
该问题答案仅针对搜题卡用户开放,请点击购买搜题卡。
马上购买搜题卡
我已购买搜题卡, 登录账号 继续查看答案
重置密码
确认修改
欢迎分享答案

为鼓励登录用户提交答案,简答题每个月将会抽取一批参与作答的用户给予奖励,具体奖励活动请关注官方微信公众号:简答题

简答题官方微信公众号

警告:系统检测到您的账号存在安全风险

为了保护您的账号安全,请在“简答题”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!

微信搜一搜
简答题
点击打开微信
警告:系统检测到您的账号存在安全风险
抱歉,您的账号因涉嫌违反简答题购买须知被冻结。您可在“简答题”微信公众号中的“官网服务”-“账号解封申请”申请解封,或联系客服
微信搜一搜
简答题
点击打开微信