![]() |
A homework for C++ fellows :D
Write a function which returns true if the string parameter is a palindrome. A palindrome is any "word" which is the same forward and backward, eg, "radar", "noon", "20011002", ... The function should return false if the argument is not a palindrome. Assume the prototype is
bool isPalindrome(char * s1); Write a function which shortens a string s1 to n characters and stores the result in string s2. Assume the prototype is void truncate(char *s1, char * s2, int n); show us:D (not for me, for a friend who needs the answers badly - special case) |
Re: A homework for C++ fellows :D
man this is a program abt palindrom i dont know if its help u i tooke the course 2 years ago but i still have the programs so good luck.
-------------------------------------------------------------------- #include<iostream.h> bool pal(char [],int,int); int main() { const int size=11; char a[size]="a bc ba"; cout<<pal(a,0,size-2)<<endl; return 0; } bool pal(char a[],int low,int high) { if(a[low]==' ') { low++; return pal(a,low,high); } if(a[high]==' ') { --high; return pal(a,low,high); } if((low==high)||(low==high-1)) return true; if(a[low]==a[high]) return pal(a,++low,--high); else return false; } ------------------------------------------------------------- |
Re: A homework for C++ fellows :D
ex1:
bool ispalindrom (char *s1) { int length; for (int i=0; s1[i]!='\0'; i++) length=i+1; for (int j=0; j<length/2; j++) if (s1[j]!=s1[length-j-1]) return false; return true; } ex2: void truncate(char *s1, char *s2, int n=3) { for (int j=n; s1[j]!='\0'; j++) s1[j]='\0'; for (int i=0;i<n; i++) s2[i]=s1[i]; } i'm very sure of those:D and not really sure about what crazysimo did, but believe me this is the way it is done:D |
Re: A homework for C++ fellows :D
thank u guys, i'll update u about his grades :D
|
Re: A homework for C++ fellows :D
Hehehe
Thanks guys And thanks rami for posting the thread for me!!! |
Re: A homework for C++ fellows :D
write your own |-( :-P yalla bassita.. thread locked.
|
| All times are GMT +1. The time now is 08:58 PM. |
Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger