<?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>Clinuxpro</title>
	<atom:link href="http://clinuxpro.com/feed" rel="self" type="application/rss+xml" />
	<link>http://clinuxpro.com</link>
	<description>Start learning Linux programming here</description>
	<lastBuildDate>Sat, 18 Feb 2012 08:29:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Character Vs Block device drivers</title>
		<link>http://clinuxpro.com/character-vs-block-device-driver</link>
		<comments>http://clinuxpro.com/character-vs-block-device-driver#comments</comments>
		<pubDate>Fri, 17 Feb 2012 11:01:27 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Device Drivers Interview Questions]]></category>

		<guid isPermaLink="false">http://clinuxpro.com/?p=1545</guid>
		<description><![CDATA[Character device is a device from which data is read or written as a stream of bytes i.e as a stream of bytes. Block device as the name suggests is a device from which data is read or written as blocks, or chunk of data at once.]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;"><strong>What is the difference between a character device and a block device drivers?</strong></p>
<p style="text-align: justify;">Character device is a device from which data is read or written as a stream of bytes i.e as a stream of bytes.</p>
<p>Examples : Serial ports, Consoles etc</p>
<p>Block device as the name suggests is a device from which data is read or written as blocks, or chunk of data at once. Normally a block would be of 4096 bytes.</p>
<p>Examples: Hard drives on the system.</p>
<p>The performance of a block driver is important as it involves movement of data from the physical memory to the virtual memory (hard disk) whenever there is a process switch. Where as performance of a character driver does not affect the performance of the system much.</p>
]]></content:encoded>
			<wfw:commentRss>http://clinuxpro.com/character-vs-block-device-driver/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How do we know which major number and minor numbers are already used?</title>
		<link>http://clinuxpro.com/how-do-we-know-which-major-number-and-minor-numbers-are-already-used</link>
		<comments>http://clinuxpro.com/how-do-we-know-which-major-number-and-minor-numbers-are-already-used#comments</comments>
		<pubDate>Fri, 17 Feb 2012 10:32:44 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Device Drivers Interview Questions]]></category>

		<guid isPermaLink="false">http://clinuxpro.com/?p=1541</guid>
		<description><![CDATA[The list of all the devices connected to the system can be found in /dev directory. By typing ls -l in that directory we can find all the used major and minor numbers.]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">The list of all the devices connected to the system can be found in /dev directory. When we type ls -l in the directory /dev the character devices are found as<br />
<em></em></p>
<p style="text-align: justify;"><em>crw&#8211;w&#8211;w-  1 root    root   <strong> 1,</strong>   7          2011-08-17   18:54    full</em></p>
<p style="text-align: justify;">here c specifes it as a char device<br />
and<br />
<em></em></p>
<p style="text-align: justify;"><em>b&#8212;&#8212;&#8212;  1 root    root        <strong> 2</strong>,  68      2011-08-17   8:54     fd0u830</em></p>
<p style="text-align: justify;">b would specify a block device.</p>
<p>And in the above 1 which is bold is the major number and 7 is the minor number. which specify that the device using a driver with major number one and the minor number of the device is 7. similarly for the second one 2  is the major number and 68 is the minor number.</p>
]]></content:encoded>
			<wfw:commentRss>http://clinuxpro.com/how-do-we-know-which-major-number-and-minor-numbers-are-already-used/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Major Number and Minor Number</title>
		<link>http://clinuxpro.com/major-number-and-minor-number</link>
		<comments>http://clinuxpro.com/major-number-and-minor-number#comments</comments>
		<pubDate>Fri, 17 Feb 2012 09:29:50 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Device Drivers Interview Questions]]></category>

		<guid isPermaLink="false">http://clinuxpro.com/?p=1537</guid>
		<description><![CDATA[The major number specifies which driver to use and if you have more devices connected to the system using the same driver, those are distinguished using the minor numbers.]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;"><strong>What are Major and Minor Numbers of a device driver?</strong><br />
<strong>What is Major number?</strong><br />
<strong>What is Minor number?</strong></p>
<p>As every person has a surname/family name and the normal name for their identification. Device drivers also need to be identified and these are done using the Major number (family name) and minor number (normal name).</p>
<p>The major number specifies which driver to use and if you have more devices connected to the system using the same driver, those are distinguished using the minor numbers.</p>
<p>We can get them allocated using the following calls<br />
These are present in <strong>&lt;linux/kdev_t.h&gt;</strong></p>
<p>Macro that return major number is  <em>MAJOR(dev_t dev);</em><br />
and minor number is<em> MINOR(dev_t dev);</em></p>
<p>From the above the kernel will allocate the major and minor number to the dev_t structure</p>
<p>If you want to give a specific  major and minor numbers and need to turn them into a dev_t, then the following macro has to be called <strong>MKDEV(int major, int minor);</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://clinuxpro.com/major-number-and-minor-number/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What is IRQ?</title>
		<link>http://clinuxpro.com/what-is-irq</link>
		<comments>http://clinuxpro.com/what-is-irq#comments</comments>
		<pubDate>Wed, 15 Feb 2012 08:22:12 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Device Drivers Interview Questions]]></category>

		<guid isPermaLink="false">http://clinuxpro.com/?p=1530</guid>
		<description><![CDATA[what is IRQ? how will you register your IRQ no? Are you sure you will get the IRQ no you have requested? What if you don't get?]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;"><strong>What is IRQ? How will you register your IRQ no? Are you sure you will get the IRQ no you have requested? What if you don&#8217;t get?</strong></p>
<p>Before getting into <strong>Interrupt request queue (IRQ)</strong>, let us understand interrupts. Interrupts are a mechanism using which you will ask the processor to do a particular task.</p>
<p style="text-align: justify;">These are mechanisms that the processor cannot ignore and whenever a interrupt comes, the processor will move the present working process and has to handle the interrupt. For handling the interrupt for a particular device, we need to register the interrupt handler. There are a limited number of interrupt lines available and hence you would need to request the processor to allocate a interrupt line for your device. So you request for a interrupt and the interrupt line that is requested is called an interrupt request queue.</p>
<p>For getting an IRQ there are APIs given in &lt;linux/interrupt.h&gt;</p>
<p style="text-align: justify;">int request_irq(unsigned int irq,<br />
irqreturn_t (*handler)(int, void *, struct pt_regs *),unsigned long flags,const char *dev_name,<br />
void *dev_id);<br />
void free_irq(unsigned int irq, void *dev_id);</p>
<p>From above it can be seen that<br />
irq  is the interrupt number that you are requesting for.</p>
<p>Handler is a function pointer to the function that is to be called when an interrupt occurs.</p>
<p>Flags are<br />
<strong></strong></p>
<p style="text-align: justify;"><strong>SA_INTERRUPT</strong><br />
When set, this indicates a “fast” interrupt handler. Fast handlers are executed<br />
with interrupts disabled on the current processor<br />
<strong></strong></p>
<p style="text-align: justify;"><strong>SA_SHIRQ</strong><br />
This bit signals that the interrupt can be shared between devices.</p>
<p><strong>SA_SAMPLE_RANDOM</strong><br />
This bit indicates that the generated interrupts can contribute to the entropy pool used by /dev/random and /dev/urandom.</p>
<p>The retrun value of the request_irq function call is &#8217;0&#8242; if the the interrupt line with the number asked in the &#8216;irq&#8217; parameter is allocated, else a negative error code is returned.</p>
<p>There are kernel defined functions which the user can use to request the kernel to give the available interrupts before going ahead to request one, like <strong>unsigned long probe_irq_on(void);</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://clinuxpro.com/what-is-irq/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Why not vmalloc for device drivers?</title>
		<link>http://clinuxpro.com/why-not-vmalloc-for-device-drivers</link>
		<comments>http://clinuxpro.com/why-not-vmalloc-for-device-drivers#comments</comments>
		<pubDate>Sat, 11 Feb 2012 11:48:51 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Device Drivers Interview Questions]]></category>

		<guid isPermaLink="false">http://clinuxpro.com/?p=1527</guid>
		<description><![CDATA[Vmalloc also allocates memory contiguously in the virtual address space, but in physical address space the memory pages might not be contiguous.]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;"><strong>Vmalloc</strong> also allocates memory contiguously in the virtual address space, but in physical address space the memory pages might not be contiguous.</p>
<p>The memory that is obtained using vmalloc is not that efficient to work as with the memory allocated when kmalloc is used.</p>
<p>The memory that is set aside for the vmalloc in some architectures is less when compared to kmalloc and hence if you try to allocate more memory it might fail.</p>
<p>Vmalloc allocates memory by building the page tables that is tweaking them rather than directly using.</p>
<p>i.e the memory allocated by vmalloc is contiguous as far as the user understands but it could be memory pages fetched from different physical memory locations and a page table built on top of it.</p>
<p>So the overhead on vmalloc is high as it not only has to fetch the free pages but also build the page tables for the same.</p>
<p>So the only point where vmalloc should be used is when you need very large memory like the one during the module creation, when the code and data copied is large and a continuous memory allocation is not possible.</p>
]]></content:encoded>
			<wfw:commentRss>http://clinuxpro.com/why-not-vmalloc-for-device-drivers/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How will you allocate memory in your driver?</title>
		<link>http://clinuxpro.com/how-will-you-allocate-memory-in-your-driver</link>
		<comments>http://clinuxpro.com/how-will-you-allocate-memory-in-your-driver#comments</comments>
		<pubDate>Sat, 11 Feb 2012 11:45:15 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Device Drivers Interview Questions]]></category>

		<guid isPermaLink="false">http://clinuxpro.com/?p=1524</guid>
		<description><![CDATA[Using kmalloc.  Kmalloc will assign memory contigiously.This call can block(put the process to sleep) if sufficient memory is not available.  i.e it waits until the requested amount of memory is available.]]></description>
			<content:encoded><![CDATA[<p><strong>Using kmalloc.</strong>  Kmalloc will assign memory contigiously.This call can block(put the process to sleep) if sufficient memory is not available.  i.e it waits until the requested amount of memory is available.</p>
<p>void *kmalloc(size_t size, int flags);</p>
<p>flags can be</p>
<p>GFP_USER<br />
GFP_KERNEL<br />
The above two flags can put the process to sleep<br />
GFP_NOFS<br />
GFP_NOIO<br />
the above two flags will disable the file and input output systems<br />
GFP_ATOMIC<br />
the process cannot be put to sleep. i.e if memory is not available the allocation fails</p>
]]></content:encoded>
			<wfw:commentRss>http://clinuxpro.com/how-will-you-allocate-memory-in-your-driver/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Why you want to write a device driver?</title>
		<link>http://clinuxpro.com/why-you-want-to-write-a-device-driver</link>
		<comments>http://clinuxpro.com/why-you-want-to-write-a-device-driver#comments</comments>
		<pubDate>Sat, 11 Feb 2012 11:40:05 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Device Drivers Interview Questions]]></category>

		<guid isPermaLink="false">http://clinuxpro.com/?p=1521</guid>
		<description><![CDATA[Device driver acts as an interface between the device(hardware) and the user.The user gives the inputs and the device driver helps the device to understand the input given by the user and act on it.]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">Device driver acts as an interface between the device (hardware) and the user.</p>
<p>The user gives the inputs and the device driver helps the device to understand the input given by the user and act on it.</p>
<p>So device drivers are way for the user to interact with the hardware connected.</p>
]]></content:encoded>
			<wfw:commentRss>http://clinuxpro.com/why-you-want-to-write-a-device-driver/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Area of a Trapezium</title>
		<link>http://clinuxpro.com/area-of-a-trapezium</link>
		<comments>http://clinuxpro.com/area-of-a-trapezium#comments</comments>
		<pubDate>Wed, 18 Jan 2012 15:38:15 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C programming Interview Questions]]></category>
		<category><![CDATA[Area and Volume]]></category>

		<guid isPermaLink="false">http://clinuxpro.com/?p=1517</guid>
		<description><![CDATA[Write a c program to find the area of a trapezium ]]></description>
			<content:encoded><![CDATA[<p><strong>Write a c program to find the area of a trapezium</strong></p>
<p>Formula of area of trapezium:<br />
Area = (1/2) * (a + b) * h</p>
<pre class="brush: c">
#include&lt;stdio.h&gt;

int main(){

float b1,b2,h;
float area;

printf(&quot;Enter the size of two bases and height of the trapezium : &quot;);
scanf(&quot;%f%f%f&quot;,&amp;b1,&amp;b2,&amp;h);

area = 0.5 * ( b1 + b2 ) * h ;

printf(&quot;Area of trapezium is: %.3f&quot;,area);

return 0;
}</pre>
<p><strong>Output:</strong></p>
<p>Enter the size of two bases and height of the trapezium: 5 8 3<br />
Area of trapezium is: 19.500</p>
]]></content:encoded>
			<wfw:commentRss>http://clinuxpro.com/area-of-a-trapezium/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Area of a Rectangle</title>
		<link>http://clinuxpro.com/area-of-a-rectangle</link>
		<comments>http://clinuxpro.com/area-of-a-rectangle#comments</comments>
		<pubDate>Wed, 18 Jan 2012 15:31:12 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C programming Interview Questions]]></category>
		<category><![CDATA[Area and Volume]]></category>

		<guid isPermaLink="false">http://clinuxpro.com/?p=1515</guid>
		<description><![CDATA[Write a c program to find the area of a rectangle]]></description>
			<content:encoded><![CDATA[<p><strong>Write a c program to find the area of a rectangle</strong></p>
<p>Formula of area of triangle:<br />
Area = length * width</p>
<pre class="brush: c">
#include&lt;stdio.h&gt;
int main(){
float l,w;
float area;
printf(&quot;Enter size of each sides of the rectangle : &quot;);
scanf(&quot;%f%f&quot;,&amp;l,&amp;w);
area = l * w;
printf(&quot;Area of rectangle is: %.3f&quot;,area);
return 0;
}</pre>
<p><strong>Output:</strong></p>
<p>Enter size of each sides of the rectangle: 5.2 20<br />
Area of rectangle is: 104.000</p>
]]></content:encoded>
			<wfw:commentRss>http://clinuxpro.com/area-of-a-rectangle/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Area of a right angled Triangle</title>
		<link>http://clinuxpro.com/area-of-a-right-angled-triangle</link>
		<comments>http://clinuxpro.com/area-of-a-right-angled-triangle#comments</comments>
		<pubDate>Wed, 18 Jan 2012 15:12:24 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C programming Interview Questions]]></category>
		<category><![CDATA[Area and Volume]]></category>

		<guid isPermaLink="false">http://clinuxpro.com/?p=1509</guid>
		<description><![CDATA[Write a c program to find the area of a right angled triangle]]></description>
			<content:encoded><![CDATA[<p><strong>Write a c program to find the area of a right angled triangle</strong></p>
<p>Formula of area of right angled triangle:<br />
Area = (1/2) * height * width</p>
<pre class="brush: c">
#include&lt;stdio.h&gt;

int main(){

float h,w;
float area;

printf(&quot;Enter height and width of the right angled triangle : &quot;);
scanf(&quot;%f%f&quot;,&amp;amp;amp;amp;h,&amp;amp;amp;amp;w);

area = 0.5 * h * w;

printf(&quot;Area of right angled triangle is: %.3f&quot;,area);

return 0;
}</pre>
<p><strong>Output:</strong></p>
<p>Enter height and width of the right angled triangle: 10 5<br />
Area of right angled triangle is: 25.000</p>
]]></content:encoded>
			<wfw:commentRss>http://clinuxpro.com/area-of-a-right-angled-triangle/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Area of an Equilateral Triangle</title>
		<link>http://clinuxpro.com/area-of-an-equilateral-triangle</link>
		<comments>http://clinuxpro.com/area-of-an-equilateral-triangle#comments</comments>
		<pubDate>Wed, 18 Jan 2012 15:09:27 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C programming Interview Questions]]></category>
		<category><![CDATA[Area and Volume]]></category>

		<guid isPermaLink="false">http://clinuxpro.com/?p=1507</guid>
		<description><![CDATA[Write a c program to find the area of an equilateral triangle ]]></description>
			<content:encoded><![CDATA[<p><strong>Write a c program to find the area of an equilateral triangle</strong></p>
<p>Formula of area of equilateral triangle:<br />
Area = (√3)/4 * a2</p>
<pre class="brush: c">
#include&lt;stdio.h&gt;
#include&lt;math.h&gt;

int main(){

float a;
float area;

printf(&quot;Enter size of side of the equilateral triangle : &quot;);
scanf(&quot;%f&quot;,&amp;a);

area = sqrt(3)/4*(a*a);

printf(&quot;Area of equilateral triangle is: %.3f&quot;,area);

return 0;
}</pre>
<p><strong>Output:</strong></p>
<p>Enter size of side of the equilateral triangle: 5<br />
Area of equilateral triangle is: 10.825</p>
]]></content:encoded>
			<wfw:commentRss>http://clinuxpro.com/area-of-an-equilateral-triangle/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Area of a Triangle</title>
		<link>http://clinuxpro.com/area-of-atriangle</link>
		<comments>http://clinuxpro.com/area-of-atriangle#comments</comments>
		<pubDate>Wed, 18 Jan 2012 14:39:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C programming Interview Questions]]></category>
		<category><![CDATA[Area and Volume]]></category>

		<guid isPermaLink="false">http://clinuxpro.com/?p=1503</guid>
		<description><![CDATA[Write a c program to find the area of a triangle ]]></description>
			<content:encoded><![CDATA[<h3>Write a c program to find the area of a triangle</h3>
<p>Formula for area of any triangle:</p>
<p>Area = √(s*(s-a)*(s-b)*(s-c))<br />
Where s = (a + b + c)/2</p>
<pre class="brush: c">
#include&lt;stdio.h&gt;
#include&lt;math.h&gt;

int main(){

float a,b,c;
float s,area;

printf(&quot;Enter size of each sides of triangle&quot;);
scanf(&quot;%f%f%f&quot;,&amp;amp;amp;a,&amp;amp;amp;b,&amp;amp;amp;c);

s = (a+b+c)/2;
area = sqrt(s*(s-a)*(s-b)*(s-c));

printf(&quot;Area of triangle is: %.3f&quot;,area);

return 0;
}</pre>
<p><strong>Output:</strong></p>
<p>Enter size of each sides of the triangle: 2 4 5<br />
Area of triangle is: 3.800</p>
]]></content:encoded>
			<wfw:commentRss>http://clinuxpro.com/area-of-atriangle/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Area of a Circle</title>
		<link>http://clinuxpro.com/area-of-a-circle</link>
		<comments>http://clinuxpro.com/area-of-a-circle#comments</comments>
		<pubDate>Wed, 18 Jan 2012 14:35:23 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C programming Interview Questions]]></category>
		<category><![CDATA[Area and Volume]]></category>

		<guid isPermaLink="false">http://clinuxpro.com/?p=1500</guid>
		<description><![CDATA[C Program to Calculate area of a circle]]></description>
			<content:encoded><![CDATA[<p><strong>C Program to Calculate area of a circle</strong></p>
<pre class="brush: c">
#include &lt;stdio.h&gt;
#define PI 3.141
int main(){
float r, a;
printf(&quot;Radius: &quot;);
scanf(&quot;%f&quot;, &amp;amp;r);
a = PI * r * r;
printf(&quot;%f\n&quot;, a);
return 0;
}</pre>
<p><strong>Mathematical formula for area of circle</strong></p>
<p><strong>Area = Pie*radius*radius</strong></p>
<p>Here Pie is constant which is equal to</p>
<p>Pie = 22/7  or</p>
<p>3.1415926535897932384626&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://clinuxpro.com/area-of-a-circle/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Binary search using Recursion</title>
		<link>http://clinuxpro.com/binary-search-using-recursion</link>
		<comments>http://clinuxpro.com/binary-search-using-recursion#comments</comments>
		<pubDate>Tue, 17 Jan 2012 18:23:18 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C programming Interview Questions]]></category>
		<category><![CDATA[Searching]]></category>

		<guid isPermaLink="false">http://clinuxpro.com/?p=1498</guid>
		<description><![CDATA[Write a simple code for binary search using function recursion in c programming language]]></description>
			<content:encoded><![CDATA[<p><strong>Write a simple code for binary search using function recursion in c programming language</strong></p>
<pre class="brush: c"> #include&lt;stdio.h&gt;
int main(){

int a[10],i,n,m,c,l,u;

printf(&quot;Enter the size of an array: &quot;);
scanf(&quot;%d&quot;,&amp;n);

printf(&quot;Enter the elements of the array: &quot; );
for(i=0;i&lt;n;i++){
scanf(&quot;%d&quot;,&amp;a[i]);
}

printf(&quot;Enter the number to be search: &quot;);
scanf(&quot;%d&quot;,&amp;m);

l=0,u=n-1;
c=binary(a,n,m,l,u);
if(c==0)
printf(&quot;Number is not found.&quot;);
else
printf(&quot;Number is found.&quot;);

return 0;
}

int binary(int a[],int n,int m,int l,int u){

int mid,c=0;

if(l&lt;=u){
mid=(l+u)/2;
if(m==a[mid]){
c=1;
}
else if(m&lt;a[mid]){
return binary(a,n,m,l,mid-1);
}
else
return binary(a,n,m,mid+1,u);
}
else
return c;
}</pre>
<p><strong>Output:</strong></p>
<p>Enter the size of an array: 5<br />
Enter the elements of the array: 8 9 10 11 12<br />
Enter the number to be search: 8<br />
Number is found.</p>
]]></content:encoded>
			<wfw:commentRss>http://clinuxpro.com/binary-search-using-recursion/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Binary Search C Program</title>
		<link>http://clinuxpro.com/binary-search-c-program</link>
		<comments>http://clinuxpro.com/binary-search-c-program#comments</comments>
		<pubDate>Tue, 17 Jan 2012 18:15:32 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C programming Interview Questions]]></category>
		<category><![CDATA[Searching]]></category>

		<guid isPermaLink="false">http://clinuxpro.com/?p=1496</guid>
		<description><![CDATA[Write a c program to search an element in an array using binary search]]></description>
			<content:encoded><![CDATA[<p><strong>Write a simple code for binary search in c programming language</strong></p>
<p><strong>Write a c program to search an element in an array using binary search</strong></p>
<pre class="brush: c">
#include&lt;stdio.h&gt;
int main(){

int a[10],i,n,m,c=0,l,u,mid;

printf(&quot;Enter the size of an array: &quot;);
scanf(&quot;%d&quot;,&amp;n);

printf(&quot;Enter the elements in ascending order: &quot;);
for(i=0;i&lt;n;i++){
scanf(&quot;%d&quot;,&amp;a[i]);
}

printf(&quot;Enter the number to be search: &quot;);
scanf(&quot;%d&quot;,&amp;m);

l=0,u=n-1;
while(l&lt;=u){
mid=(l+u)/2;
if(m==a[mid]){
c=1;
break;
}
else if(m&lt;a[mid]){
u=mid-1;
}
else
l=mid+1;
}
if(c==0)
printf(&quot;The number is not found.&quot;);
else
printf(&quot;The number is found.&quot;);

return 0;
}</pre>
<p><strong>Output:</strong></p>
<p>Enter the size of an array: 5<br />
Enter the elements in ascending order: 4 7 8 11 21<br />
Enter the number to be search: 11<br />
The number is found.</p>
]]></content:encoded>
			<wfw:commentRss>http://clinuxpro.com/binary-search-c-program/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linear Search C Program</title>
		<link>http://clinuxpro.com/linear-search-c-program</link>
		<comments>http://clinuxpro.com/linear-search-c-program#comments</comments>
		<pubDate>Tue, 17 Jan 2012 18:00:58 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C programming Interview Questions]]></category>
		<category><![CDATA[Searching]]></category>

		<guid isPermaLink="false">http://clinuxpro.com/?p=1493</guid>
		<description><![CDATA[Write a c program to search an element in an array using linear search]]></description>
			<content:encoded><![CDATA[<p><strong>Write a simple code for linear search in c programming language</strong></p>
<p><strong>Write a c program to search an element in an array using linear search</strong></p>
<pre class="brush: c">
#include&lt;stdio.h&gt;
int main(){

int a[10],i,n,m,c=0;

printf(&quot;Enter the size of an array: &quot;);
scanf(&quot;%d&quot;,&amp;amp;n);

printf(&quot;Enter the elements of the array: &quot;);
for(i=0;i&lt;=n-1;i++){
scanf(&quot;%d&quot;,&amp;amp;a[i]);
}

printf(&quot;Enter the number to be search: &quot;);
scanf(&quot;%d&quot;,&amp;amp;m);
for(i=0;i&lt;=n-1;i++){
if(a[i]==m){
c=1;
break;
}
}
if(c==0)
printf(&quot;The number is not in the list&quot;);
else
printf(&quot;The number is found&quot;);

return 0;
}</pre>
<p><strong>Output:</strong></p>
<p>Enter the size of an array: 5<br />
Enter the elements of the array: 4 6 8 0 3<br />
Enter the number to be search: 0<br />
The number is found</p>
]]></content:encoded>
			<wfw:commentRss>http://clinuxpro.com/linear-search-c-program/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Shell Sort C Program</title>
		<link>http://clinuxpro.com/shell-sort-c-program</link>
		<comments>http://clinuxpro.com/shell-sort-c-program#comments</comments>
		<pubDate>Tue, 17 Jan 2012 17:34:39 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C programming Interview Questions]]></category>
		<category><![CDATA[Sorting]]></category>

		<guid isPermaLink="false">http://clinuxpro.com/?p=1490</guid>
		<description><![CDATA[Source code of simple Shell sort implementation using array in ascending order in c programming language]]></description>
			<content:encoded><![CDATA[<p><strong>Source code of simple Shell sort implementation using array in ascending order in c programming language</strong></p>
<pre class="brush: c">
#include &lt;stdio.h&gt;

void shellsort(int A[],int max)
{
int stop,swap,limit,temp,k;
int x=(int)(max/2)-1;
while(x&gt;0)
{
stop=0;
limit=max-x;
while(stop==0)
{
swap=0;

for(k=0; kA[k+x])
{
temp=A[k];
A[k]=A[k+x];
A[k+x]=temp;
swap=k;
}
}
limit=swap-x;
if(swap==0)
stop=1;
}
x=(int)(x/2);
}
}
int main()
{

int i,ELEMENTS,X[100];
printf(&quot;Enter the number of elements to be sorted:&quot;);
scanf(&quot;%d&quot;,&amp;ELEMENTS);
printf(&quot;Enter the elements to be sorted:\n&quot;);
for(i = 0; i &lt; ELEMENTS; i++ ){
scanf(&quot;%d&quot;,&amp;X[i]);
}
printf(&quot;Unsorted Array:\n&quot;);
for(i=0;i &lt; ELEMENTS;i++)
printf(&quot;%d &quot;,X[i]);

shellsort(X,ELEMENTS);
printf(&quot;\nSORTED ARRAY\n&quot;);
for(i=0;i &lt; ELEMENTS;i++)
printf(&quot;%d &quot;,X[i]);

printf(&quot;\n&quot;);
}</pre>
<p><strong>Output:</strong></p>
<p>Enter the number of elements to be sorted: 5<br />
Enter the elements to be sorted: 2 6 4 1 2<br />
Unsorted Array: 2 6 4 1 2<br />
SORTED ARRAY 2 1 4 2 6</p>
]]></content:encoded>
			<wfw:commentRss>http://clinuxpro.com/shell-sort-c-program/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Heap Sort C Program</title>
		<link>http://clinuxpro.com/heap-sort-c-program</link>
		<comments>http://clinuxpro.com/heap-sort-c-program#comments</comments>
		<pubDate>Tue, 17 Jan 2012 17:19:02 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C programming Interview Questions]]></category>
		<category><![CDATA[Sorting]]></category>

		<guid isPermaLink="false">http://clinuxpro.com/?p=1487</guid>
		<description><![CDATA[Source code of simple heap sort implementation using array in ascending order in c programming language]]></description>
			<content:encoded><![CDATA[<p><strong>Source code of simple heap sort implementation using array in ascending order in c programming language</strong></p>
<pre class="brush: c">
#include &lt;stdio.h&gt;
#include &lt;malloc.h&gt;

void main()
{
int *x,i,n;
int temp;
void heap(int *,int);

fflush(stdin);
printf(&quot;Heap Sort&quot;);
printf(&quot;Enter How many Numbers : &quot;);
scanf(&quot;%d&quot;,&amp;n);
x = (int *)malloc(n * sizeof(int));
printf(&quot;Enter the elements into the array :&quot;);
for(i=0;i=1;i--)
{
temp =  x[i];
x[i] = x[0];
x[0] = temp;
heap(x,i-1);
}

printf(&quot;The array after sorting is \n&quot;);
for(i=0;i=0;i--)
{
if(a[(2*i)+1] &lt; a[(2*i)+2] &amp;&amp; (2*i+1)&lt;=n &amp;&amp; (2*i+2)&lt;=n)
{
temp = a[(2*i)+1];
a[(2*i)+1] = a[(2*i)+2];
a[(2*i)+2] = temp;
}
if(a[(2*i)+1] &gt; a[i] &amp;&amp; (2*i+1)&lt;=n &amp;&amp; i&lt;=n)
{
temp = a[(2*i)+1];
a[(2*i)+1] = a[i];
a[i] = temp;
}
}
}</pre>
<p><strong>Output:</strong></p>
<p>Heap Sort Enter How many Numbers : 5<br />
Enter the elements into the array : 2 5 0 9 1<br />
The array after sorting is 0 1 2 5 9</p>
]]></content:encoded>
			<wfw:commentRss>http://clinuxpro.com/heap-sort-c-program/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mergesort C program</title>
		<link>http://clinuxpro.com/mergesort-c-program</link>
		<comments>http://clinuxpro.com/mergesort-c-program#comments</comments>
		<pubDate>Tue, 17 Jan 2012 17:12:33 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C programming Interview Questions]]></category>
		<category><![CDATA[Sorting]]></category>

		<guid isPermaLink="false">http://clinuxpro.com/?p=1484</guid>
		<description><![CDATA[Source code of simple merge sort implementation using array in ascending order in c programming language]]></description>
			<content:encoded><![CDATA[<p><strong>Source code of simple merge sort implementation using array in ascending order in c programming language</strong></p>
<pre class="brush: c">
#include&lt;stdio.h&gt;
#define MAX 50

void mergeSort(int arr[],int low,int mid,int high);
void partition(int arr[],int low,int high);

int main(){

int merge[MAX],i,n;

printf(&quot;Enter the total number of elements: &quot;);
scanf(&quot;%d&quot;,&amp;n);

printf(&quot;Enter the elements which to be sort: &quot;);
for(i=0;i&lt;n;i++){
scanf(&quot;%d&quot;,&amp;merge[i]);
}

partition(merge,0,n-1);

printf(&quot;After merge sorting elements are: &quot;);
for(i=0;i&lt;n;i++){
printf(&quot;%d &quot;,merge[i]);
}

return 0;
}

void partition(int arr[],int low,int high){

int mid;

if(low&lt;high){
mid=(low+high)/2;
partition(arr,low,mid);
partition(arr,mid+1,high);
mergeSort(arr,low,mid,high);
}
}

void mergeSort(int arr[],int low,int mid,int high){

int i,m,k,l,temp[MAX];

l=low;
i=low;
m=mid+1;

while((l&lt;=mid)&amp;&amp;(m&lt;=high)){

if(arr[l]&lt;=arr[m]){
temp[i]=arr[l];
l++;
}
else{
temp[i]=arr[m];
m++;
}
i++;
}

if(l&gt;mid){
for(k=m;k&lt;=high;k++){
temp[i]=arr[k];
i++;
}
}
else{
for(k=l;k&lt;=mid;k++){
temp[i]=arr[k];
i++;
}
}

for(k=low;k&lt;=high;k++){
arr[k]=temp[k];
}
}</pre>
<p><strong>Output:</strong></p>
<p>Enter the total number of elements: 5<br />
Enter the elements which to be sort: 2 5 0 9 1<br />
After merge sorting elements are: 0 1 2 5 9</p>
]]></content:encoded>
			<wfw:commentRss>http://clinuxpro.com/mergesort-c-program/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quicksort C program</title>
		<link>http://clinuxpro.com/quicksort-c-program</link>
		<comments>http://clinuxpro.com/quicksort-c-program#comments</comments>
		<pubDate>Tue, 17 Jan 2012 17:06:13 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C programming Interview Questions]]></category>
		<category><![CDATA[Sorting]]></category>

		<guid isPermaLink="false">http://clinuxpro.com/?p=1480</guid>
		<description><![CDATA[Source code of simple quick sort implementation using  array ascending  order in c programming language]]></description>
			<content:encoded><![CDATA[<p><strong>Source code of simple quick sort implementation using  array ascending  order in c programming language</strong></p>
<pre class="brush: c">
#include&lt;stdio.h&gt;

void quicksort(int [10],int,int);

int main(){
int x[20],size,i;

printf(&quot;Enter size of the array: &quot;);
scanf(&quot;%d&quot;,&amp;amp;size);

printf(&quot;Enter %d elements: &quot;,size);
for(i=0;i&lt;size;i++)
scanf(&quot;%d&quot;,&amp;amp;x[i]);

quicksort(x,0,size-1);

printf(&quot;Sorted elements: &quot;);
for(i=0;i&lt;size;i++)
printf(&quot; %d&quot;,x[i]);

return 0;
}

void quicksort(int x[10],int first,int last){
int pivot,j,temp,i;

if(first&lt;last){
pivot=first;
i=first;
j=last;

while(i&lt;j){
while(x[i]&lt;=x[pivot]&amp;amp;&amp;amp;i&lt;last)
i++;
while(x[j]&gt;x[pivot])
j--;
if(i&lt;j){
temp=x[i];
x[i]=x[j];
x[j]=temp;
}
}

temp=x[pivot];
x[pivot]=x[j];
x[j]=temp;
quicksort(x,first,j-1);
quicksort(x,j+1,last);

}
}</pre>
<p><strong>Output:</strong></p>
<p>Enter size of the array: 5<br />
Enter 5 elements: 3 8 0 1 2<br />
Sorted elements: 0 1 2 3 8</p>
]]></content:encoded>
			<wfw:commentRss>http://clinuxpro.com/quicksort-c-program/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

