下面程序的功能是将一个字符串str的内容颠倒过来,请填空。
include<string.h>
main()
{ infi,j, [13] ;char str[]={"1234567"};
for(i=0,j=strlen(str) [14] ;i<j;i++,j--)
{k=str[i];str[i]=str[i];str[j]=k;}
printf("%s\n",str);}
第1题:
将输入的字符串按逆序输出,例如输入abcd,则按dcba顺序输出出来,请完善程序。 #include <stdio.h> #include <string.h> int main() { char *str, s[20]; int n; str=s; scanf("%s",str); n=strlen(str); while(--n>=0) { str=&s[ ________ ]; printf("%c",*str); } return 0; }
第2题:
下面的invert 函数的功能是将一个字符串str的内容颠倒过来,请填空。 void invert(char str[]) { int i,j, __________ ; //声明i,j下标和交换中间变量k for(i=0,j=________;i<j;i++,j--) //循环,头尾字符对调 { k=str[i]; str[i]=str[j]; str[j]=k; } }
第3题:
【填空题】下面程序的功能是在一个字符数组中查找一个指定的字符,若数组中含有该字符则输出该字符在数组中第一次出现的位置(下标值);否则输出-1。请分析程序填空。 #include <stdio.h> #include <string.h> main() {char c='a',t[50]; int n,k,j; gets(t); n=【1】; for(k=0,j=-1;k<n;k++) if(【2】) {j=k;break;} printf("%d",j); }
第4题:
将输入的字符串按逆序输出,例如输入abcd,则按dcba顺序输出出来,请完善程序。 #include <stdio.h> #include <string.h> int main() { char *str, s[20]; int n; str=s; scanf("%s",str); n=strlen(str); while(--n>=0) { str=&s[____]; printf("%c",*str); } return 0; }
第5题:
【填空题】下面程序的功能是在三个字符串中找出最小的。请分析程序填空。 #include <stdio.h> #include <string.h> main() {char s[20],str[3][20]; int i; for(i=0;i<3;i++) gets(str[i]); strcpy(s,【1】); if(strcmp(str[2],s)<0) strcpy(s,str[2]); printf("%sn",【2】); }