字符串反转问题 [英] String reversing problem
问题描述
为什么不:
#include< stdio.h>
void reverse(char [],int) ;
main()
{
char s [5];
s [0] =''h'';
s [1] =''e'';
s [2] =''l'';
s [3] =''l'';
s [4] =''o'';
reverse(s,5);
for(int i = 0; i< = 4; i ++)
putchar(s [i]);
返回0 ;
}
void reverse(char s [],int num_elements)
{
int i,j;
for(i = 0,j = num_elements-1;(i< = num_elements-1)&&(j> = 0); i ++, j--)
s [i] = s [j];
}
输出:
olleh
?
Why doesn''t:
#include <stdio.h>
void reverse(char[], int);
main()
{
char s[5];
s[0] = ''h'';
s[1] = ''e'';
s[2] = ''l'';
s[3] = ''l'';
s[4] = ''o'';
reverse(s, 5);
for (int i=0; i<=4; i++)
putchar(s[i]);
return 0;
}
void reverse(char s[], int num_elements)
{
int i, j;
for (i=0,j=num_elements-1; (i<=num_elements-1) && (j>=0); i++,j--)
s[i] = s[j];
}
output:
olleh
?
推荐答案
Albert写道:
为什么不:
#include< stdio.h>
void reverse(char [],int);
main()
{
char s [5];
s [0] =''h'';
s [1] =''e'';
s [2] =''l'';
s [3] =''l'';
s [4] =''o'';
反向(s,5) ;
for(int i = 0; I< = 4; i ++)
putchar(s [i]);
返回0;
}
void reverse(char s [],int num_elements)
{
int i,j;
for(i = 0,j = num_elements-1;(i< = num_elements-1)&&(j> = 0); i ++, j--)
想想当i == 4和j == 1时会发生什么。 [他们仍然打电话给他们吗?
它'桌面检查''?
s [i] = s [j];
}
>输出:
olleh
?
Why doesn''t:
#include <stdio.h>
void reverse(char[], int);
main()
{
char s[5];
s[0] = ''h'';
s[1] = ''e'';
s[2] = ''l'';
s[3] = ''l'';
s[4] = ''o'';
reverse(s, 5);
for (int i=0; i<=4; i++)
putchar(s[i]);
return 0;
}
void reverse(char s[], int num_elements)
{
int i, j;
for (i=0,j=num_elements-1; (i<=num_elements-1) && (j>=0); i++,j--)
Think what happens when i==4 and j==1, for example. [Do they still call
it `desk checking''?]
s[i] = s[j];
}
output:
olleh
?
HTH,
--ag
-
Artie Gold - 德克萨斯州奥斯汀
http://goldsays.blogspot.com (新帖子8/5)
http://www.cafepress.com/goldsays
如果你没有什么可隐瞒的,你就不会尝试!
HTH,
--ag
--
Artie Gold -- Austin, Texas
http://goldsays.blogspot.com (new post 8/5)
http://www.cafepress.com/goldsays
"If you have nothing to hide, you''re not trying!"
使用这个
#include< stdio.h>
void reverse(char [],int);
main()
{
char s [5];
int i;
s [0] =''h'';
s [1] =''e'';
s [2] =''l '';
s [3] =''l'';
s [4] =''o'';
reverse(s ,5);
for(i = 0; i< = 4; i ++)
putchar(s [i]);
返回0;
}
void reverse(char s [],int num_elements)
{
int i,j;
for(i = 0,j = num_elements- 1; (i< = num_elements-1)&& (J> = 0); i ++,j--)
s [i] = s [j];
}
use this one
#include <stdio.h>
void reverse(char[], int);
main()
{
char s[5];
int i;
s[0] = ''h'';
s[1] = ''e'';
s[2] = ''l'';
s[3] = ''l'';
s[4] = ''o'';
reverse(s, 5);
for ( i = 0; i<=4; i++)
putchar(s[i]);
return 0;
}
void reverse(char s[], int num_elements)
{
int i, j;
for (i=0,j=num_elements-1; (i<=num_elements-1) && (j>=0); i++,j--)
s[i] = s[j];
}
''桌面检查'是什么意思?'
What do you mean by ''desk checking''?
这篇关于字符串反转问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!