tag:blogger.com,1999:blog-5531960551406702359.post6171390806051213687..comments2024-03-29T12:14:02.680+05:30Comments on C Programming | Computer | Ms-Excel: Palindrome using pointerDinesh Berahttp://www.blogger.com/profile/17779626530091691900noreply@blogger.comBlogger7125tag:blogger.com,1999:blog-5531960551406702359.post-85911679083265786042014-02-01T13:44:32.447+05:302014-02-01T13:44:32.447+05:30this code gives the same answer for all the string...this code gives the same answer for all the strings...i.e. String is aplindromeAnonymoushttps://www.blogger.com/profile/17853927821836223691noreply@blogger.comtag:blogger.com,1999:blog-5531960551406702359.post-85362951170183998272014-02-01T13:42:52.356+05:302014-02-01T13:42:52.356+05:30I executed this..
Compilation : Passed
Test Case 1...I executed this..<br />Compilation : Passed<br />Test Case 1 Passed<br />Input Expected Output Actual Output<br />1 2 3 4 5 5 4 3 2 1 yes yes<br />Test Case 2 Wrong Answer<br />Input Expected Output Actual Output<br />1 2 3 4 5 6 7 8 9 0 no yes<br />it meant that the string ":1 2 3 4 5 6 7 8 9 0" is a palindrome<br /><br />why so?<br /><br />Anonymoushttps://www.blogger.com/profile/17853927821836223691noreply@blogger.comtag:blogger.com,1999:blog-5531960551406702359.post-69387085085106937462013-04-24T17:00:57.318+05:302013-04-24T17:00:57.318+05:30Dinesh sir...why you are decrementing the value of...Dinesh sir...why you are decrementing the value of p in the second for loop and again in the later part of the program <br />if (*p == *t) is true , then one more time p is decremented?? please explain the reasonAnonymoushttps://www.blogger.com/profile/14869207303096534717noreply@blogger.comtag:blogger.com,1999:blog-5531960551406702359.post-37691474462188587832012-11-02T13:57:15.655+05:302012-11-02T13:57:15.655+05:30@Rubi,
*p==*t is comparison of character.
*p repr...@Rubi,<br /><br />*p==*t is comparison of character.<br />*p represent the last character of string, and<br />*t represent the beginning character of string<br />and both are equal then<br />p decrease to one i.e. second last character, and<br />t increase to one i.e. second value of character.<br /><br />Hence, this condition check equality both side(i.e. left side and right side) character one by one, If this condition found any unequal then compiler goes to "else" part execute break; statement and next its check "string is palindrome or not" using t>p.Dinesh Berahttps://www.blogger.com/profile/17779626530091691900noreply@blogger.comtag:blogger.com,1999:blog-5531960551406702359.post-78273506180096640612012-11-01T20:31:17.814+05:302012-11-01T20:31:17.814+05:30
what is the logic behind this?
{
if(*p==*t)
...<br /><br />what is the logic behind this?<br />{<br /> if(*p==*t)<br /> {<br /> p--;<br /> t++;<br /> }<br /> else<br /> break;Rubihttps://www.blogger.com/profile/08192416493511703054noreply@blogger.comtag:blogger.com,1999:blog-5531960551406702359.post-79366379454342397172012-05-09T18:10:18.928+05:302012-05-09T18:10:18.928+05:30The logic behind this loop is comparison of charac...The logic behind this loop is comparison of character(starting character and ending character):<br /><br />Let's assume str = MADAM<br />01234<br /><br />for(p=str; *p!='\0'; p++);<br />for(t=str,p--; p>=t; )<br /><br />In first for loop is has ; so p value is going to end of string i.e. NULL.<br /><br />Now we take an another char pointer say t.<br /><br />In second for loop we set t=str and p--<br />i.e. current values of t and p is as M and M respectively. And its run process till all checking starting and ending character by character.Dinesh Berahttps://www.blogger.com/profile/17779626530091691900noreply@blogger.comtag:blogger.com,1999:blog-5531960551406702359.post-65813873271805724502012-05-09T16:48:20.037+05:302012-05-09T16:48:20.037+05:30What is the logic behind this?
for(t=str, p-- ; p&...What is the logic behind this?<br />for(t=str, p-- ; p>=t; )Anonymousnoreply@blogger.com