寫一個回文的程式

Home Home
引用 | 編輯 bing80329
2009-12-23 23:58
樓主
推文 x0
大一的作業要求我們寫回文的程式
題目 : 用C寫一個程式 , 判斷出輸入的字元(a,b,c...)是否為回文(abbba , aabaa ...)
使用程式: Microsoft Visual C++ 6.0
以下是我想到的 , 但是只能判斷4或5字元長度 , 請不吝指教
p.s. 希望可以提供我無限制字元長度的 , 感恩

#include <stdio.h>
char a(char q[] , int w);char s(char e[] , int r);
int main ()
{
int z ;
printf("size (請輸入4或是5) :\n") ..

訪客只能看到部份內容,免費 加入會員



獻花 x0
引用 | 編輯 rchockxm
2009-12-25 00:32
1樓
  
可以宣告成字串
字串比對也有專門函式處理的

不好意思,我沒在用 vc 的...

獻花 x0
引用 | 編輯 su5gsm
2010-11-10 00:06
2樓
  
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int n,s=0,t;
printf("input:n \n");
scanf("%d",&n);

for (t=n;t>0;t=((t-(t%10))/10)) s=s*10+(t%10); // t>0

if (s==n) printf("%d is palindrome\n",n);
else printf("%d is not palindrome\n",n);

system("pause");
return 0 ;
}

獻花 x0
引用 | 編輯 s90304a123
2010-11-18 12:48
3樓
  
不能用陣列的回文寫法就截然不同了
老師說現在不能用陣列 搞得我頭很疼....

獻花 x0
引用 | 編輯 kolong
2010-12-04 10:44
4樓
  
可宣告動態記憶,這樣就可以無限字串長度.

獻花 x0