首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
下列给定程序中,函数fun()的功能是:用冒泡法对6个字符串按由大到小的顺序进行排序。 请改正程序中的错误,使它能得到正确结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。 试题程序: #includ
下列给定程序中,函数fun()的功能是:用冒泡法对6个字符串按由大到小的顺序进行排序。 请改正程序中的错误,使它能得到正确结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。 试题程序: #includ
admin
2009-02-15
94
问题
下列给定程序中,函数fun()的功能是:用冒泡法对6个字符串按由大到小的顺序进行排序。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include <conio.h>
#include <stdio.h>
#define MAXLINE 20
void fun(char *pstr[6])
{
int i,j;
char *p;
for(i=0;i<5;i++)
for(j=i+1;j<6;j++)
/*************found*************/
if(strcmp((pstr+i),(pstr+j))<0)
{
p=*(pstr+i);
*(pstr+i)=*(pstr+j);
/*************found*************/
*(pstr+j)=*p;
}
}
main()
{
int i;
char*pstr[6],str[6][MAXLINE];
clrscr();
for(i=0;i<6;i++)
pstr
=str
;
printf("/nEnter 6 string(1 string at each line):\n");
for(i=0;i<6;i++)
scanf("%s",pstr
);
fun(pstr);
printf("The strings after sorting:\n");
for(i=0;i<6;i++)
printf("%s\n",pstr
);
}
选项
答案
(1)错误:if(strcmp((pstr+i),(pstr+j))<0) 正确:if(strcmp(*(pstr+i),*(pstr+j))<0) (2) 错误:*(pstr+j)=*p; 正确:*(pstr+j)=p;
解析
错误1:本题旨在考查指针的引用方法。*(pstr+i)指字符串中下标为i的字符。错误2:*p是字符类型,而*(pstr+j)是指针类型,二者不能进行赋值运算。
转载请注明原文地址:https://jikaoti.com/ti/XxkiFFFM
本试题收录于:
二级C语言题库NCRE全国计算机二级分类
0
二级C语言
NCRE全国计算机二级
相关试题推荐
甲欲杀死乙,在乙饭碗里投放毒药,不料朋友丙分食了乙的饭菜,甲为了杀死乙,没有阻止丙,结果导致乙和丙均中毒死亡。甲对丙死亡所持的心理态度是()。
根据《行政处罚法》的规定,违法事实确凿且有法定依据,对公民处以()以下罚款的行政处罚的,可以当场作出行政处罚决定。
在当事人没有约定、法律亦无特别规定的情况下,买卖合同中的财产所有权的转移时间是()。
下列以平衡国际收支的暂时不平衡为主要功能的组织是()。
宪法作为国家根本大法要求其必须具有更高的稳定性.因此宪法的修改程序相对于其他法律也是更为严格的。我国宪法的修改权由()行使。
国家机构是我国宪法的主要内容之一。下列有关国家机构的说法正确的是()。
有一位百岁老人出生于二十世纪,2015年他的年龄各数字之和正好是他在2012年的年龄的各数字之和的三分之一,问该老人出生的年份各数字之和是多少(出生当年算作0岁)?
四只同样的瓶子内分别装有一定数量的油,每瓶和其他各瓶分别合称一次,记录千克数如下:8、9、10、11、12、13。已知四只空瓶的重量之和以及油的重量之和均为质数,求最重的两瓶内有多少油?
某出版社新招了10名英文、法文和日文方向的外文编辑,其中既会英文又会日文的小李是唯一掌握一种以上外语的人。在这10人中,会法文的比会英文的多4人,是会日文人数的两倍。问只会英文的有几人?
随机试题
实绩原则:指以下属的实绩为依据,给予适当方式的激励。根据上述定义,下列情况哪项遵循实绩原则?()
肝穿刺的禁忌证是
表面活性剂是能使溶液表面张力
A.侏儒症B.呆小症C.肢端肥大症D.巨人症E.黏液性水肿幼年时甲状腺激素分泌不足可引起
A.先兆流产B.难免流产C.过期流产D.不全流产E.完全流产容易发生失血性休克的是
圆管层流中,下述错误的是()。
2011年末,湖南省中小企业共计18.49万家,较上年增长11.0%,占全省企业总数的99.8%。2011年全省中小企业实现增加值达8154.32亿元,较上年增长16.1%;中小企业增加值占GDP的比重为41.5%,比上年提高0.8个百分点。中小企业拉动G
Whichofthefollowingisthegirl’slowgrade?
Whoismostlikelythespeaker?
Goingaroundatthetopofthemountain,wewatchedthefog________fromthevalleybelow;itseemedthatwehadenteredafairyl
最新回复
(
0
)