<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-3950550929622410891</id><updated>2024-09-11T22:01:09.247+05:30</updated><category term="solved"/><category term="c"/><category term="programming"/><category term="puzzle"/><category term="unsolved"/><category term="c++"/><category term="find-an-answer"/><category term="logical"/><category term="string"/><category term="cin"/><category term="excel"/><category term="gold coin"/><category term="introduction"/><category term="linked list"/><category term="mathematical"/><category term="multiplication"/><category term="namespace"/><category term="reverse"/><category term="swap"/><category term="weights"/><title type='text'>Find An Answer</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://find-an-answer.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3950550929622410891/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://find-an-answer.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Sarfraaz Ahmed</name><uri>http://www.blogger.com/profile/05627188302724560435</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>10</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-3950550929622410891.post-6737429266301928096</id><published>2011-02-24T20:32:00.000+05:30</published><updated>2011-02-24T20:32:13.929+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="c"/><category scheme="http://www.blogger.com/atom/ns#" term="programming"/><category scheme="http://www.blogger.com/atom/ns#" term="puzzle"/><category scheme="http://www.blogger.com/atom/ns#" term="unsolved"/><title type='text'>Boolean</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;Here&#39;s a very simple program with standard questions :)&lt;br /&gt;
&lt;br /&gt;
Question 1&amp;gt; : Is there anything wrong with this code ?&lt;br /&gt;
Question 2&amp;gt; : Will this code compile ?&lt;br /&gt;
Question 3&amp;gt; : Are there any specific options that I should give for compiling it ?&lt;br /&gt;
Question 4&amp;gt; : What is the output of this program ?&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;textarea cols=&quot;50&quot; name=&quot;c-code&quot; readonly=&quot;readonly&quot; rows=&quot;30&quot; style=&quot;background-color: #eaeaea;&quot;&gt;// Replace [ with less than symbol
// Replace ] with greater than symbol

#include [stdio.h]

int main()
{
 bool x = 2;

 switch(x)
 {
  case 0 :
   printf(&quot;Found Zero\n&quot;);
   break;
  case 1 :
   printf(&quot;Found One\n&quot;);
   break;
  case 2 :
   printf(&quot;Found Two\n&quot;);
   break;
  default :
   printf(&quot;Found Nothing\n&quot;);
   break;
 }
 return 0;
}

&lt;/textarea&gt;&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://find-an-answer.blogspot.com/feeds/6737429266301928096/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://find-an-answer.blogspot.com/2011/02/boolean.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3950550929622410891/posts/default/6737429266301928096'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3950550929622410891/posts/default/6737429266301928096'/><link rel='alternate' type='text/html' href='http://find-an-answer.blogspot.com/2011/02/boolean.html' title='Boolean'/><author><name>Sarfraaz Ahmed</name><uri>http://www.blogger.com/profile/05627188302724560435</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3950550929622410891.post-2796884729939429411</id><published>2010-11-04T10:40:00.000+05:30</published><updated>2010-11-04T10:40:26.181+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="excel"/><category scheme="http://www.blogger.com/atom/ns#" term="solved"/><title type='text'>Excel formula not updating</title><content type='html'>I came across this strange problem where all of a sudden my excel sheet suddenly stopped calculating the formulas on its own. I had to click the &quot;Save&quot; button to make excel do the calculations.&lt;br /&gt;
&lt;br /&gt;
Normally, I enter a value in a cell and expect the value in another cell to be automatically updated based on the formula present in it. It was frustrating to find that this suddenly stopped working !!!&lt;br /&gt;
&lt;br /&gt;
A simple google gave me this link.&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.techsupportforum.com/microsoft-support/microsoft-office-support/163598-solved-excel-formula-not-updating.html&quot;&gt;http://www.techsupportforum.com/microsoft-support/microsoft-office-support/163598-solved-excel-formula-not-updating.html&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
And it saved my day :)&lt;br /&gt;
&lt;br /&gt;
Pressing F9 would make excel do the calculations without me clicking on &quot;Save&quot; button.&lt;br /&gt;
But, an even better thing was to change the setting under Tools-&amp;gt; Options-&amp;gt; Calculations to &quot;Automatic&quot; .. and vroom the calculations starting getting updated &quot;automatically&quot; as earlier.&lt;br /&gt;
&lt;br /&gt;
I have no idea how I ended up in this but seeing it work back make my day !!!</content><link rel='replies' type='application/atom+xml' href='http://find-an-answer.blogspot.com/feeds/2796884729939429411/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://find-an-answer.blogspot.com/2010/11/excel-formula-not-updating.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3950550929622410891/posts/default/2796884729939429411'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3950550929622410891/posts/default/2796884729939429411'/><link rel='alternate' type='text/html' href='http://find-an-answer.blogspot.com/2010/11/excel-formula-not-updating.html' title='Excel formula not updating'/><author><name>Sarfraaz Ahmed</name><uri>http://www.blogger.com/profile/05627188302724560435</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3950550929622410891.post-1137418110043929862</id><published>2010-06-09T18:05:00.000+05:30</published><updated>2014-05-29T08:47:36.006+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="c++"/><category scheme="http://www.blogger.com/atom/ns#" term="cin"/><category scheme="http://www.blogger.com/atom/ns#" term="find-an-answer"/><category scheme="http://www.blogger.com/atom/ns#" term="programming"/><category scheme="http://www.blogger.com/atom/ns#" term="solved"/><title type='text'>[ Solved ] Why does cin not wait for Enter ?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;Question&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
When I compile and execute the following C++ program, I find it strange that the program does not wait for the user to hit &#39;Enter&#39;. What could be the possible explanation for this behaviour ? How can we solve this anamoly ?&lt;br /&gt;
&lt;br /&gt;
&lt;script src=&quot;https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js?skin=sunburst&quot;&gt;&lt;/script&gt;

