算法的主要运算如下: While i<n do { s=0; While s<n do { s=s+1; } i=i+1; } 其中i的初值为0,s初值为0,“=”为赋值号。该算法的时间复杂度为()
A.O(2n)
B.O(n+log2n)
C.O(nlog2n)
D.O(n2)
第1题:
有以下程序: #include<stdio.h> #include<string.h> void fun(char s[][10],int n) { char t;int i,j; for(i=0;i<n-1;i++) for(j=i+1;j<n;j++) /*比较字符串的首字符大小,并交换字符串的首字符*/ if(s[i][0]>s[j][0]){t=s[i][0];s[i][0]=s[j][0];sEj][0]=t;} } main() {char s[5][10]={"bcc","bbcc","xy","aaaacc","aabcc"); fun(ss,5);printf("%s,%s\n",ss[0],ss[4]); } 程序的运行结果是( )。
A.xy,aaaacc
B.aaaacc,xy
C.xcc,aabcc
D.acc,xabcc
第2题:
有如下程序,运行输出的结果是 ______ 。 s=0 Do s=(s+1)*(s+2) n=n+1 Loop Until s>=30 Print n; s
A.0 1
B.30 30
C.4 30
D.3 182
第3题:
程序段s=i=0;do{i=i+1;s=s+i;}while(i=n);的时间复杂度为()。
A、O(n)
B、O(nlog2n)
C、O(n)
D、O(n/2)
第4题:
有如下程序 Private Sub Command1_Chck( ) s=0 DO s=(s+1) *(s+2) N=N+1 Loop Until s>=10 Prim N;s End Sub 运行后的输出结果是
A.0 1
B.30 30
C.4 30
D.2 12
第5题:
设有定义“chars[8];inti=0;”,下列不能将一行(不超过80个字符)带有空格的字符国正确读入的语句或语句组是( )。
A.gets(s);
B.while((s[i++]=getchar( ))!=\n);s[i]=\0;
C.seanf("%S",s);
D.do{scanf("%C",&s[i]);}while(s[i++]!=\n);s[i]=\0;
第6题:
有以下程序 #include<stdio.h> void main() { char s[]={"01aXy"};int i,n=0; for(i=0;s[i]!=0;i++) if(s[i]<='a'&&s[i]>='z')n++; printf("%d\n",n); } 程序运行后的输出结果是( )。
A.0
B.2
C.3
D.5
第7题:
以下能够正确计算n!的程序是( )。
A.Pfivate Sub Commgld1_LClick() n=5:x=1 Do x=x*1 i=i+1 Loop Whilei<n
B.Private Sub Command1_Click() n=5:x=1:i=1 Do x=x*1 i=i+1 Loop Whilei<n Print x End Sub
C.Pfivate Sub Command1_ C1ick() n=5:x=1:i=1 Do X=X*1 i=i+1 Loop While i<=n
D.Private Sub Command1_C1ick() n=5:x=1:i=1 Do X=X*1 i=i+1 Loop While i>n Print x End Sub
第8题:
有以下程序 main() { int i=0,s=0; do{ if(i%2){i++;continue;} i++; s+=i; }while(i<7); printf("%d\n",s); } 执行后输出结果是
A.16
B.12
C.28
D.21
第9题:
下列程序的运行结果是() classProgramx=0,y=-1; { publicstaticvoidMain(string[]args) { int i=0,s=1; do{s/=s+1;i++; } while(i<=10); Console.WriteLine(“i={0},s={1}”,i,s);
第10题:
不正确的字符串赋值或赋初值的方式是()
第11题:
下面是一段关于计算变量s的算法: ①变量s的初值是0 ②变量i从1起循环到n,此时变量s的值由下面的式子表达式计算 ③s=s+(-1)*i ④输出变量s的值 这个计算s值的算法中,s的代数式表示是()。
第12题:
n2
O(nlgn)
O(n)
O(n2)
第13题:
(30)设有定义:char s[81];int i=10;,以下不能将一行(不超过80个字符)带有空格的字符串真确读入的语句或语句组是
A gets(s)
B)while((s[i++]=getchar())!=”\n”;s=”\0”;
C)scanf(“%s”,s);
D)do{scanf(“%c”,&s);}while(s[i++]!=”\n”);s=”\0”;
第14题:
有以下程序 main( ) { int i=0,s=0; do{ if(i%2){i++;continue;} i++; s+=i; } while(i<7); printf("%d\n",s); } 执行后输出的结果是
A.16
B.12
C.28
D.21
第15题:
算法的主运算如下,其中i的初值为1,s的初值为0,“←”为赋值号。 while i<n do { for j←1 to n do s←s+a[i,j] i←i*2; 则该算法的时间复杂度为 ( )
A.O(2n)
B.O(n+log2n)
C.O(nlog2n)
D.O(n2)
第16题:
设有定义:char s[10];int i=0;,以下不能将一行(不超过100个字符)带有空格的字符串正确读入的语句或语句组是( )。
A.gets(s);
B.scanf("%s",s);
C.while((s[i++]=getchar())!='\n');s[i]='\0';
D.do{scanf("%c",&s[i]);}while(s[i++]!='\n');s[i]='\0';
第17题:
str是全部由小写字母字符和空格字符组成的字符串,由 num传入字符串的长度。请补充函数fun(),该函数的功能是:统计字符串str中的单词个数,结果由变量num传回。每个单词之间都由空格隔开,并且字符串str开始不存在空格。
例如:str=“how do you do”,结果为:num=4。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
include <stdio.h>
define N 80
void fun(char *s,int *num)
{
int i,n=0;
for(i=0;【 】;i++)
{
if(s[i]>='a',&&s[i]<='z',&&(s[i+1)==’’||s[i+1]=='\0'))
【 】;
}
【 】;
}
main()
{
char str[N];
int num=0;
printf("Enter a string:\n");
gets(str);
while(str[num])
num++;
fun(str,&num);
printf("The number of word is:
%d\n\n",num);
第18题:
以下能够正确计算n!的程序是______。
A.Private Sub Commeadl_Click() n=5: x=1 Do x=x*i i=i+1 Loop While i<n Print x End Sub
B.Private Sub Command1_Click() n=5: x=1: i=1 Do x=x*i i=i+1 Loop While i<n Print x End Sub
C.Private Sub Command1_Click() n=5: x=1: i=1 Do x=x*i i=i+1 Loop Whilei<=n Print x End Sub
D.Private Sub Commsndl_Click() n=5: x=1: i=1 Do x=x*i i=i+1 Loop While i>n Print x End Sub
第19题:
执行下列程序,最后S的显示值为( )。 SET TALK OFF s=0 i=2 x=10 DO WHILE s<=x s=s+i i=i+1 ENDDO ?s SET TALK ON
A.12
B.14
C.16
D.18
第20题:
执行如下程序,最后S的显示值为 SET TALK OFF S=0 i=5 X=11 DO WHILE s<=X s=s+i i=i+1 ENDDO ?s SET TALK ON
A.5
B.11
C.18
D.26
第21题:
以下能正确计算1×2×3×…×10的程序段是()。
第22题:
若变量已正确定义,以下不能正确计算1+2+3+4+5的程序段是()。
第23题: