<?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>electrofriends.com &#187; Computer Science</title>
	<atom:link href="http://electrofriends.com/category/articles/computer-science/feed/" rel="self" type="application/rss+xml" />
	<link>http://electrofriends.com</link>
	<description>...bringing innovative minds together</description>
	<lastBuildDate>Fri, 30 Apr 2010 05:54:32 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Introduction to PCI protocol</title>
		<link>http://electrofriends.com/articles/computer-science/protocol/introduction-to-pci-protocol/</link>
		<comments>http://electrofriends.com/articles/computer-science/protocol/introduction-to-pci-protocol/#comments</comments>
		<pubDate>Sat, 10 Oct 2009 15:24:16 +0000</pubDate>
		<dc:creator>Ranjith</dc:creator>
				<category><![CDATA[Protocols]]></category>
		<category><![CDATA[arbitration process]]></category>
		<category><![CDATA[bus transactions]]></category>
		<category><![CDATA[computer hardware]]></category>
		<category><![CDATA[error detections]]></category>
		<category><![CDATA[master and slave]]></category>
		<category><![CDATA[PCI Cards]]></category>
		<category><![CDATA[PCI protocol]]></category>
		<category><![CDATA[pci signals]]></category>
		<category><![CDATA[PCI slots]]></category>
		<category><![CDATA[pin descreption]]></category>
		<category><![CDATA[reports]]></category>
		<category><![CDATA[space decoding]]></category>
		<category><![CDATA[timing diagrams]]></category>

		<guid isPermaLink="false">http://electrofriends.com/?p=930</guid>
		<description><![CDATA[Today’s  computer systems, with their emphasis on high resolution graphics, full motion  video, high bandwidth networking, and so on, go far beyond the capabilities of  the architecture that ushered in the age of the personal computer in 1982.  Modern PC systems demand high performance interconnects that also allow devices  to [...]]]></description>
			<content:encoded><![CDATA[<p>Today’s  computer systems, with their emphasis on high resolution graphics, full motion  video, high bandwidth networking, and so on, go far beyond the capabilities of  the architecture that ushered in the age of the personal computer in 1982.  Modern PC systems demand high performance interconnects that also allow devices  to be changed or upgraded with a minimum of effort by the end user.</p>
<p align="left">In response to this need, PCI (<strong>peripheral component interconnect</strong>) has emerged as the dominant mechanism for  interconnecting the elements of modern, high performance computer systems. It  is a well thought out standard with a number of forward looking features that  should keep it relevant well into the next century. Originally conceived as a  mechanism for interconnecting peripheral components on a motherboard, PCI has  evolved into at least a half dozen different physical implementations directed  at specific market segments yet all using the same basic bus protocol. In the  form known as Compact PCI, it is having a major impact in the rapidly growing telecommunications  market.</p>
<p>PCI offers a number of significant  performance and architectural advantages over previous busses:</p>
<p><strong>Speed:</strong>The basic PCI protocol can transfer up to 132 Mbytes per second,  well over an order of magnitude faster than ISA. Even so, the demand for  bandwidth is insatiable. Extensions to the basic protocol yield bandwidths as  high as 512 Mbytes per second and development currently under way will push it  to a gigabyte.</p>
<p><strong>Configurability:</strong>PCI offers the ability to configure a system automatically,  relieving the user of the task of system configuration. It could be argued that  PCI’s success owes much to the very fact that users need not be aware of it.</p>
<p><strong>Multiple Masters:</strong>Prior to PCI, most busses supported only one “master,” the  processor. High bandwidth devices could have direct access to memory through a  mechanism called DMA (direct memory access) but devices,  in general, could not talk to each other. In PCI, any device has the potential  to take control of the bus and initiate transactions with any other device.</p>
<p><strong>Reliability:</strong>“Hot Plug”  and “Hot Swap,” defined respectively for PCI and Compact PCI, offer the ability  to replace modules without disrupting a system’s operation. This substantially  reduces MTTR (mean time to repair) to yield the necessary  degree of up-time required of mission-critical systems such as the telephone  network.</p>
<div id="attachment_952" class="wp-caption aligncenter" style="width: 375px"><img class="size-full wp-image-952" title="PCI_slot_and_cards" src="http://electrofriends.com/wp-content/uploads/2009/10/PCI_slot_and_cards.jpg" alt="PCI Slots and PCI card" width="365" height="468" /><p class="wp-caption-text">PCI Slots and PCI card</p></div>
<p><strong>1. PCI Protocol </strong></p>
<p>PCI is a synchronous bus architecture with all data  transfers being performed relative to a system clock (CLK). The initial PCI  specification permitted a maximum clock rate of 33 MHz allowing one bus  transfer to be performed every 30 nanoseconds. Later, PCI specification  extended the bus definition to support operation at 66 MHz, but the vast  majority of today&#8217;s personal computers continue to implement a PCI bus that  runs at a maximum speed of 33 MHz.</p>
<p>PCI implements a 32-bit multiplexed Address and Data  bus (AD[31:0]). It architects a means of supporting a 64-bit data bus through a  longer connector slot, but most of today&#8217;s personal computers support only  32-bit data transfers through the base 32-bit PCI connector. At 33 MHz, a  32-bit slot supports a maximum data transfer rate of 132 MBytes/sec, and a  64-bit slot supports 264 MBytes/sec.</p>
<p>The multiplexed Address and Data bus allows a reduced  pin count on the PCI connector that enables lower cost and smaller package size  for PCI components. Typical 32-bit PCI add-in boards use only about 50 signals  pins on the PCI connector of which 32 are the multiplexed Address and Data bus.  PCI bus cycles are initiated by driving an address onto the AD[31:0] signals  during the first clock edge called the address phase. The address phase  is signaled by the activation of the FRAME# signal. The next clock edge begins  the first of one or more data phases in which data is transferred over  the AD[31:0] signals.</p>
<p>In PCI terminology, data is transferred between an initiator which is the bus master, and a target which is the bus slave. The  initiator drives the C/BE[3:0]# signals during the address phase to signal the  type of transfer (memory read, memory write, I/O read, I/O write, etc.). During  data phases the C/BE[3:0]# signals serve as byte enable to indicate which data  bytes are valid. Both the initiator and target may insert wait states into the  data transfer by deasserting the IRDY# and TRDY# signals. Valid data transfers  occur on each clock edge in which both IRDY# and TRDY# are asserted.</p>
<p>A PCI bus transfer consists of one address phase and  any number of data phases. I/O operations that access registers within PCI  targets typically have only a single data phase. Memory transfers that move blocks  of data consist of multiple data phases that read or write multiple consecutive  memory locations. Both the initiator and target may terminate a bus transfer  sequence at any time. The initiator signals completion of the bus transfer by  deasserting the FRAME# signal during the last data phase. A target may  terminate a bus transfer by asserting the STOP# signal. When the initiator  detects an active STOP# signal, it must terminate the current bus transfer and  re-arbitrate for the bus before continuing. If STOP# is asserted without any  data phases completing, the target has issued a retry. If STOP# is  asserted after one or more data phases have successfully completed, the target  has issued a disconnect.</p>
<p>Initiators arbitrate for ownership of the bus by asserting  a REQ# signal to a central arbiter. The arbiter grants ownership of the bus by  asserting the GNT# signal. REQ# and GNT# are unique on a per slot basis  allowing the arbiter to implement a bus fairness algorithm. Arbitration in PCI  is &#8220;hidden&#8221; in the sense that it does not consume clock cycles. The  current initiator&#8217;s bus transfers are overlapped with the arbitration process  that determines the next owner of the bus.</p>
<p>PCI supports a rigorous auto configuration mechanism.  Each PCI device includes a set of configuration registers that allow  identification of the type of device (SCSI, video, Ethernet, etc.) and the  company that produced it. Other registers allow configuration of the device&#8217;s  I/O addresses, memory addresses, interrupt levels, etc.</p>
<p>Although it is not widely implemented, PCI supports  64-bit addressing. Unlike the 64-bit data bus option which requires a longer  connector with additional 32-bits of data signals, 64-bit addressing can be  supported through the base 32-bit connector. Dual Address Cycles are  issued in which the low order 32-bits of the address are driven onto the  AD[31:0] signals during the first address phase, and the high order 32-bits of  the address (if non-zero) are driven onto the AD[31:0] signals during a second  address phase. The remainder of the transfer continues like a normal bus  transfer.</p>
<p>PCI defines support for both 5 Volt and 3.3 Volt  signaling levels. The PCI connector defines pin locations for both the 5 Volt  and 3.3 Volt levels. However, most early PCI systems were 5 Volt only, and did  not provide active power on the 3.3 Volt connector pins. Over time more use of  the 3.3 Volt interface is expected, but add-in boards which must work in older  legacy systems are restricted to using only the 5 Volt supply. A &#8220;keying&#8221;  scheme is implemented in the PCI connectors to prevent inserting an add-in  board into a system with incompatible supply voltage.</p>
<p>Although used most extensively in PC compatible  systems, the PCI bus architecture is processor independent. PCI signal  definitions are generic allowing the bus to be used in systems based on other  processor families. PCI includes strict specifications to ensure the signal  quality required for operation at 33 and 66 MHz. Components and add-in boards  must include unique bus drivers that are specifically designed for use in a PCI  bus environment. Typical TTL devices used in previous bus implementations such  as ISA and EISA are not compliant with the requirements of PCI. This  restriction along with the high bus speed dictates that most PCI devices are  implemented as custom ASICs.</p>
<p>The  higher speed of PCI limits the number of expansion slots on a single bus to no  more than 3 or 4, as compared to 6 or 7 for earlier bus architectures. To  permit expansion buses with more than 3 or 4 slots, the PCI SIG has defined a PCI-to-PCI Bridge mechanism. PCI-to-PCI Bridges  are ASICs that electrically isolate two PCI buses while allowing bus transfers  to be forwarded from one bus to another. Each bridge device has a  &#8220;primary&#8221; PCI bus and a &#8220;secondary&#8221; PCI bus. Multiple  bridge devices may be cascaded to create a system with many PCI buses.</p>
<p><strong>Chapters:</strong></p>
<ol>
<li><a href="http://electrofriends.com/articles/computer-science/protocol/introduction-to-pci-protocol/">Introduction to PCI protocol</a></li>
<li><a href="http://electrofriends.com/articles/computer-science/protocol/introduction-to-pci-protocol/2/">PCI Signal Descriptions</a></li>
<li><a href="http://electrofriends.com/articles/computer-science/protocol/introduction-to-pci-protocol/3/">PCI Bus Transactions</a></li>
<li><a href="http://electrofriends.com/articles/computer-science/protocol/introduction-to-pci-protocol/4/">PCI Bus Timing Diagrams</a></li>
<li><a href="http://electrofriends.com/articles/computer-science/protocol/introduction-to-pci-protocol/5/">Configuration space decoding</a></li>
<li><a href="http://electrofriends.com/articles/computer-science/protocol/introduction-to-pci-protocol/6/">Arbitration process under PCI</a></li>
<li><a href="http://electrofriends.com/articles/computer-science/protocol/introduction-to-pci-protocol/7/">Error Detection and Reporting</a></li>
</ol>
<p><strong>Bibliography</strong></p>
<ol>
<li>PCI Tutorial by Xilinx</li>
<li>PCI Bus Demystified by Doug Abbott</li>
</ol>
<p><strong>Submitted by</strong>: Rovin and Sagar</p>
]]></content:encoded>
			<wfw:commentRss>http://electrofriends.com/articles/computer-science/protocol/introduction-to-pci-protocol/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP &#8211; Install/Run</title>
		<link>http://electrofriends.com/articles/computer-science/php-tutorial/php-installrun/</link>
		<comments>http://electrofriends.com/articles/computer-science/php-tutorial/php-installrun/#comments</comments>
		<pubDate>Thu, 04 Jun 2009 13:08:51 +0000</pubDate>
		<dc:creator>Ranjith</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://electrofriends.com/?p=556</guid>
		<description><![CDATA[To run any php file you need to install Apache web server on your localhost. Also you need to install MySQL server for any database programming. You can install these seperatly or there is easy way to achive the same by installing XAMPP.
XAMPP is an easy to install Apache distribution containing MySQL, PHP and Perl. [...]]]></description>
			<content:encoded><![CDATA[<p>To run any php file you need to install Apache web server on your localhost. Also you need to install MySQL server for any database programming. You can install these seperatly or there is easy way to achive the same by installing XAMPP.</p>
<p>XAMPP is an easy to install Apache distribution containing MySQL, PHP and Perl. XAMPP is really very easy to install and to use &#8211; just download, extract and start.</p>
<p>You have already learned to write a basic PHP program in the previous page. Here is that program.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&lt;html&gt;
   &lt;body&gt;
      <span style="color: #000000; font-weight: bold;">&lt;?php</span>
         <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;MY First PHP Program&quot;</span><span style="color: #339933;">;</span>
      <span style="color: #000000; font-weight: bold;">?&gt;</span>
   &lt;/body&gt;
&lt;/html&gt;</pre></div></div>

<p>Write this program in a notepad and save as firstprogram.php</p>
<p>Now to run this do the following steps.</p>
<ol>
<li>First download the xampp from <a href="http://www.apachefriends.org/en/xampp.html" target="_blank">http://www.apachefriends.org/en/xampp.html</a></li>
<li>Extract the file and double click the exe. This will install Mysql and Apache servers.</li>
<li>Once the installation is complete, you will find XAMPP under Start / Programs / XAMPP. You can use the XAMPP Control Panel to start/stop all servers. Start Mysql and Apache servers.</li>
<li>Copy firstprogram.php to C:/Program Files/XAMPP/htdocs/</li>
<li>To run the php file, you just need to brows http://localhost/firstprogram.php</li>
</ol>
<p><strong>Note:</strong> You can also create any folders inside htdocs folder. For ex. create a folder called &#8220;test&#8221; and copy firstprogram.php to &#8220;test&#8221;, then the address will become http://localhost/test/firstprogram.php</p>
]]></content:encoded>
			<wfw:commentRss>http://electrofriends.com/articles/computer-science/php-tutorial/php-installrun/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP &#8211; Introduction</title>
		<link>http://electrofriends.com/articles/computer-science/php-tutorial/php-introduction/</link>
		<comments>http://electrofriends.com/articles/computer-science/php-tutorial/php-introduction/#comments</comments>
		<pubDate>Thu, 04 Jun 2009 13:01:17 +0000</pubDate>
		<dc:creator>Ranjith</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://electrofriends.com/?p=551</guid>
		<description><![CDATA[PHP stands for &#8220;Hypertext Preprocessor&#8220;,  is a server-side scripting language used to create dynamic Web pages. This can be embedded to HTML pages. This is very easy scripting language compare to other scripting languags. The goal of the language is to allow Web developers to write dynamically generated pages quickly.
PHP supports many databases like MySQL, [...]]]></description>
			<content:encoded><![CDATA[<p>PHP stands for &#8220;<strong>Hypertext Preprocessor</strong>&#8220;,  is a server-side scripting language used to create dynamic Web pages. This can be embedded to HTML pages. This is very easy scripting language compare to other scripting languags. The goal of the language is to allow Web developers to write dynamically generated pages quickly.</p>
<p>PHP supports many databases like MySQL, Informix, Oracle, Sybase, Solid, PostgreSQL, Generic ODBC, etc.</p>
<p>You no need any software to write this php codes. Yo can write in a basic windows notepad.</p>
<p><strong>My first PHP program:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&lt;html&gt;
&lt;body&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;MY First PHP Program&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;/body&gt;
&lt;/html&gt;</pre></div></div>

<p>PHP block should written inside <strong>&lt;?php</strong> and <strong>?&gt;</strong> Here echo &#8220;MY First PHP Program&#8221;; will display &#8220;MY First PHP Program&#8221; in browser.</p>
<p>Now the time to run this program. Before that you need to install server in your localhost. Learn how in next pages.</p>
]]></content:encoded>
			<wfw:commentRss>http://electrofriends.com/articles/computer-science/php-tutorial/php-introduction/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Insertion sort in C program</title>
		<link>http://electrofriends.com/source-codes/software-programs/c/sorting-programs/program-to-sort-the-numbers-using-insertion-sort/</link>
		<comments>http://electrofriends.com/source-codes/software-programs/c/sorting-programs/program-to-sort-the-numbers-using-insertion-sort/#comments</comments>
		<pubDate>Thu, 04 Dec 2008 06:12:42 +0000</pubDate>
		<dc:creator>Ranjith</dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[Sorting Programs]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[C/C++]]></category>
		<category><![CDATA[C/C++ Programms]]></category>
		<category><![CDATA[download]]></category>
		<category><![CDATA[Insertion sort]]></category>
		<category><![CDATA[logic]]></category>
		<category><![CDATA[sort in c]]></category>
		<category><![CDATA[sorting]]></category>
		<category><![CDATA[sorting demo]]></category>
		<category><![CDATA[sorting in c]]></category>
		<category><![CDATA[sorting numbers]]></category>
		<category><![CDATA[Source Codes]]></category>

		<guid isPermaLink="false">http://electrofriends.com/?p=351</guid>
		<description><![CDATA[Here is the program to sort the given integer in ascending order using insertion sort method. Please find the pictorial tutor of the insertion sorting. 
Logic : Here, sorting takes place by inserting a particular element at the appropriate position, that&#8217;s why the name-  insertion sorting. In the First iteration, second element A[1] is compared [...]]]></description>
			<content:encoded><![CDATA[<p>Here is the program to sort the given integer in ascending order using insertion sort method. Please find the pictorial tutor of the insertion sorting. </p>
<p><strong>Logic :</strong> Here, sorting takes place by inserting a particular element at the appropriate position, that&#8217;s why the name-  insertion sorting. In the First iteration, second element A[1] is compared with the first element A[0]. In the second iteration third element is compared with first and second element. In general, in every iteration an element is compared with all the elements before it. While comparing if it is found that the element can be inserted at a suitable position, then space is created for it by shifting the other elements one position up and inserts the desired element at the suitable position. This procedure is repeated for all the elements in the list.</p>
<p>If we complement the if condition in this program, it will give out the sorted array in descending order. Sorting can also be done in other methods, like selection sorting and bubble sorting, which follows in the next pages.</p>
<div id="attachment_912" class="wp-caption aligncenter" style="width: 590px"><img class="size-full wp-image-912" title="Insertion Sort Demo" src="http://electrofriends.com/wp-content/uploads/2008/12/insertion_sort.jpg" alt="Insertion Sort Demo" width="580" height="1332" /><p class="wp-caption-text">Insertion Sort Demo</p></div>
<p><strong>C program for Insertion Sort:</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
</pre></td><td class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include&lt;stdio.h&gt;</span>
<span style="color: #993333;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #993333;">int</span> A<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">20</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> N<span style="color: #339933;">,</span> Temp<span style="color: #339933;">,</span> i<span style="color: #339933;">,</span> j<span style="color: #339933;">;</span>
	clrscr<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\t</span> ENTER THE NUMBER OF TERMS...: &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	scanf<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;%d&quot;</span><span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>N<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\t</span> ENTER THE ELEMENTS OF THE ARRAY...:&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>N<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		gotoxy<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">25</span><span style="color: #339933;">,</span><span style="color: #0000dd;">11</span><span style="color: #339933;">+</span>i<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		scanf<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\t</span><span style="color: #000099; font-weight: bold;">\t</span>%d&quot;</span><span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>A<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>N<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		Temp <span style="color: #339933;">=</span> A<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		j <span style="color: #339933;">=</span> i<span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span>Temp<span style="color: #339933;">&lt;</span>A<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span> <span style="color: #339933;">&amp;&amp;</span> j<span style="color: #339933;">&gt;=</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			A<span style="color: #009900;">&#91;</span>j<span style="color: #339933;">+</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> A<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
			j <span style="color: #339933;">=</span> j<span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		A<span style="color: #009900;">&#91;</span>j<span style="color: #339933;">+</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> Temp<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\t</span>THE ASCENDING ORDER LIST IS...:<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>N<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
		<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\t</span><span style="color: #000099; font-weight: bold;">\t</span><span style="color: #000099; font-weight: bold;">\t</span>%d&quot;</span><span style="color: #339933;">,</span> A<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	getch<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><a href="http://electrofriends.com/wp-content/uploads/2008/12/ins_srt.zip">Download exe and source code here.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://electrofriends.com/source-codes/software-programs/c/sorting-programs/program-to-sort-the-numbers-using-insertion-sort/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>Bubble sort program in C</title>
		<link>http://electrofriends.com/source-codes/software-programs/c/sorting-programs/program-to-sort-the-numbers-using-bubble-sort/</link>
		<comments>http://electrofriends.com/source-codes/software-programs/c/sorting-programs/program-to-sort-the-numbers-using-bubble-sort/#comments</comments>
		<pubDate>Thu, 04 Dec 2008 06:09:14 +0000</pubDate>
		<dc:creator>Ranjith</dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[Sorting Programs]]></category>
		<category><![CDATA[Bubble sort]]></category>
		<category><![CDATA[bubblesort demo]]></category>
		<category><![CDATA[C/C++]]></category>
		<category><![CDATA[C/C++ Programms]]></category>
		<category><![CDATA[download]]></category>
		<category><![CDATA[Examples]]></category>
		<category><![CDATA[sorting demo]]></category>
		<category><![CDATA[sorting methods]]></category>

		<guid isPermaLink="false">http://electrofriends.com/?p=348</guid>
		<description><![CDATA[Here is the program to sort the given integer in ascending order using bubble sort method. Please find the pictorial tutor of the bubble sorting. 
Logic :  The entered integers are stored in the array A. Here, to sort the data in ascending order, any number is compared with the next numbers for orderliness. i.e. [...]]]></description>
			<content:encoded><![CDATA[<p>Here is the program to sort the given integer in ascending order using bubble sort method. Please find the pictorial tutor of the bubble sorting. </p>
<p>Logic :  The entered integers are stored in the array A. Here, to sort the data in ascending order, any number is compared with the next numbers for orderliness. i.e. first element A[0] is compared with the second  element A[1]. If forth is greater than the prior element then swapping them, else no change. Then second element is compared with third element, and procedure is continued. Hence, after the first iteration of the outer for loop, largest element is placed at the end of the array. In the second iteration, the comparisons are made till the last but one position and now second largest element is placed at the last but one position. The procedure is traced till the array length.</p>
<p>If we complement the if condition in this program, it will give out the sorted array in descending order. Sorting can also be done in other methods, like <a href="http://electrofriends.com/source-codes/software-programs/c/sorting-programs/program-to-sort-the-numbers-using-selection-sort/">selection sorting</a> and <a href="http://electrofriends.com/articles/computer-science/c-tutorials/source-codes/software-programs/c/sorting-programs/program-to-sort-the-numbers-using-insertion-sort/">insertion sorting</a>, which follows in the next pages.</p>
<div id="attachment_1077" class="wp-caption aligncenter" style="width: 590px"><img src="http://electrofriends.com/wp-content/uploads/2008/12/Bubble_sort.jpg" alt="Bubble sort Image Demo" title="Bubble sort Image Demo" width="580" height="1510" class="size-full wp-image-1077" /><p class="wp-caption-text">Bubble sort Image Demo</p></div>
<p>Here is the C program to sort the numbers using Bubble sort</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #339900;">#include&lt;stdio.h&gt;</span>
<span style="color: #0000ff;">void</span> main<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
	<span style="color: #0000ff;">int</span> A<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">20</span><span style="color: #008000;">&#93;</span>, N, Temp, i, j<span style="color: #008080;">;</span>
	clrscr<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #0000dd;">printf</span><span style="color: #008000;">&#40;</span>“\n\n\t ENTER THE NUMBER OF TERMS…<span style="color: #008080;">:</span> “<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #0000dd;">scanf</span><span style="color: #008000;">&#40;</span>“<span style="color: #000040;">%</span>d”,<span style="color: #000040;">&amp;</span>N<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #0000dd;">printf</span><span style="color: #008000;">&#40;</span>“\n\t ENTER THE ELEMENTS OF THE ARRAY…<span style="color: #008080;">:</span>”<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">for</span><span style="color: #008000;">&#40;</span>i<span style="color: #000080;">=</span><span style="color: #0000dd;">0</span><span style="color: #008080;">;</span> i<span style="color: #000080;">&lt;</span>N<span style="color: #008080;">;</span> i<span style="color: #000040;">++</span><span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
		gotoxy<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">25</span>, <span style="color: #0000dd;">11</span><span style="color: #000040;">+</span>i<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
		<span style="color: #0000dd;">scanf</span><span style="color: #008000;">&#40;</span>“\n\t\t<span style="color: #000040;">%</span>d”, <span style="color: #000040;">&amp;</span>A<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
	<span style="color: #0000ff;">for</span><span style="color: #008000;">&#40;</span>i<span style="color: #000080;">=</span><span style="color: #0000dd;">0</span><span style="color: #008080;">;</span> i<span style="color: #000080;">&lt;</span>N<span style="color: #000040;">-</span><span style="color: #0000dd;">1</span><span style="color: #008080;">;</span> i<span style="color: #000040;">++</span><span style="color: #008000;">&#41;</span>
		<span style="color: #0000ff;">for</span><span style="color: #008000;">&#40;</span>j<span style="color: #000080;">=</span><span style="color: #0000dd;">0</span><span style="color: #008080;">;</span> j<span style="color: #000080;">&lt;</span>N<span style="color: #000040;">-</span>i<span style="color: #008080;">;</span>j<span style="color: #000040;">++</span><span style="color: #008000;">&#41;</span>
			<span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>A<span style="color: #008000;">&#91;</span>j<span style="color: #008000;">&#93;</span><span style="color: #000080;">&gt;</span>A<span style="color: #008000;">&#91;</span>j<span style="color: #000040;">+</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span>
			<span style="color: #008000;">&#123;</span>
				Temp <span style="color: #000080;">=</span> A<span style="color: #008000;">&#91;</span>j<span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
				A<span style="color: #008000;">&#91;</span>j<span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> A<span style="color: #008000;">&#91;</span>j<span style="color: #000040;">+</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
				A<span style="color: #008000;">&#91;</span>j<span style="color: #000040;">+</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#93;</span> <span style="color: #000080;">=</span> Temp<span style="color: #008080;">;</span>
			<span style="color: #008000;">&#125;</span>
	<span style="color: #0000dd;">printf</span><span style="color: #008000;">&#40;</span>“\n\tTHE ASCENDING ORDER LIST IS…<span style="color: #008080;">:</span>\n”<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">for</span><span style="color: #008000;">&#40;</span>i<span style="color: #000080;">=</span><span style="color: #0000dd;">0</span><span style="color: #008080;">;</span> i<span style="color: #000080;">&lt;</span>N<span style="color: #008080;">;</span> i<span style="color: #000040;">++</span><span style="color: #008000;">&#41;</span>
		<span style="color: #0000dd;">printf</span><span style="color: #008000;">&#40;</span>“\n\t\t\t<span style="color: #000040;">%</span>d”,A<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	getch<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p><a href="http://electrofriends.com/wp-content/uploads/2008/12/bubl_srt.zip">Download exe and source code here.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://electrofriends.com/source-codes/software-programs/c/sorting-programs/program-to-sort-the-numbers-using-bubble-sort/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Mouse programming in C</title>
		<link>http://electrofriends.com/articles/computer-science/c-tutorials/mouse-programming-in-cc/</link>
		<comments>http://electrofriends.com/articles/computer-science/c-tutorials/mouse-programming-in-cc/#comments</comments>
		<pubDate>Thu, 20 Nov 2008 11:21:41 +0000</pubDate>
		<dc:creator>Ranjith</dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[C/C++ graphics]]></category>
		<category><![CDATA[Mouse programming]]></category>

		<guid isPermaLink="false">http://electrofriends.com/?p=259</guid>
		<description><![CDATA[Mouse can be used in text mode as well as in graphics mode. Usually it is used in graphics mode. Hence we must first change over to graphics mode. In our program the function initgraph() is responsible for switching the mode from text to graphics .DETECT is a macro defined in &#8216;graphics.h&#8217;. It requests initgraph() [...]]]></description>
			<content:encoded><![CDATA[<p>Mouse can be used in text mode as well as in graphics mode. Usually it is used in graphics mode. Hence we must first change over to graphics mode. In our program the function initgraph() is responsible for switching the mode from text to graphics .DETECT is a macro defined in &#8216;graphics.h&#8217;. It requests initgraph() to automatically determine which graphics driver to load in order to switch to the highest resolution graphics mode. The initgraph() function takes three parameters, the graphics driver, the graphics mode and the path to the driver file.</p>
<p>Once the driver has been loaded, initgraph() sets up the numeric values of the graphics mode chosen in the variables gd and gm respectively. Here we are assuming that the driver files are in the directory &#8216;c:\tc\bgi&#8217;. Hence the path passed to initgraph() is &#8216;c:\tc\bgi&#8217;.</p>
<p>The various mouse functions can be accessed by setting up the AX register with different values (service number) and issuing interrupt number 51. The functions are listed below.</p>
<table id="tbl" style="border-collapse: collapse; text-align: left; height: 507px;" border="1" cellspacing="0" cellpadding="0" width="438" align="center" bordercolor="#c0c0c0">
<tbody>
<tr height="55">
<td width="14%" align="middle"><strong>Interrupt</strong></td>
<td width="14%" align="middle"><strong>Service</strong></td>
<td width="100%" align="middle"><strong>Purpose</strong></td>
</tr>
<tr>
<td width="14%" height="89" align="middle">51</td>
<td width="14%" height="89" align="middle">0  <span style="font-size: 11pt;"> </span></td>
<td width="100%" height="89" align="middle">
<p align="justify">Reset mouse and get status<br />
Call with AX = 0<br />
Returns:  AX = FFFFh If mouse support is available<br />
Ax = 0 If mouse support is not available</td>
</tr>
<tr>
<td width="14%" height="73" align="middle">51</td>
<td width="14%" height="73" align="middle">1</td>
<td width="100%" height="73" align="middle">
<p align="left">Show mouse pointer<br />
Call with AX = 1<br />
Returns: Nothing</td>
</tr>
<tr>
<td width="14%" height="76" align="middle">51</td>
<td width="14%" height="76" align="middle">2</td>
<td width="100%" height="76" align="middle">
<p align="left">Hide mouse pointer<br />
Call with AX = 2<br />
Returns: Nothing</td>
</tr>
<tr>
<td width="14%" height="193" align="middle">51</td>
<td width="14%" height="193" align="middle">3</td>
<td width="100%" height="193" align="middle">
<p align="justify">Get mouse position and button status<br />
Call with AX = 3<br />
Returns: BX = mouse button status<br />
Bit   Significance<br />
0     button not pressed<br />
1     left button is pressed<br />
2     right button is pressed<br />
3     center button is pressed<br />
CX = x coordinate<br />
DX = y coordinate</td>
</tr>
<tr>
<td width="14%" height="114" align="middle">51</td>
<td width="14%" height="114" align="middle">4</td>
<td width="100%" height="114" align="middle">
<p align="left">Set mouse pointer position<br />
Call with AX = 4<br />
CX = x coordinate<br />
DX = y coordinate<br />
Returns: Nothing</td>
</tr>
<tr>
<td width="14%" height="113" align="middle">51</td>
<td width="14%" height="113" align="middle">7</td>
<td width="100%" height="113" align="middle">
<p align="left">Set horizontal limits for pointer<br />
Call with AX = 7<br />
CX = minimum x coordinate<br />
DX = maximum x coordinate<br />
Returns: Nothing</td>
</tr>
<tr>
<td width="14%" height="113" align="middle">51</td>
<td width="14%" height="113" align="middle">8</td>
<td width="100%" height="113" align="middle">
<p align="left">Set vertical limits for pointer<br />
Call with AX = 8<br />
CX = minimum y coordinate<br />
DX = maximum y coordinate<br />
Returns: Nothing</td>
</tr>
</tbody>
</table>
<p>Let us consider a program which makes use of the above functions.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #339900;">#include&amp;lt;graphics.h&amp;gt;</span>
<span style="color: #339900;">#include&amp;lt;stdio.h&amp;gt;</span>
<span style="color: #339900;">#include&amp;lt;conio.h&amp;gt;</span>
<span style="color: #339900;">#include&amp;lt;dos.h&amp;gt;</span>
<span style="color: #0000ff;">union</span> REGS in,out<span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">int</span> callmouse<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
in.<span style="color: #007788;">x</span>.<span style="color: #007788;">ax</span><span style="color: #000080;">=</span><span style="color: #0000dd;">1</span><span style="color: #008080;">;</span>
int86<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">51</span>,<span style="color: #000040;">&amp;</span>amp<span style="color: #008080;">;</span>in,<span style="color: #000040;">&amp;</span>amp<span style="color: #008080;">;</span>out<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #0000ff;">return</span> <span style="color: #0000dd;">1</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
<span style="color: #0000ff;">void</span> mouseposi<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> <span style="color: #000040;">&amp;</span>amp<span style="color: #008080;">;</span>xpos,<span style="color: #0000ff;">int</span> <span style="color: #000040;">&amp;</span>amp<span style="color: #008080;">;</span>ypos,<span style="color: #0000ff;">int</span> <span style="color: #000040;">&amp;</span>amp<span style="color: #008080;">;</span>click<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
in.<span style="color: #007788;">x</span>.<span style="color: #007788;">ax</span><span style="color: #000080;">=</span><span style="color: #0000dd;">3</span><span style="color: #008080;">;</span>
int86<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">51</span>,<span style="color: #000040;">&amp;</span>amp<span style="color: #008080;">;</span>in,<span style="color: #000040;">&amp;</span>amp<span style="color: #008080;">;</span>out<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
click<span style="color: #000080;">=</span>out.<span style="color: #007788;">x</span>.<span style="color: #007788;">bx</span><span style="color: #008080;">;</span>
xpos<span style="color: #000080;">=</span>out.<span style="color: #007788;">x</span>.<span style="color: #007788;">cx</span><span style="color: #008080;">;</span>
ypos<span style="color: #000080;">=</span>out.<span style="color: #007788;">x</span>.<span style="color: #007788;">dx</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
<span style="color: #0000ff;">int</span> mousehide<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
in.<span style="color: #007788;">x</span>.<span style="color: #007788;">ax</span><span style="color: #000080;">=</span><span style="color: #0000dd;">2</span><span style="color: #008080;">;</span>
int86<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">51</span>,<span style="color: #000040;">&amp;</span>amp<span style="color: #008080;">;</span>in,<span style="color: #000040;">&amp;</span>amp<span style="color: #008080;">;</span>out<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #0000ff;">return</span> <span style="color: #0000dd;">1</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
<span style="color: #0000ff;">void</span> setposi<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> <span style="color: #000040;">&amp;</span>amp<span style="color: #008080;">;</span>xpos,<span style="color: #0000ff;">int</span> <span style="color: #000040;">&amp;</span>amp<span style="color: #008080;">;</span>ypos<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
in.<span style="color: #007788;">x</span>.<span style="color: #007788;">ax</span><span style="color: #000080;">=</span><span style="color: #0000dd;">4</span><span style="color: #008080;">;</span>
in.<span style="color: #007788;">x</span>.<span style="color: #007788;">cx</span><span style="color: #000080;">=</span>xpos<span style="color: #008080;">;</span>
in.<span style="color: #007788;">x</span>.<span style="color: #007788;">dx</span><span style="color: #000080;">=</span>ypos<span style="color: #008080;">;</span>
int86<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">51</span>,<span style="color: #000040;">&amp;</span>amp<span style="color: #008080;">;</span>in,<span style="color: #000040;">&amp;</span>amp<span style="color: #008080;">;</span>out<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
<span style="color: #0000ff;">int</span> main<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
<span style="color: #0000ff;">int</span> x,y,cl,a,b<span style="color: #008080;">;</span>
clrscr<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #0000ff;">int</span> g<span style="color: #000080;">=</span>DETECT,m<span style="color: #008080;">;</span>
initgraph<span style="color: #008000;">&#40;</span><span style="color: #000040;">&amp;</span>amp<span style="color: #008080;">;</span>g,<span style="color: #000040;">&amp;</span>amp<span style="color: #008080;">;</span>m,<span style="color: #FF0000;">&quot;c:<span style="color: #000099; font-weight: bold;">\t</span>c<span style="color: #000099; font-weight: bold;">\b</span>gi&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
a<span style="color: #000080;">=</span><span style="color: #0000dd;">100</span><span style="color: #008080;">;</span>
b<span style="color: #000080;">=</span><span style="color: #0000dd;">400</span><span style="color: #008080;">;</span>
setposi<span style="color: #008000;">&#40;</span>a,b<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
callmouse<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #0000ff;">do</span>
<span style="color: #008000;">&#123;</span>
mouseposi<span style="color: #008000;">&#40;</span>x,y,cl<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
gotoxy<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">10</span>,<span style="color: #0000dd;">9</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #0000dd;">printf</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\t</span>Mouse Position is: %d,%d&quot;</span>,x,y<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #0000dd;">printf</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\t</span>Click: %d&quot;</span>,cl<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #0000dd;">printf</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\t</span>Press any key to hide the mouse&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span><span style="color: #0000ff;">while</span><span style="color: #008000;">&#40;</span><span style="color: #000040;">!</span>kbhit<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
getch<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
mousehide<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #0000dd;">printf</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\t</span>Press any key to Exit&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
getch<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>The above program makes use of the following functions:</p>
<p>*  callmouse( )<br />
*  mouseposi( )<br />
*  mousehide( )<br />
*  setposi( )</p>
<p><strong> callmouse() </strong> :-  In this function AX is set to &#8220;1&#8243;. When this function is called in main() it displays the mouse pointer. The position of the pointer can be changed by using the mouse.</p>
<p><strong>mousehide() </strong>:-  In this function AX is set to &#8220;2&#8243;.When this function is called in main() it hides the mouse pointer. This function is useful while drawing  figures, first the mouse pointer is kept hidden, then the figure is been drawn and again the mouse pointer is been called.</p>
<p><strong>mouseposi() </strong>:-  In this function AX is set to &#8220;3&#8243;. This function returns the position of the mouse pointer. It contains three parameters,they are xpos,ypos,click. xpos and ypos returns the position of x co-ordinate and y co-ordinate respectively. Click is the integer variable which returns the values 1,2,3 corresponding to the button pressed on the mouse and 0 for buttons being not pressed.</p>
<p><strong> kbhit:</strong> If any key is pressed kbhit returns nonzero integer; if not it returns zero</p>
<p><strong>setposi() </strong>:-      In this function AX is set to &#8220;4&#8243;. This function sets the mouse pointer to specific position . CX is been loaded by x co-ordinate of the mouse pointer and DX is been loaded with the y co-ordinate of the mouse pointer.</p>
<p>Let us consider another program</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #339900;">#include&amp;lt;graphics.h&amp;gt;</span>
<span style="color: #339900;">#include&amp;lt;stdio.h&amp;gt;</span>
<span style="color: #339900;">#include&amp;lt;conio.h&amp;gt;</span>
<span style="color: #339900;">#include&amp;lt;dos.h&amp;gt;</span>
<span style="color: #0000ff;">union</span> REGS in,out<span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">int</span> callmouse<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
in.<span style="color: #007788;">x</span>.<span style="color: #007788;">ax</span><span style="color: #000080;">=</span><span style="color: #0000dd;">1</span><span style="color: #008080;">;</span>
int86<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">51</span>,<span style="color: #000040;">&amp;</span>amp<span style="color: #008080;">;</span>in,<span style="color: #000040;">&amp;</span>amp<span style="color: #008080;">;</span>out<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #0000ff;">return</span> <span style="color: #0000dd;">1</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
<span style="color: #0000ff;">void</span> restrictmouseptr<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> x1,<span style="color: #0000ff;">int</span> y1,<span style="color: #0000ff;">int</span> x2,<span style="color: #0000ff;">int</span> y2<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
in.<span style="color: #007788;">x</span>.<span style="color: #007788;">ax</span><span style="color: #000080;">=</span><span style="color: #0000dd;">7</span><span style="color: #008080;">;</span>
in.<span style="color: #007788;">x</span>.<span style="color: #007788;">cx</span><span style="color: #000080;">=</span>x1<span style="color: #008080;">;</span>
in.<span style="color: #007788;">x</span>.<span style="color: #007788;">dx</span><span style="color: #000080;">=</span>x2<span style="color: #008080;">;</span>
int86<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">51</span>,<span style="color: #000040;">&amp;</span>amp<span style="color: #008080;">;</span>in,<span style="color: #000040;">&amp;</span>amp<span style="color: #008080;">;</span>out<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
in.<span style="color: #007788;">x</span>.<span style="color: #007788;">ax</span><span style="color: #000080;">=</span><span style="color: #0000dd;">8</span><span style="color: #008080;">;</span>
in.<span style="color: #007788;">x</span>.<span style="color: #007788;">cx</span><span style="color: #000080;">=</span>y1<span style="color: #008080;">;</span>
in.<span style="color: #007788;">x</span>.<span style="color: #007788;">dx</span><span style="color: #000080;">=</span>y2<span style="color: #008080;">;</span>
int86<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">51</span>,<span style="color: #000040;">&amp;</span>amp<span style="color: #008080;">;</span>in,<span style="color: #000040;">&amp;</span>amp<span style="color: #008080;">;</span>out<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
<span style="color: #0000ff;">int</span> main<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
<span style="color: #0000ff;">int</span> x,y,cl,a,b<span style="color: #008080;">;</span>
clrscr<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #0000ff;">int</span> g<span style="color: #000080;">=</span>DETECT,m<span style="color: #008080;">;</span>
initgraph<span style="color: #008000;">&#40;</span><span style="color: #000040;">&amp;</span>amp<span style="color: #008080;">;</span>g,<span style="color: #000040;">&amp;</span>amp<span style="color: #008080;">;</span>m,<span style="color: #FF0000;">&quot;c:<span style="color: #000099; font-weight: bold;">\t</span>c<span style="color: #000099; font-weight: bold;">\b</span>gi&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
rectangle<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">100</span>,<span style="color: #0000dd;">100</span>,<span style="color: #0000dd;">550</span>,<span style="color: #0000dd;">400</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
callmouse<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
restrictmouseptr<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">100</span>,<span style="color: #0000dd;">100</span>,<span style="color: #0000dd;">550</span>,<span style="color: #0000dd;">400</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
getch<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>The above program makes use of the following functions:</p>
<p>*   Horizontal ( )<br />
*   Vertical( )</p>
<p><strong>Horizontal()</strong> :- In this function AX is set to &#8220;7&#8243;. Its sets the horizontal barrier for the pointer which restricts the mouse pointer to pass that limit. CX is been loaded with the minimum x co-ordinate and Dx is been loaded with the maximum x co-ordinate.</p>
<p><strong>Vertical()</strong> :-     In this function AX is set to &#8220;8&#8243;.Its sets the vertical barrier for the pointer which restricts the mouse pointer to pass that limit. CX is been loaded with the minimum y co-ordinate and Dx is been loaded with the maximum y co-ordinate.</p>
<p><a href="http://electrofriends.com/wp-content/uploads/2008/11/mouse.zip">Click here to download all example programs. </a></p>
]]></content:encoded>
			<wfw:commentRss>http://electrofriends.com/articles/computer-science/c-tutorials/mouse-programming-in-cc/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Turbo C graphics programming</title>
		<link>http://electrofriends.com/articles/computer-science/c-tutorials/turbo-c-graphics-programming/</link>
		<comments>http://electrofriends.com/articles/computer-science/c-tutorials/turbo-c-graphics-programming/#comments</comments>
		<pubDate>Thu, 20 Nov 2008 10:45:39 +0000</pubDate>
		<dc:creator>Ranjith</dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[arc]]></category>
		<category><![CDATA[bar]]></category>
		<category><![CDATA[c graphics]]></category>
		<category><![CDATA[circle]]></category>
		<category><![CDATA[drawpoly]]></category>
		<category><![CDATA[ellipse]]></category>
		<category><![CDATA[fillpoly]]></category>
		<category><![CDATA[initgraph]]></category>
		<category><![CDATA[line]]></category>
		<category><![CDATA[outtextxy]]></category>
		<category><![CDATA[pieslice]]></category>
		<category><![CDATA[rectangle]]></category>
		<category><![CDATA[sector]]></category>
		<category><![CDATA[setfillstyle]]></category>
		<category><![CDATA[Turbo C graphics]]></category>

		<guid isPermaLink="false">http://electrofriends.com/?p=254</guid>
		<description><![CDATA[To start with graphics programming, Turbo C is a good choice. Even though DOS has its own limitations,  it is having a large number of  useful functions and is easy to program. To implement graphics algorithms,  To give graphical display of statistics, To view signals from any source, we can use C graphics. Here  is  [...]]]></description>
			<content:encoded><![CDATA[<p>To start with graphics programming, Turbo C is a good choice. Even though DOS has its own limitations,  it is having a large number of  useful functions and is easy to program. To implement graphics algorithms,  To give graphical display of statistics, To view signals from any source, we can use C graphics. Here  is  a article to start programming  with  Turbo  C. &#8216;Run and Learn&#8217; is  our   method.   We  have  used source codes throughout the explanations. Just  execute  them to understand what is happening.</p>
<p>Turbo C has a good collection of graphics libraries. If you know the basics of C, you can easily learn graphics programming. To start programming, let us write a small program that displays a circle on the screen.</p>
<p>/* simple.c<br />
example 1.0<br />
*/<br />
#include&lt;graphics.h&gt;<br />
#include&lt;conio.h&gt;</p>
<p>void main()<br />
{<br />
int gd=DETECT, gm;</p>
<p>initgraph(&amp;gd, &amp;gm, &#8220;c:\\turboc3\\bgi &#8221; );<br />
circle(200,100,150);</p>
<p>getch();<br />
closegraph();<br />
}</p>
<p>To run this program, you need graphics.h header file, graphics.lib library file and Graphics driver (BGI file) in the program folder. These files are part of Turbo C package. In all our programs we used 640&#215;480 VGA monitor. So all the programs are according to that specification. You need to make necessary changes to your programs according to your screen resolution. For VGA monitor, graphics driver used is EGAVGA.BGI.</p>
<p>Here, initgraph() function initializes the graphics mode and clears the screen. We will study the difference between text mode and graphics mode in detail latter.</p>
<p><strong> InitGraph: </strong> Initializes the graphics system.</p>
<p>Declaration:  void far initgraph(int far *graphdriver, int far *graphmode, char far *pathtodriver);</p>
<p>Remarks: To start the graphics system, you must first call initgraph.</p>
<p>initgraph initializes the graphics system by loading a graphics driver from disk (or validating a registered driver) then putting the system into graphics mode.</p>
<p>initgraph also resets all graphics settings (color, palette, current position, viewport, etc.) to their defaults, then resets graphresult to 0.<br />
Arguments:</p>
<p>*graphdriver: Integer that specifies the graphics driver to be used. You can give graphdriver a value using a constant of the graphics drivers enumeration type.</p>
<p>*graphmode : Integer that specifies the initial graphics mode (unless *graphdriver = DETECT). If *graphdriver = DETECT, initgraph sets *graphmode to the highest resolution available for the detected driver. You can give *graphmode a value using a constant of the graphics_modes enumeration type.</p>
<p>pathtodriver : Specifies the directory path where initgraph looks for graphics drivers (*.BGI) first.  If they&#8217;re not there, initgraph looks in the current directory.  If pathtodriver is null, the driver files must be in the current directory.  This is also the path settextstyle searches for the stroked character font files (*.CHR).</p>
<p>closegraph() function switches back the screen from graphcs mode to text mode. It clears the screen also. A graphics program should have a closegraph function at the end of graphics. Otherwise DOS screen will not go to text mode after running the program. Here, closegraph() is called after getch() since screen should not clear until user hits a key.</p>
<p>If you have the BGI file in the same folder of your program, you can just leave it as &#8220;&#8221; only. you need not mention *graphmode if you give *graphdriver as DETECT.</p>
<p>In graphics mode, all the screen co-ordinates are mentioned in terms of pixels. Number of pixels in the screen decides resolution of the screen. In the example 1.0,  circle is drawn with x-coordinate of the center 200, y-coordinate 100 and radius 150 pixels. All the coordinates are mentioned with respect to top-left corner of the screen.</p>
<p><strong>Basic Shapes and Colors:</strong></p>
<p>Now let us write a program to draw some basic shapes.</p>
<p>/*<br />
shapes.c<br />
example 1.1<br />
*/</p>
<p>#include&lt;graphics.h&gt;<br />
#include&lt;conio.h&gt;</p>
<p>void main()<br />
{<br />
int gd=DETECT, gm;<br />
int poly[12]={350,450, 350,410, 430,400, 350,350, 300,430, 350,450 };<br />
initgraph(&amp;gd, &amp;gm, &#8220;&#8221;);</p>
<p>circle(100,100,50);<br />
outtextxy(75,170, &#8220;Circle&#8221;);<br />
rectangle(200,50,350,150);<br />
outtextxy(240, 170, &#8220;Rectangle&#8221;);<br />
ellipse(500, 100,0,360, 100,50);<br />
outtextxy(480, 170, &#8220;Ellipse&#8221;);<br />
line(100,250,540,250);<br />
outtextxy(300,260,&#8221;Line&#8221;);</p>
<p>sector(150, 400, 30, 300, 100,50);<br />
outtextxy(120, 460, &#8220;Sector&#8221;);<br />
drawpoly(6, poly);<br />
outtextxy(340, 460, &#8220;Polygon&#8221;);<br />
getch();<br />
closegraph();<br />
}</p>
<p>Here is the screenshot of output:</p>
<div id="attachment_255" class="wp-caption aligncenter" style="width: 510px"><img class="size-full wp-image-255" title="Output of above program" src="http://electrofriends.com/wp-content/uploads/2008/11/c_grap1.gif" alt="Output of above program" width="500" height="375" /><p class="wp-caption-text">Output of above program</p></div>
<p>Here, circle() function takes x, y coordinates of the circle with respect to left top of the screen and radius of the circle in terms of pixels as arguments. Not that, in graphics, almost all the screen parameters are measured in terms of pixels.</p>
<p>Function outtextxy() displays a string in graphical mode. You can use different fonts, text sizes, alignments, colors and directions of the text that we will study later. Parameters passed are x and y coordinates of the position on the screen where text is to be displayed. There is another function outtext() that displays a text in the current position. Current position is the place where last drawing is ended. These functions are declared as follows:</p>
<p>void far outtextxy(int x, int y, char *text);<br />
void far outtext(char *text);</p>
]]></content:encoded>
			<wfw:commentRss>http://electrofriends.com/articles/computer-science/c-tutorials/turbo-c-graphics-programming/feed/</wfw:commentRss>
		<slash:comments>28</slash:comments>
		</item>
		<item>
		<title>Sorting of numbers</title>
		<link>http://electrofriends.com/articles/computer-science/c-tutorials/sorting-of-numbers/</link>
		<comments>http://electrofriends.com/articles/computer-science/c-tutorials/sorting-of-numbers/#comments</comments>
		<pubDate>Tue, 04 Nov 2008 20:04:34 +0000</pubDate>
		<dc:creator>Ranjith</dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[Bubble sort]]></category>
		<category><![CDATA[c program]]></category>
		<category><![CDATA[demo in sorting]]></category>
		<category><![CDATA[graphics program]]></category>
		<category><![CDATA[Insertion sort]]></category>
		<category><![CDATA[Selection sort]]></category>

		<guid isPermaLink="false">http://electrofriends.com/?p=44</guid>
		<description><![CDATA[Sorting means arranging a set of data in some order. There are different methods that are used to sort the data in ascending order. Some of the  methods are

 Selection sort
 Bubble sort
 Insertion sort

1. Selection sort
Here, to sort the data in ascending order, the 0th element is compared with all other elements. If it [...]]]></description>
			<content:encoded><![CDATA[<p>Sorting means arranging a set of data in some order. There are different methods that are used to sort the data in ascending order. Some of the  methods are</p>
<ol>
<li> Selection sort</li>
<li> Bubble sort</li>
<li> Insertion sort</li>
</ol>
<p><strong>1. Selection sort</strong></p>
<p>Here, to sort the data in ascending order, the 0th element is compared with all other elements. If it is greater than the compared element then they are interchanged. So after the first iteration smallest element is placed at the 0th position. The same procedure is repeated for the 1st element and so on. <a href="http://electrofriends.com/source-codes/software-programs/c/sorting-programs/program-to-sort-the-numbers-using-selection-sort/">Read more&#8230;</a></p>
<p><strong>2. Bubble sort</strong></p>
<p>Here, to sort the data in ascending order, 0th element is compared with the 1st element. If it is greater than the 1st element then they are interchanged else remains same. Then 1st element is compared with 2nd element and procedure is continued. So after the first iteration largest element is placed at the last position. In the second iteration, the comparisons are made till the last but one position and now second largest element is placed at the second last position. After all the iterations, the list becomes sorted. <a href="http://electrofriends.com/source-codes/software-programs/c/sorting-programs/program-to-sort-the-numbers-using-bubble-sort/">Read more&#8230;</a></p>
<p><strong>3. Insertion sort</strong></p>
<p>Here, sorting takes place by inserting a particular element at the appropriate position. To sort the element in ascending order, in first iteration,1st element is compared with the 0th element. In the second iteration 2nd element is compared with 0th and 1st element. In general, in every iteration an element is compared with all the elements before it. While comparing if it is found that the element in question can be inserted at a suitable position, then space is created for it by shifting the other element one position to the right and inserting the element at the suitable position. This procedure is repeated for all the elements in the list. <a href="../source-codes/software-programs/c/sorting-programs/program-to-sort-the-numbers-using-insertion-sort/">Read more&#8230;</a></p>
<p>In my program, you can enter 5 numbers which are to be sorted by any one of the above methods. After entering the numbers they are shown in red colour box and while comparison is done, the two elements which are compared are shown in green colour box. After sorting the elements, their permanent position is indicated by blue colour box. <a href="http://electrofriends.com/wp-content/uploads/2008/11/sort.zip">Click here to download the program</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://electrofriends.com/articles/computer-science/c-tutorials/sorting-of-numbers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