&lt;br /&gt;
&lt;pre class=&quot;prettyprint linenums&quot;&gt;#include &amp;lt;iostream&amp;gt;

using namespace std;

int main()
{
 string key;

 cout &amp;lt;&amp;lt; &quot;Enter a word\n&quot;;
 cin &amp;gt;&amp;gt; key;
 cout &amp;lt;&amp;lt; &quot;You entered : &quot; [[ key [[ &quot;\n&quot;;
 cout &amp;lt;&amp;lt; &quot;Hit Enter to proceed...&quot;;
 key = cin.get();

 if (key == &quot;\n&quot;)
  cout &amp;lt;&amp;lt; &quot;Exit\n&quot;;
 else
  cout &amp;lt;&amp;lt; &quot;Error\n&quot;;

 return 0;
}
&lt;/pre&gt;
&lt;!-- &lt;/textarea&gt;&lt;/pre&gt;
--&gt;

The output of the program is something like this&lt;br /&gt;
&lt;br /&gt;
&lt;!-- &lt;pre&gt;&lt;textarea cols=&quot;50&quot; name=&quot;c-code&quot; readonly=&quot;readonly&quot; rows=&quot;7&quot; style=&quot;background-color: #eaeaea;&quot;&gt; --&gt;

&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;# ./wait 
Enter a word
india
You entered : india
Hit Enter to be proceed...Exit
# 
&lt;/pre&gt;
&lt;!-- &lt;/textarea&gt;&lt;/pre&gt;
--&gt;

&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;Answer&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Before writing the answer, it makes more sense to understand the problem. When you read input from the keyboard, the input is read through an input stream. The behaviour of this stream is to capture keyboard input and store it in an internal buffer. The stream will read from keyboard input, only after this internal buffer is empty.&lt;br /&gt;
&lt;br /&gt;
When we entered the word &quot;india&quot; and pressed &quot;Enter&quot;, the characters &#39;i&#39;,&#39;n&#39;,&#39;d&#39;,&#39;i&#39;,&#39;a&#39;,&#39;\n&#39; were stored in the internal buffer. cin.get() only reads up to the delimiting character, viz., &#39;\n&#39; by default. [ More on this at :&amp;nbsp;&lt;a href=&quot;http://www.cplusplus.com/reference/istream/istream/get/&quot;&gt;http://www.cplusplus.com/reference/istream/istream/get/&lt;/a&gt; ].&lt;br /&gt;
&lt;br /&gt;
So, the initial value in the string &quot;key&quot; was &quot;india&quot;, but the input buffer still contained the trailing character &#39;\n&#39;. When we did a cin.get(); on line 13, we expected cin to read from keyboard input. But, instead it is the trailing character in the input buffer that is read by cin. And the program never prompted for user input.&lt;br /&gt;
&lt;br /&gt;
To force the program to prompt for user input, we need to clear [ or eat ] the trailing contents in the input buffer. Remember that flush() is applicable only on output streams. So, it won&#39;t solve the problem here. We have to explicitly read the trailing characters in the input buffer. Keep in mind that we do not know how many characters are still remaining in the input buffer.&lt;br /&gt;
&lt;br /&gt;
If the user has only entered the &quot;india&quot; and pressed &quot;Enter&quot; [ assuming he is a very obedient user :-) ] the simplest solution is to add the following line before line 12.&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;string tmp = cin.get();&lt;/pre&gt;
&lt;br /&gt;
The new code would be :&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;prettyprint linenums&quot;&gt;#include &amp;lt;iostream&amp;gt;

using namespace std;

int main()
{
 string key;

 cout &amp;lt;&amp;lt; &quot;Enter a word\n&quot;;
 cin &amp;gt;&amp;gt; key;
 cout &amp;lt;&amp;lt; &quot;You entered : &quot; [[ key [[ &quot;\n&quot;;
 string tmp = cin.get(); // This eats up the trailing &#39;\n&#39; still remaining in the input buffer
 cout &amp;lt;&amp;lt; &quot;Hit Enter to proceed...&quot;;
 key = cin.get();

 if (key == &quot;\n&quot;)
  cout &amp;lt;&amp;lt; &quot;Exit\n&quot;;
 else
  cout &amp;lt;&amp;lt; &quot;Error\n&quot;;

 return 0;
}
&lt;/pre&gt;
&lt;br /&gt;
And the new output behaves as below :&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;#./wait 
Enter a word
peace
You entered : peace
Hit Enter to proceed...
Exit
#./wait
Enter a word
more peace
You entered : more
Hit Enter to proceed...Error
&lt;/pre&gt;
&lt;br /&gt;
As expected, this works only if the user enters one word. If he enters more than one word, this fails. And since we do not know what characters the user would input, and we need to program for the worst possible case, a more generic and proper fix is to bite into the entire input buffer and junk it. The complete fix would be like this one below :&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;prettyprint linenums&quot;&gt;#include &amp;lt;iostream&amp;gt;

using namespace std;

int main()
{
 string key;

 cout &amp;lt;&amp;lt; &quot;Enter a word\n&quot;;
 cin &amp;gt;&amp;gt; key;
 cout &amp;lt;&amp;lt; &quot;You entered : &quot; [[ key [[ &quot;\n&quot;;
 cin.clear();
 cin.ignore(std::numeric_limits&amp;lt;streamsize&amp;gt;::max(), &#39;\n&#39;);
 cout &amp;lt;&amp;lt; &quot;Hit Enter to proceed...&quot;;
 key = cin.get();

 if (key == &quot;\n&quot;)
  cout &amp;lt;&amp;lt; &quot;Exit\n&quot;;
 else
  cout &amp;lt;&amp;lt; &quot;Error\n&quot;;

 return 0;
}
&lt;/pre&gt;
&lt;br /&gt;
The cin.clear() : only clears the internal stream&#39;s error state flags [ and not the input buffer !!! ] [ More info :&amp;nbsp;&lt;a href=&quot;http://www.cplusplus.com/reference/ios/ios/clear/&quot;&gt;http://www.cplusplus.com/reference/ios/ios/clear/&lt;/a&gt; ]&lt;br /&gt;
&lt;br /&gt;
The cin.ignore() : extracts characters from the input stream and junks them till it has extracted the maximum number of input characters, or the &#39;\n&#39; character.&lt;br /&gt;
&lt;br /&gt;
The output now is :&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;prettyprint&quot;&gt;#./wait
Enter a word
world
You entered : world
Hit Enter to proceed...
Exit
#./wait
Enter a word
world cup
You entered : world
Hit Enter to proceed...
Exit
#./wait
Enter a word
2014 world cup
You entered : 2014
Hit Enter to proceed...
Exit
&lt;/pre&gt;
&lt;br /&gt;
Enjoy :-)&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://find-an-answer.blogspot.com/feeds/1137418110043929862/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://find-an-answer.blogspot.com/2010/06/why-does-cin-not-wait-for-enter.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3950550929622410891/posts/default/1137418110043929862'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3950550929622410891/posts/default/1137418110043929862'/><link rel='alternate' type='text/html' href='http://find-an-answer.blogspot.com/2010/06/why-does-cin-not-wait-for-enter.html' title='[ Solved ] Why does cin not wait for Enter ?'/><author><name>Sarfraaz Ahmed</name><uri>http://www.blogger.com/profile/05627188302724560435</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3950550929622410891.post-4025373083180406469</id><published>2010-06-07T16:57:00.000+05:30</published><updated>2010-06-07T16:57:32.160+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="c++"/><category scheme="http://www.blogger.com/atom/ns#" term="namespace"/><category scheme="http://www.blogger.com/atom/ns#" term="unsolved"/><title type='text'>Unnamed Namespace</title><content type='html'>&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;Question&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;Do you think the following C++ program will compile ? If yes, then will it execute without any errors ? It yes, then what is the output on the screen ?&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;pre&gt;&lt;textarea cols=&quot;50&quot; name=&quot;c-code&quot; readonly=&quot;readonly&quot; rows=&quot;32&quot; style=&quot;background-color: #eaeaea;&quot;&gt;

// Replace [ with less than symbol
// Replace ] with greater than symbol

#include [iostream]

using namespace std;

namespace {
 void hi()
 {
  cout [[ &quot;Hello from unnamed namespace\n&quot;;
 }
}

class A
{
 public :
        A() 
        { 
                hi; 
                hi(); 
        }

};

int main()
{
 A a;
  return 0;
}
&lt;/textarea&gt;&lt;/pre&gt;&lt;br /&gt;
&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;Answer&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial; font-size: small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 13px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://find-an-answer.blogspot.com/feeds/4025373083180406469/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://find-an-answer.blogspot.com/2010/06/unnamed-namespace.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3950550929622410891/posts/default/4025373083180406469'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3950550929622410891/posts/default/4025373083180406469'/><link rel='alternate' type='text/html' href='http://find-an-answer.blogspot.com/2010/06/unnamed-namespace.html' title='Unnamed Namespace'/><author><name>Sarfraaz Ahmed</name><uri>http://www.blogger.com/profile/05627188302724560435</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3950550929622410891.post-3556291840941836545</id><published>2010-06-01T16:29:00.001+05:30</published><updated>2010-06-01T16:30:58.123+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="c"/><category scheme="http://www.blogger.com/atom/ns#" term="programming"/><category scheme="http://www.blogger.com/atom/ns#" term="puzzle"/><category scheme="http://www.blogger.com/atom/ns#" term="string"/><category scheme="http://www.blogger.com/atom/ns#" term="unsolved"/><title type='text'>Find the value of the modified string</title><content type='html'>This is my&amp;nbsp;favorite&amp;nbsp;question. Its so much fun to listen to all the different answers and their logical explanations :)&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;Question&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
If my C program contains only the following 2 statements ( inside main function ofcourse !! ), then what is the value of the string pointed by &quot;x&quot;, after the execution of these 2 statements.&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;textarea cols=&quot;50&quot; name=&quot;c-code&quot; readonly=&quot;readonly&quot; rows=&quot;4&quot; style=&quot;background-color: #eaeaea;&quot;&gt;

char *x = &quot;ABCD&quot;;
x[2] = &#39;z&#39;;
&lt;/textarea&gt;&lt;/pre&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;Answer&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial, sans-serif; font-size: 13px;&quot;&gt;&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: arial, sans-serif; font-size: 13px;&quot;&gt;&lt;i&gt;Please &lt;a href=&quot;http://find-an-answer.blogspot.com/2010/06/find-value-of-modified-string.html#comments&quot;&gt;follow this link&lt;/a&gt; to post your answer. I shall update this post with the correct answer in about a week&#39;s time.&lt;/i&gt;&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://find-an-answer.blogspot.com/feeds/3556291840941836545/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://find-an-answer.blogspot.com/2010/06/find-value-of-modified-string.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3950550929622410891/posts/default/3556291840941836545'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3950550929622410891/posts/default/3556291840941836545'/><link rel='alternate' type='text/html' href='http://find-an-answer.blogspot.com/2010/06/find-value-of-modified-string.html' title='Find the value of the modified string'/><author><name>Sarfraaz Ahmed</name><uri>http://www.blogger.com/profile/05627188302724560435</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3950550929622410891.post-3716964506245136556</id><published>2010-05-28T16:38:00.003+05:30</published><updated>2010-06-01T16:14:03.427+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="logical"/><category scheme="http://www.blogger.com/atom/ns#" term="mathematical"/><category scheme="http://www.blogger.com/atom/ns#" term="multiplication"/><category scheme="http://www.blogger.com/atom/ns#" term="puzzle"/><category scheme="http://www.blogger.com/atom/ns#" term="solved"/><title type='text'>(x-a)(x-b)(x-c)....(x-z)</title><content type='html'>&lt;b&gt;Update&lt;/b&gt; : This puzzle is now solved&lt;br /&gt;
&lt;br /&gt;
I consider this to be one of the more silly puzzle questions :p&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;Question&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
What is the value of this multiplication :&lt;br /&gt;
&lt;br /&gt;
(x-a)(x-b)(x-c).....(x-z)&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;Answer&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
As rightly pointed out by &lt;a href=&quot;http://www.google.com/profiles/108710479286204388539&quot;&gt;Ajay&lt;/a&gt; and &lt;a href=&quot;http://www.google.com/profiles/103885090373515297488&quot;&gt;Kalpana&lt;/a&gt;, the answer is &quot;zero&quot;.&lt;br /&gt;
&lt;br /&gt;
The reason being, x-x = 0</content><link rel='replies' type='application/atom+xml' href='http://find-an-answer.blogspot.com/feeds/3716964506245136556/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://find-an-answer.blogspot.com/2010/05/x-ax-bx-cx-z.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3950550929622410891/posts/default/3716964506245136556'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3950550929622410891/posts/default/3716964506245136556'/><link rel='alternate' type='text/html' href='http://find-an-answer.blogspot.com/2010/05/x-ax-bx-cx-z.html' title='(x-a)(x-b)(x-c)....(x-z)'/><author><name>Sarfraaz Ahmed</name><uri>http://www.blogger.com/profile/05627188302724560435</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3950550929622410891.post-6269863699079408607</id><published>2010-05-20T17:59:00.000+05:30</published><updated>2010-05-20T17:59:45.431+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="c"/><category scheme="http://www.blogger.com/atom/ns#" term="linked list"/><category scheme="http://www.blogger.com/atom/ns#" term="programming"/><category scheme="http://www.blogger.com/atom/ns#" term="solved"/><title type='text'>Delete any node in the middle of a linked list</title><content type='html'>&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;Question&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Given a pointer to a node in the middle of a linked list, how will you delete the present node ?&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;Answer&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot;&gt;&amp;nbsp;&amp;nbsp;The trick is in using simple pointer tricks. The &quot;present node&quot; should now point to the &quot;next node&quot;. Make sure you delete the data in the &quot;present node&quot;&lt;/span&gt;&lt;br /&gt;
&lt;center&gt;&lt;pre&gt;&lt;textarea cols=&quot;50&quot; name=&quot;c-code&quot; readonly=&quot;readonly&quot; rows=&quot;18&quot; style=&quot;background-color: #eaeaea;&quot;&gt;
void delete_node (list **node)
{

   list *present = *node;

   if (present == NULL)
        return;

[ use arrow in place of dot below ]

   *node = present.next; 
   free (present.data); 
   free (present);
   return;
}
&lt;/textarea&gt;&lt;/pre&gt;&lt;/center&gt;</content><link rel='replies' type='application/atom+xml' href='http://find-an-answer.blogspot.com/feeds/6269863699079408607/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://find-an-answer.blogspot.com/2010/05/delete-any-node-in-middle-of-linked.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3950550929622410891/posts/default/6269863699079408607'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3950550929622410891/posts/default/6269863699079408607'/><link rel='alternate' type='text/html' href='http://find-an-answer.blogspot.com/2010/05/delete-any-node-in-middle-of-linked.html' title='Delete any node in the middle of a linked list'/><author><name>Sarfraaz Ahmed</name><uri>http://www.blogger.com/profile/05627188302724560435</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3950550929622410891.post-4504279915173671317</id><published>2010-04-30T23:47:00.004+05:30</published><updated>2010-05-01T00:29:00.534+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="c"/><category scheme="http://www.blogger.com/atom/ns#" term="reverse"/><category scheme="http://www.blogger.com/atom/ns#" term="string"/><category scheme="http://www.blogger.com/atom/ns#" term="swap"/><title type='text'>Reverse a string</title><content type='html'>&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;Question&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Write code to reverse a string in its place.&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;Answer&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
[ This basically means, that we cannot allocate extra memory for the reversed string and have to return it back in the same memory ]&lt;br /&gt;
&lt;br /&gt;
To reverse a string in its place, we&#39;ll have to swap the 1&lt;sup&gt;st&lt;/sup&gt; character with the n&lt;sup&gt;th&lt;/sup&gt; character, then the 2&lt;sup&gt;nd&lt;/sup&gt; character with the (n - 1)&lt;sup&gt;th&lt;/sup&gt; character and so on ...&lt;br /&gt;
&lt;center&gt;&lt;br /&gt;
&lt;pre&gt;&lt;textarea cols=&quot;50&quot; name=&quot;c-code&quot; readonly=&quot;readonly&quot; rows=&quot;18&quot; style=&quot;background-color: #eaeaea;&quot;&gt;
void reverse_str (char **s)
{
   char *t = *s;
   char *left = t;
   /* TODO: make sure that t is not NULL */
   char *right = t + strlen (t) - 1; 
   char tmp;

   while (left -lt right)
   {
      tmp = *left;
      *left = *right;
      *right = tmp;
      left ++;
      right --;
   }
}
&lt;/textarea&gt;&lt;/pre&gt;&lt;/center&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;Corollary Question&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Reverse the string in its place, &lt;u&gt;without using a temporary variable.&lt;/u&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;Answer&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
The logic for this comes from the simple swapping technique that does not use a temporary variable.&lt;br /&gt;
&lt;center&gt;&lt;br /&gt;
&lt;pre&gt;&lt;textarea cols=&quot;50&quot; name=&quot;c-code&quot; readonly=&quot;readonly&quot; rows=&quot;10&quot; style=&quot;background-color: #eaeaea;&quot;&gt;
swap ( int *a, int *b)
{
   /* Lets start with a = 10 and b = 50

   *a = *a + *b;  /* a = 60, b = 50 */
   *b = *a - *b;  /* a = 60, b = 10 */
   *a = *a - *b;  /* a = 50, b = 10 */

}
&lt;/textarea&gt;&lt;/pre&gt;&lt;/center&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;Using the above logic we can re-write our function to reverse the string as below&lt;/div&gt;&lt;center&gt;&lt;br /&gt;
&lt;pre&gt;&lt;textarea align=&quot;center&quot; cols=&quot;50&quot; name=&quot;c-code&quot; readonly=&quot;readonly&quot; rows=&quot;18&quot; style=&quot;background-color: #eaeaea;&quot;&gt;
void reverse_str (char **s)
{
   char *t = *s;
   char *left = t;
   /* TODO: make sure that t is not NULL */
   char *right = t + strlen (t) - 1; 

   while (left -lt right)
   {
      *left  = *left + *right;
      *right = *left - *right;
      *left  = *left - *right;
      left ++;
      right --;
   }
}
&lt;/textarea&gt;&lt;/pre&gt;&lt;/center&gt;</content><link rel='replies' type='application/atom+xml' href='http://find-an-answer.blogspot.com/feeds/4504279915173671317/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://find-an-answer.blogspot.com/2010/04/reverse-string.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3950550929622410891/posts/default/4504279915173671317'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3950550929622410891/posts/default/4504279915173671317'/><link rel='alternate' type='text/html' href='http://find-an-answer.blogspot.com/2010/04/reverse-string.html' title='Reverse a string'/><author><name>Sarfraaz Ahmed</name><uri>http://www.blogger.com/profile/05627188302724560435</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3950550929622410891.post-2327009989136743762</id><published>2010-04-29T12:42:00.012+05:30</published><updated>2010-05-19T22:29:20.315+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="gold coin"/><category scheme="http://www.blogger.com/atom/ns#" term="logical"/><category scheme="http://www.blogger.com/atom/ns#" term="puzzle"/><category scheme="http://www.blogger.com/atom/ns#" term="solved"/><category scheme="http://www.blogger.com/atom/ns#" term="weights"/><title type='text'>Find the box containing 9 grams gold coin</title><content type='html'>&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;Puzzle :&lt;/span&gt;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;Update : This puzzle is solved now&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;There are 5 boxes. Each box contains 10 gold coins.&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;4 of the boxes contain gold coins weighing 10 grams each.&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;One of the box contains gold coins that weigh 9 grams each.&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;You are allowed to open the boxes if needed.&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;But, the gold coins are completely identical and the difference in their weight cannot be identified by the naked eye.&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;You are given a digital weighing machine.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Find out the box that contains the 9 grams gold coins by using the weigh only once.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: x-large;&quot;&gt;Solution :&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot;&gt;Lets label the 5 boxes as A,B,C,D and E&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot;&gt;Now pick 1 gold coin from box A, 2 from box B, 3 from box C, 4 from box D and 5 from box E&lt;/span&gt;&lt;br /&gt;
Keep them on the weighing machine and find out the total weight.&lt;br /&gt;
If all the boxes contained gold coins that weighed 10 grams each, then the weight would be :&lt;br /&gt;
&lt;br /&gt;
10 + 20 + 30 + 40 + 50 = 150 grams.&lt;br /&gt;
&lt;br /&gt;
But, since one box contains all the gold coins weighing 9 grams, based on the box that contains this defective gold coin the measured weight would vary.&lt;br /&gt;
&lt;br /&gt;
If box A contained the 9 gram gold coins, the measured weight would be :&lt;br /&gt;
&lt;br /&gt;
9 + 20 + 30 + 40 + 50 = 149 grams.&lt;br /&gt;
&lt;br /&gt;
Following the same logic, based on the single measured weight we can identify the box that contains 9 grams gold coin as below :&lt;br /&gt;
&lt;br /&gt;
If measured weight is 149 grams, then the 9 gram gold coin is in box A.&lt;br /&gt;
If measured weight is 148 grams, then the 9 gram gold coin is in box B.&lt;br /&gt;
If measured weight is 147 grams, then the 9 gram gold coin is in box C.&lt;br /&gt;
If measured weight is 146 grams, then the 9 gram gold coin is in box D.&lt;br /&gt;
If measured weight is 145 grams, then the 9 gram gold coin is in box E.&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://find-an-answer.blogspot.com/feeds/2327009989136743762/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://find-an-answer.blogspot.com/2010/04/find-box-containing-9-grams-gold-coin.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3950550929622410891/posts/default/2327009989136743762'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3950550929622410891/posts/default/2327009989136743762'/><link rel='alternate' type='text/html' href='http://find-an-answer.blogspot.com/2010/04/find-box-containing-9-grams-gold-coin.html' title='Find the box containing 9 grams gold coin'/><author><name>Sarfraaz Ahmed</name><uri>http://www.blogger.com/profile/05627188302724560435</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3950550929622410891.post-2189460456249619478</id><published>2010-04-15T16:53:00.000+05:30</published><updated>2010-04-15T16:55:58.644+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="find-an-answer"/><category scheme="http://www.blogger.com/atom/ns#" term="introduction"/><title type='text'>Introduction</title><content type='html'>Have been thinking of trying out the new Blogger templates since quite a while now. Got some time now and thought of creating this new blog, where I would be posting all the interesting FAQs and various questions, some with answers, some seeking answers :)&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Lets see how far I can go with posts on this new blog of mine.&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://find-an-answer.blogspot.com/feeds/2189460456249619478/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://find-an-answer.blogspot.com/2010/04/introduction.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3950550929622410891/posts/default/2189460456249619478'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3950550929622410891/posts/default/2189460456249619478'/><link rel='alternate' type='text/html' href='http://find-an-answer.blogspot.com/2010/04/introduction.html' title='Introduction'/><author><name>Sarfraaz Ahmed</name><uri>http://www.blogger.com/profile/05627188302724560435</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>