网络信息传输的时候少不了各种信息的加密和解密。如A要传达给B的信息为:ILoveYou为了防止被人发现而暴露目标,A决定先使用一段程序进行加密。同时告诉B自己的加密程序,以确保B能够正确读懂A的心意。程序是这样的:我们定义一个数组str[]="HKnudT";和变量i=0;while(str[i]!=’/0’){str[i]=str[i]+1;i++;}请问B利用A的加密程序进行解密之后,看到了什么:()
第1题:
str是一个由数字和字母字符组成的字符串,由变量num传人字符串长度。请补充函数proc,该函数的功能是:把字符串str中的数字字符转换成数字并存放到整型数组bb中,函数返回数组bb的长度。 例如,str="abcl23de45f967",结果为:l234567。 注意:部分源程序给出如下。 请勿改动main函数和其他函数中的任何内容,仅在函数proc的横线上填入所编写的若干表达式或语句。 试题程序: include<stdio.h> define M 80 int bb[M]; int proc(char str[],int bb[],int num) { int i,n=0; for(i=0;i<num;i++) { if( 【1】 ) { bb[n]=【2】 ; n++; } } return 【3】 ; } void main { char str[M]; int num=0,n,i; printf("Enter a string:\n"); gets(str); while(str[num]) num++: n=proc(str,bb,num); printf("\nbb="); for(i=0;i<n;i++) printf("%d",bb[i]); }
第2题:
下列程序的运行结果为( )。
#include<stdio.h>
voidabc(Char*str)
{ inta,b,i,j;
for(i=j=0;str[i]!='\0';i++)
if(str[i]!='a')
str[j++]=str[i];
str[j]='\0';
}
void main()
{ char str[]="abcdef";
abc(str);
printf("str[]=%s",str);
}
A.str[]=bcdef
B.str[]=abcdef
C.str[]=a
D.str[]=ab
第3题:
下列程序的运行结果为( )。
#include<stdio.h>
voidabc(char*str)
{int a,b,i,j;
for(i=j=0;str[i]!='\0';i++)
if(str[i]!='a')
str[j++]=str[j];
str[j]='\0';
}
void main()
{char Str[]="abcdef';
abc(str);
printf("str[]=%s",str);
}
A.str[]=bcdef
B.str[]=abcdef
C.str[]=a
D.str[]=ab
第4题:
如下程序: #include<iostream.h> void main() { char str[2][5]={"1234","5678"),*p[2]; int i,j,s=0; for(i=0;i<2;i++)p[i]=str[i]; for(i=0;i<2;i++) for(j=0;p[i][j]>'\0';j+=2) s=10*s+p[i][j]-'0'; cout<<s; } 该程序的输出结果是( )。
A.1357
B.2468
C.3556
D.23678
第5题:
字符串str由数字字符组成(长度不超过5个字符),可看作任意进制的数,请补充函数fun(),该函数的功能是:把 str字符串转换成任意进制的数,结果保存在数组xx中,由函数返回转换后数组腆的实际长度。其中x表示str原来的进制, y表示要转换成的进制。例如,输入str=“1111”,x=2,y=10,结果输出:15。如果输入str=“15”, x=10,Y=2,结果输出: 1111。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
include <stdio.h>
include<stdlib.h>
include<string.h>
define N 8
int xx[N];
int fun(char *str,int x,int y)
{
int sum;
int i=0;
char *p=str;
for(i=0; i<N; i++)
xx[i]=0;
sum=*p-'0';
p++;
while (*p)
{
sum=【 】;
p++;
}
i=0;
while(sum!=0)
{
xx[i]=【 】;
【 】;
i++;
}
return i;
}
main ()
{
char str[6];
int i;
int n;
int x;
int y;
printf("Enter a string made up of '0' to
'9' digits character:");
gets(str);
if(strlen (str) >5)
{
printf("Error:string too longer!,
please input again!\n\n");
exit(0);
}
for(i=0;str[i];i++)
if(str[i]<'0'||str[i]>'9')
{
printf("Error:%c not is '0' to
'9' digits character!\n\n",
str[i]);
exit(0);
}
printf("The original string: ");
puts(str);
printf("\nINPUT x= ");
scanf("%d",&x);
printf("\nINPUT y= ");
scanf("%d",&y);
n=fun(str,x,y);
printf("\n%s is convered to",str);
for (i=n-1; i>=0; i--)
printf("%d",xx[i]);
}
第6题:
下列程序的输出结果是______。 char*fun(char*str,int n) { int i; char*p=str; for(i=0;i<10;i++,str++) *str='a'+i; return++p; } main() { char a[10]; printf("%s\n",fun(a,10)); }
A.ABCDEFGHIJ
B.abcdefghij
C.bcdefghij
D.不确定的值
第7题:
阅读下列程序,当运行函数时,输入asd af aa z67,则输出为 #include<stdio.h> #include<ctype.h> #include<string.h> int fun(char*str) { int i,j=0; for(i=0;str[i]!='\0';i++) if(str[i]!='')str[j++]=str[i]; str[j]='\0'; } main() { char str[81]; int n; clrscr(); printf("Input a string:"); gets(str); puts(str); fun(str); printf("%s\n",str); }
A.asdafaaz67
B.asdafaaz67
C.asd
D.z67
第8题:
阅读下列程序,当运行函数时,输入asd af aa z67,则输出为 #include <stdio.h> #include <ctype.h> #inelude <string.h> int fun(char *str) { int i,j=0; for(i=0;str[i]!='\0';i++) if(str[i]!='')str[j++]=str[i]; str[j]='\0'; } main() { char str[81]; int n; printf("Input a string:"); gets(str); puts(str); fun(str); printf("%s\n",str); }
A.asdafaaz67
B.asd af aa z67
C.asd
D.z67
第9题:
下列给定程序中,函数proc的功能是:读入一个字符串(长度<20),将该字符串中的所有字符按ASCII码升序排序后输出。 例如,输入opdye,则应输出deopy。 请修改程序中的错误,使它能得到正确结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。 试题程序: include<string.h> include<stdlib.h> include<conio.h> include<stdio.h> //****found**** int proc(char str[]) { char c; unsigned i,j; for(i=0;i<strlen(str)-1;i++) for(j=i+1;j<strlen(str);j++) if(str[i]>str[j]) { c=str[j]: //****found**** str[j]=str[i++]; str[i]=c; } } void main { char str[81]; system("CLS"); printf("\nPlease enter a character string:"); gets(str); printf("\n\nBefore sorting:\n%s",str); proc(str); printf("\nAfter sorting decendingly:\n %s",str); }
(1)错误:int proc(char str[])
正确:void proc(char、tr[])
(2)错误:str[j]=str[++];
正确:str[j]=str[i];
【解析】由主函数中的函数调用可知,函数proc没有返回值。因此,“int proc char str[])”应改为“void proc (char str[])”;由函数proc可知,if语句块完成将字符串str中的第i个元素与第j个元素相交换。因此,“str[j]=str [i++];”应改为“str[j]=str[i];”。
第10题:
阅读下列程序,当运行函数时,输入asd af aa z67,则输出为
#include <stdio.h>
#include <ctype.h>
#include <string.h>
int fun (char *str)
{ int i,j=0;
for(i=0;str[i]!=′ \0′;i++)
if(str[i]!=′ ′)str[j++]=str[i];
str[j]= ′\0′;
}
main()
{
char str[81];
int n;
printf("Input a string : ");
gets(str);
puts(str);
fun(str);
printf("%s\n",str);
}
A.asdafaaz67
B.asd af aa z67
C.asd
D.z67
第11题:
当运行以下程序时,输入abcd,程序的输出结果是:( )。
insert(char str[])
{int i;
i=strlen(str);
while(i>0)
{str[2*i]=str[i];str[2*i-1]='*';i--;}
printf("%s\n",str);
}
main()
{char str[40];
scanf("%s",str);insert(str);
}
第12题:
第13题:
下列给定程序中,函数proc的功能是:读入一个字符串(长度<20),将该字符串中的所有字符按ASCIl码升序排序后输出。 例如,输入opdye,则应输出deopy。 请修改程序中的错误,使它能得到正确结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。 试题程序: include%string.h> include%stdlib.h> include<conio.h> include<stdio.h> //****found**** int proc(char str[]) { char C; unsigned i,j; for(i=0;i<strlen(str)-1;i++) for(j=i+1;j<strlen(str);j4-+) if(str[i]>str[j]) { c=str[j]: //****found**** str[j]=str[i++]; str[i]=C; } } void main { char st/[81]; system("CLS"); printf("\nPlease enter a character string:"); gets(str); printf("\nknBefore sorting:\n %s",str); proc(str); printf("\nAfter sorting decendingly:\n %S",str); }
第14题:
阅读下列程序,当运行函数时,输入asd af aa z67,则输出为
#include
#include
#include
int fun (char *str)
{ int i,j=0;
for(i=0;str[i]!=′\0′;i++)
if(str[i]!=′ ′)str[j++]=str[i];
str[j]= ′\0′;
}
main()
{
char str[81];
int n;
clrscr();
printf("Input a string : ");
gets(str);
puts(str);
fun(str);
printf("%s\n",str);
}
A.asdafaaz67
B.asd af aa z67
C.asd
D.z67
第15题:
str是一个由数字和字母字符组成的字符串,由变量hum传入字符串长度。请补充函数fun( ),该函数的功能是:把字符串str中的数字字符转换成数字并存放到整型数组bb中,函数返回数组bb的长度。
例如:str=“Bcdl23e456hui890”,结果为:123456890。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
include<stdio.h>
define N 80
int bb[N];
int fun(char s[ ],int bb[ ],int num)
{
int i,n=0;
for(i=0;i<num;i++)
{
if(【 】)
{
bb[n]=【 】;
n++;
}
}
return【 】;
}
main()
{
char str[N];
int num=0,n,i;
printf("Enter a string:\n");
gets(str);
while(str[num])
num++;
n=fun(str,bb,num);
printf("\nbb=");
for(i=0;i<n;i++)
printf("%d",bb[i]);
}
第16题:
如下程序段#include <stdio.h>#include <ctype.h>#include <conio.h>int fun (char *str){ int i,j=0; for(i=0;str[i]!= ’\0’;i++) if(str[i]!= ’ ’)str[j++]=str[i]; str[j]= ’\0’;}main(){ char str[81]; int n; clrscr(); printf("Input a string : "); gets(str); fun(str); printf("%s\n",str);}当运行程序时,输入asd af aa z67<回车>,则输出是A.asdafaaz67 B.asd af aa z67 C.asd D.z67
第17题:
以下程序运行后输入:3,abcde<回车>,则输出结果是【 】
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",&n,s);
z=strlen(s);
for(i=1; i<=n; i++) move(s, z);
printf("%s\n",s);
}
第18题:
有以下程序#include "stdio.h"main() { char str[]="tomeetme",str1[]="toseeyou"; char *p=str,*p1=str1; int i; for(i=0;i if(*(p+i)==*(p1+i)) putchar(*(p+i)); printf("\n");}程序的运行结果是A.to B.tomeetC.toeeD.程序段不能通过编译
第19题:
阅读下列程序,写出程序的运行结果【 】。
include<iostream. h>
void main() { char str1[ ]: "Hello, World?;
char str2[100];
int i=0;
do{
if (str1[i]>= 'a'&& str1[i]<= 'z' )
str2[i]=str1[i]-32;
else
str2[i]=strl [i];
i++;
}while(strl[i]!='\0');
str2[i]='\0';
cout<<str1<<end1;
cout<<str2<<end1;
}
第20题:
下面程序的输出结果是_____。 main() { char str[10],c='a'; int i=0; for (;i<5;i++) str[i]=c++; printf("%s",str); }
A.abcde
B.a
C.不确定
D.bcdef
第21题:
阅读下列程序,当运行程序时,输入asd af aa z67,则输出为( )。 #include <sldio.h> int fun (char *str) { int i,j=0; for(i=0;str[i]! ='\0';i++) if(str[i]! =") str[j++]=str[i]; str[j]='\0'; } main() { char str[81]; int n; printf("Input a string:"); gets(str); fun(str); printf("%s\n",str); }
A.asdafaaz67
B.asd af aa z67
C.asd
D.z67
第22题:
下列程序的输出结果是______。
include<iostream.h>
int CalcDigital(char*str)
{
if(str= =NULL)
return 0;
int num_of_digital=0;
for(int i=0;str{i]!=0x0;i++)
if(str[i]<='9'&& str[i]>='0')
num_of_digital++;
return num_of_digital;
}
void main( )
{
char a[]="Beijing20080lympic";
cout<<CalcDigital(a)<<endl;
}
第23题:
下列程序的输出结果是 ()。 #include