<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>EmbLogic &#187; arithmetic</title>
	<atom:link href="https://www.emblogic.com/blog/tag/arithmetic/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.emblogic.com/blog</link>
	<description>Embedded System and ARM Training</description>
	<lastBuildDate>Tue, 03 Mar 2020 13:00:06 +0000</lastBuildDate>
	<language>en-US</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.9.1</generator>
	<item>
		<title>Different methods of swapping 2 numbers</title>
		<link>https://www.emblogic.com/blog/09/different-methods-of-swapping-2-numbers/</link>
		<comments>https://www.emblogic.com/blog/09/different-methods-of-swapping-2-numbers/#comments</comments>
		<pubDate>Tue, 20 Sep 2016 15:10:38 +0000</pubDate>
		<dc:creator><![CDATA[Ankur Garg]]></dc:creator>
				<category><![CDATA[Data Structures with C]]></category>
		<category><![CDATA[arithmetic]]></category>
		<category><![CDATA[bitwise]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[gcc]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://www.emblogic.com/blog/?p=13684</guid>
		<description><![CDATA[#include&#60;stdio.h&#62; void swap(int *,int *); int main() { int temp; int *t; int a=100,b=200; //Using 3 variables //1.1 temp = a; a = b; b = temp; printf(&#8220;%d %d\n&#8221;,a,b); //1.2 swap(&#38;a,&#38;b); printf(&#8220;%d %d\n&#8221;,a,b); //Using 2 variables //2.1 a += b; &#8230; <a href="https://www.emblogic.com/blog/09/different-methods-of-swapping-2-numbers/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>#include&lt;stdio.h&gt;<br />
void swap(int *,int *);</p>
<p>int main()<br />
{<br />
int temp;<br />
int *t;<br />
int a=100,b=200;<br />
//Using 3 variables<br />
//1.1<br />
temp = a;<br />
a = b;<br />
b = temp;<br />
printf(&#8220;%d %d\n&#8221;,a,b);<br />
//1.2<br />
swap(&amp;a,&amp;b);<br />
printf(&#8220;%d %d\n&#8221;,a,b);</p>
<p>//Using 2 variables<br />
//2.1<br />
a += b;<br />
b = a-b;<br />
a = a-b;<br />
printf(&#8220;%d %d\n&#8221;,a,b);<br />
//2.2<br />
if(a!=0 &amp;&amp; b!=0)<br />
{<br />
a *= b;<br />
b = a/b;<br />
a = a/b;<br />
printf(&#8220;%d %d\n&#8221;,a,b);<br />
}<br />
//2.3<br />
a = a^b;<br />
b = a^b;<br />
a = a^b;<br />
printf(&#8220;%d %d\n&#8221;,a,b);<br />
//Using 2 variables in single step<br />
//3.1<br />
a = b+a-(b=a);<br />
printf(&#8220;%d %d\n&#8221;,a,b);<br />
//3.2<br />
a = b*a/(b=a);<br />
printf(&#8220;%d %d\n&#8221;,a,b);<br />
//3.3<br />
a ^=b^=a^=b;<br />
printf(&#8220;%d %d\n&#8221;,a,b);<br />
return 0;<br />
}<br />
void swap(int *x,int *y)<br />
{<br />
int tmp;<br />
tmp = *x;<br />
*x = *y;<br />
*y = tmp;<br />
}</p>
]]></content:encoded>
			<wfw:commentRss>https://www.emblogic.com/blog/09/different-methods-of-swapping-2-numbers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
