tag:blogger.com,1999:blog-82858048305352722682024-03-13T05:35:45.876-07:00C Programming TutorialIt is a blog about c programming. Here we provide c programs and tutorials to enhance your skills.Mantu Kumarhttp://www.blogger.com/profile/02897308282659594376noreply@blogger.comBlogger67125tag:blogger.com,1999:blog-8285804830535272268.post-70589008451622018792015-06-01T10:06:00.000-07:002016-11-18T11:27:57.073-08:00Prime Number Program In C<div dir="ltr" style="text-align: left;" trbidi="on">
<h2 style="text-align: left;">
Program to find whether a given number is Prime or Not</h2>
<br />
<div class="mokcode">
<pre><span style="color: blue;">#include<stdio.h></span><span style="color: blue;">
</span><span style="color: blue;">
int main()
{
/* Declaring variable for n=number, c=counter variable:holds
number of factor of 'n' */
int n,c=0, i;
// Inputting number
printf("Enter number to check whether Prime or Not:");
scanf("%d",&n);
// Checking whether number valid or not
if(n>0)
{
// Checking whether number is prime or not
for(i=1;i<=n;i++)
{
if(n%i==0)
c=c+1;
}
if(c==2)
printf("Prime Number");
else
printf("Not a Prime Number");
}
else
printf("Not a valid Number");</span></pre>
<pre><span style="color: blue;">
return 0;
}</span>
</pre>
</div>
<br />
<h2 style="text-align: left;">
Program to print ( list ) all the prime number between 1 to n</h2>
<div class="mokcode">
<pre><span style="color: blue;">#include<stdio.h></span><span style="color: blue;">
</span><span style="color: blue;">
int main()
{
/* Declaring variable for n=number, c=counter variable:holds
number of factor of 'n' */
int n,c, i,j;
// Inputting number
printf("Enter number till which you want to list prime number:");
scanf("%d",&n);
// Checking whether number valid or not
if(n>0)
{
printf("List of Prime Numbers:");
// Checking whether number is prime or not
for(i=1;i<=n;i++)
{
c=0;
for(j=1;j<=i;j++)
{
if(i%j==0)
c=c+1;
}
if(c==2)
printf("%d ",i);
}
}
else
printf("Not a valid Number");</span><span style="color: blue;">
</span><span style="color: blue;">
return 0;
}</span></pre>
</div>
</div>
Mantu Kumarhttp://www.blogger.com/profile/02897308282659594376noreply@blogger.com0tag:blogger.com,1999:blog-8285804830535272268.post-61617745818657601342015-05-25T13:35:00.000-07:002015-05-25T13:38:47.946-07:00Palindrome Program In C<div dir="ltr" style="text-align: left;" trbidi="on"><div dir="ltr" style="text-align: left;" trbidi="on"><h2 style="text-align: left;"><span style="font-weight: normal;"><span style="color: yellow;"><a href="http://www.comp-psyche.com/2015/05/palindrome-program-in-c.html#Palindrome Program" name="Palindrome Program">Palindrome Program</a></span></span></h2><br />
<li style="text-align: justify;"><a href="http://www.comp-psyche.com/2015/05/palindrome-program-in-c.html#Palindrome Number">C Program to determine Palindrome number</a></li><br />
<li style="text-align: justify;"><a href="http://www.comp-psyche.com/2015/05/palindrome-program-in-c.html#List Palindrome Number">C Program to print (list) Palindrome number from 10 to n</a></li><br />
<li><a href="http://www.comp-psyche.com/2015/05/palindrome-program-in-c.html#Recursion Palindrome Number">C Program to find whether a number is Palindrome or not using recursion</a></li><br />
<li style="text-align: justify;"><a href="http://www.comp-psyche.com/2015/05/palindrome-program-in-c.html#String Palindrome">C Program to enter a word and check whether it is palindrome or not using string function</a></li><br />
<li style="text-align: justify;"><a href="http://www.comp-psyche.com/2015/05/palindrome-program-in-c.html#String Palindrome1">C Program to enter a word and check whether it is palindrome or not without using string function</a></li><br />
</div><br />
<a href="http://www.comp-psyche.com/2015/05/palindrome-program-in-c.html#Palindrome Number" name="Palindrome Number">C PROGRAM TO DETERMINE PALINDROME NUMBER</a><br />
<br />
<a href="http://www.comp-psyche.com/2015/05/palindrome-program-in-c.html#Palindrome Program">Back To Palindrome Program</a><br />
<br />
<div class="mokcode"><pre><span style="color: blue;">#include<stdio.h>
int main()
{
// variable for a=number, n=to copy number, d=digit, rev=reverse of number
int a,n,d=0,rev=0;
// Inputting number
printf("Enter any number to determine whether it is Palindrome or not:");
scanf("%d",&a);
// copying number in n
n=a;
// Determining whether number is palindrome or not
while(n!=0)
{
d=n%10;
rev=rev*10+d;
n=n/10;
}
// Displaying Whether number is palindrome or not
if(a==rev)
printf("Palindrome number");
else
printf("Not a Palindrome Number");
return 0;
}
</span></pre></div><span style="color: blue;"></span><br />
<br />
<a href="http://www.comp-psyche.com/2015/05/palindrome-program-in-c.html#List Palindrome Number" name="List Palindrome Number">C PROGRAM TO PRINT(LIST) PALINDROME NUMBER FROM 10 TO n</a><br />
<br />
<a href="http://www.comp-psyche.com/2015/05/palindrome-program-in-c.html#Palindrome Program">Back To Palindrome Program</a><br />
<br />
<div class="mokcode"><pre><span style="color: blue;">#include<stdio.h></span></pre><pre><span style="color: blue;">int main()
{
/*declaring variable for num=user wish, i=acts as number, n=to copy number,
d=digit, rev=reverse of number */
int num,n,d=0,rev,i;
// Inputting number
printf("Enter number till which you want to list Palindrome Number:");
scanf("%d",&num);
printf("List of Palindrome Number:");
for(i=10;i<=num;i++)
{
// copying number in n
n=i;
rev=0;
// Determining whether number is palindrome or not
while(n!=0)
{
d=n%10;
rev=rev*10+d;
n=n/10</span></pre><pre><span style="color: blue;"> }
// Displaying Whether number is palindrome or not
if(i==rev)
printf("%d ",i);
}
return 0;</span></pre><pre><span style="color: blue;">}</span>
</pre></div><br />
<a href="http://www.comp-psyche.com/2015/05/palindrome-program-in-c.html#Recursion Palindrome Number" name="Recursion Palindrome Number">C PROGRAM TO FIND WHETHER A NUMBER IS PALINDROME OR NOT USING RECURSION</a><br />
<br />
<a href="http://www.comp-psyche.com/2015/05/palindrome-program-in-c.html#Palindrome Program">Back To Palindrome Program</a><br />
<br />
<div class="mokcode"><pre><span style="color: blue;">#include<stdio.h></span><span style="color: blue;">
// Declaring global variable r=reverse, d=digit
int r=0, d=0;
// Defining function with parameter n = number
int rev(int n)
{
/* Base condition : Any condition where a recursive function
or method does not invoke itself. */
if(n==0)
return r;
// Continue calling function rev or function invoke itself
else
{
// Extracting digit
d=n%10;
// Finding reverse
r=(r*10+d);
// function invoke itself
rev(n/10);
}
}
int main()
{
// Declaring variable n = number
int n;
// Declaring variable "r" to hold the reverse number
int r;
// Inputting Number
printf("Enter the Number : ");
scanf("%d",&n);
// Calling function "rev" with actual parameter "n" passed to it
r=rev(n);
// Checking and Displaying if a Number is palindrome or Not
if(r==n)
printf("%d is a Palindrome Number ",n);
else
printf("%d is not a Palindrome Number ",n);</span></pre><pre><span style="color: blue;">
return 0;
}</span>
</pre><div><span style="color: blue;"><br />
</span></div></div><br />
<a href="http://www.comp-psyche.com/2015/05/palindrome-program-in-c.html#String Palindrome" name="String Palindrome">C PROGRAM TO ENTER A WORD AND CHECK WHETHER IT IS PALINDROME OR NOT USING STRING FUNCTION</a><br />
<br />
<a href="http://www.comp-psyche.com/2015/05/palindrome-program-in-c.html#Palindrome Program">Back To Palindrome Program</a><br />
<br />
<br />
<div class="mokcode"><pre><span style="color: blue;">// palindrom - When word = reverse of word then it is called palindrome
// Example : madam - palindrome, Madam - not palindrome, MadaM - palindrome
#include<stdio.h>
#include<string.h>
int main()
{
// Declaring variable str=string
char word[50], word1[50];
// Inputing string
printf("Enter any word : ");
scanf("%s",&word);
// Copying word to word1
strcpy(word1,word);
// checking if palindrome or not
if(strcmp(word,strrev(word1))==0)
{
printf("Entered word is a palindrome ");
}
else
printf("Entered word is not palindrome ");
return 0;
}</span>
</pre></div><br />
<a href="http://www.comp-psyche.com/2015/05/palindrome-program-in-c.html#String Palindrome1" name="String Palindrome1">PALINDROME PROGRAM IN C WITHOUT USING STRING FUNCTION</a><br />
<br />
<a href="http://www.comp-psyche.com/2015/05/palindrome-program-in-c.html#Palindrome Program">Back To Palindrome Program</a><br />
<br />
<div class="mokcode"><pre><span style="color: blue;">#include<stdio.h>
int main()
{
// Declaring variable str=string
char word[50], revword[50];
/* Declaring variable i=to iterate loop, l=length,
c=count the number of matched character */
int i, j, l=0, c;
// Inputing string
printf("Enter any word : ");
scanf("%s",&word);
// finding length
while(word[l]!='\0')
l++;
// Reversing string
j=0;
for(i=l-1;i>=0;i--)
{
revword[j]=word[i];
j++;
}
revword[j]='\0';
//checking if palindrome or not
c=0;
for(i=0;word[i]!='\0';i++)
{
if(revword[i]==word[i])
c++;
}
if(c==l)
{
printf("Word is a palindrome ");
}
else
printf("Word is not palindrome ");
return 0;
}</span>
</pre></div></div>Mantu Kumarhttp://www.blogger.com/profile/02897308282659594376noreply@blogger.com0tag:blogger.com,1999:blog-8285804830535272268.post-1375931275503707532015-05-24T05:37:00.000-07:002015-05-24T06:48:30.259-07:00Leap Year Program In C<div dir="ltr" style="text-align: left;" trbidi="on">
<h3 style="text-align: left;">
<span style="font-weight: normal;">Leap Year Program In C using if-else</span></h3>
<div class="mokcode">
<span style="color: blue;">// Leap year program in c using if-else</span><br />
<pre><span style="color: blue;">#include<stdio.h></span><span style="color: blue;">
</span><span style="color: blue;">
int main()
{
// Declaring variable for y=year
int y;
// Inputing year
printf("Enter year to check leap year or not: ");
scanf("%d",&y);
// Determining and displaying whether leap year or not
if(y%4==0)
{
if(y%100==0 && y%400!=0)
printf("Century year, But not a leap year");
else
printf("Leap year");
}
else
printf("Not a Leap Year");</span><span style="color: blue;">
</span><span style="color: blue;">
return 0;
}</span>
</pre>
</div>
<br />
<h3 style="text-align: left;">
<span style="font-weight: normal;">Leap Year Program In C Using Ternary</span></h3>
<div class="mokcode">
<span style="color: blue;">// Leap year program in c using ternary</span><br />
<pre><span style="color: blue;">#include<stdio.h></span><stdio .h=""><conio .h=""><span style="color: blue;">
int main()
{
// Declaring variable "y" to input year and "leap" to determine leap year
int y,leap;
// Inputting year
printf("Enter any year : ");
scanf("%d",&y);
// Checking if leaf year or not
leap=(y%400==0)?:(y%100!=0)?(y%4==0)?1:0:0;
if(leap==1)
printf("The given year is leap year");
else
printf("The given year is not leap year");
</span><span style="color: blue;">
return 0;
}</span>
</conio></stdio></pre>
</div>
</div>
Mantu Kumarhttp://www.blogger.com/profile/02897308282659594376noreply@blogger.com0tag:blogger.com,1999:blog-8285804830535272268.post-4143293091703445422015-04-23T03:25:00.001-07:002020-11-17T05:22:42.667-08:00Insertion Sort Algorithm, Time Complexity And Program In C<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="text-align: left;">
<h2 style="text-align: left;">
<span style="font-weight: normal;"><span style="color: yellow;"><a href="http://back%20to%20insertion%20sort/#insertion sort" name="insertion sort">INSERTION SORT</a></span></span></h2>
</div>
<div style="text-align: left;">
</div>
<ul style="text-align: left;">
<li><a href="http://www.comp-psyche.com/2014/12/insertion-sort-algorithm-time-complexity-and-program-in-c.html#insertion sort in c">Insertion Sort In C</a></li>
<li><a href="http://www.comp-psyche.com/2014/12/insertion-sort-algorithm-time-complexity-and-program-in-c.html#insertion sort algorithm">Algorithm for Insertion Sort</a></li>
<li><a href="http://www.comp-psyche.com/2014/12/insertion-sort-algorithm-time-complexity-and-program-in-c.html#Time Complexity">Time Complexity Of Insertion Sort</a></li>
<li><a href="http://www.comp-psyche.com/2014/12/insertion-sort-algorithm-time-complexity-and-program-in-c.html#insertion sort program in c">Insertion Sort Program In C</a></li>
</ul>
<h2>
<span style="font-weight: normal;"><span style="color: yellow;"><br />
</span></span></h2>
<h2>
<span style="font-weight: normal;"><span style="color: yellow;"><a href="http://www.comp-psyche.com/2014/12/insertion-sort-algorithm-time-complexity-and-program-in-c.html#insertion sort in c" name="insertion sort in c">INSERTION SORT IN C</a></span></span></h2>
<div>
<span style="font-weight: normal;"><a href="http://www.comp-psyche.com/2014/12/insertion-sort-algorithm-time-complexity-and-program-in-c.html#insertion sort">Back to Insertion Sort</a></span></div>
<div>
<span style="font-weight: normal;"><br />
</span></div>
<div>
<div style="text-align: justify;">
In <span style="color: lime;">Insertion Sort</span> we select a <span style="color: lime;">key</span> i.e an element one by one from any given list of element ( <span style="color: lime;">array</span> ) and then we insert it in its appropriate position. We can either scan the list from<span style="color: lime;"> left to right</span> or <span style="color: lime;">right to left </span>to find an appropriate position. But usually we scan list from <span style="color: lime;">right to left</span> because it is better in case of sorted and almost sorted arrays. Insertion sort is an efficient algorithm for sorting small number of elements. Though Insertion Sort is based on <span style="color: lime;">recursive idea, </span>it is more efficient to implement this algorithm by bottom up approach i.e<span style="color: lime;"> iteratively</span>. </div>
<div style="text-align: justify;">
<br /></div><div style="text-align: justify;">Need Programming Help visit: <a href="https://letstacle.com">Get Programming Help Online</a></div><div style="text-align: justify;"><br /></div>
<div style="text-align: justify;">
Consider the elements to be sorted by insertion sort are : <span style="color: lime; text-align: left;">89, 45, 68, 90, 29, 34, 17</span></div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
As shown in Figure below, starting with <span style="color: lime;">A[1]</span> and ending with <span style="color: lime;">A[n - 1]</span>, <span style="color: lime;">A[i]</span> is inserted in its appropriate place among the <span style="color: lime;">first i elements</span> of the array that have been already sorted (but, unlike selection sort, the elements are generally not in their final positions). </div>
</div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="http://4.bp.blogspot.com/-vyMUb4D2iYM/U89U7bpPZEI/AAAAAAAAALM/XDGoHzKCsvk/s1600/insertion+sort.png" style="margin-left: auto; margin-right: auto;"><img alt="Insertion Sort In C : Showing insertion of elements" border="0" height="192" src="http://4.bp.blogspot.com/-vyMUb4D2iYM/U89U7bpPZEI/AAAAAAAAALM/XDGoHzKCsvk/s1600/insertion+sort.png" title="Insertion Sort Program In C" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="color: lime;">Insertion Sort In C : Showing how elements are sorted</span></td></tr>
</tbody></table>
The above figure shows how elements <span style="color: lime;">89, 45, 68, 90, 29, 34, 17</span> are sorted by insertion sort. A vertical bar separates the sorted part of the array from the remaining elements; the element being inserted is in bold.<br />
<br />
<span style="color: lime;">Note : Refer to algorithm for better understanding.</span><br />
<span style="color: lime;"><br />
</span> <br />
<h2>
<span style="font-weight: normal;"><span style="color: yellow;"><a href="http://www.comp-psyche.com/2014/12/insertion-sort-algorithm-time-complexity-and-program-in-c.html#insertion sort algorithm" name="insertion sort algorithm">INSERTION SORT ALGORITHM</a></span></span></h2>
<div>
<a href="http://www.comp-psyche.com/2014/12/insertion-sort-algorithm-time-complexity-and-program-in-c.html#insertion sort">Back to Insertion Sort</a></div>
<div>
<span style="font-weight: normal;"><br />
</span></div>
<div>
</div>
<div class="mokcode">
<pre><span style="color: blue;">InsertionSort(int a[ ], int n)</span>
<span style="color: blue;"> for i=1 to n-1
key = a[i]
j = i-1</span></pre>
<pre><span style="color: blue;">
while j>=0 and key < a[j]
a[j+1]=a[j];
j=j-1;
a[j+1] = key</span>
</pre>
</div>
<br />
<span style="color: lime;">Note : The operation of the algorithm can be understood with the help of above figure.</span><br />
<br />
<h2 style="text-align: left;">
<span style="font-weight: normal;"><a href="http://www.comp-psyche.com/2014/12/insertion-sort-algorithm-time-complexity-and-program-in-c.html#Time Complexity" name="Time Complexity">TIME COMPLEXITY OF INSERTION SORT</a></span></h2>
<div>
<a href="http://www.comp-psyche.com/2014/12/insertion-sort-algorithm-time-complexity-and-program-in-c.html#insertion sort">Back to Insertion Sort</a></div>
<div>
<br /></div>
<h3 style="text-align: left;">
<span style="color: yellow;">Time Complexity Of Insertion Sort - Best Case</span></h3>
<div>
<br />
<ul style="text-align: left;">
<li style="text-align: justify;">The best case input in an array is such that the array is already sorted. </li>
<li style="text-align: justify;">In this case insertion sort has linear running time i.e O(n)</li>
</ul>
</div>
<h3 style="text-align: left;">
<span style="color: yellow;"><br />
</span></h3>
<h3 style="text-align: left;">
<span style="color: yellow;">Time Complexity Of Insertion Sort -</span><span style="color: yellow;"> </span><span style="color: yellow;">Worst Case</span></h3>
<div>
<br />
<ul style="text-align: left;">
<li style="text-align: justify;">The worst case input in an array is such that the array is sorted in reverse order.</li>
<li style="text-align: justify;">In this case insertion sort has quadratic running time i.e O(n<sup>2</sup>) </li>
</ul>
</div>
<h3 style="text-align: left;">
<span style="color: yellow;"><br />
</span></h3>
<h3 style="text-align: left;">
<span style="color: yellow;">Time Complexity Of Insertion Sort -</span><span style="color: yellow;"> </span><span style="color: yellow;">Average Case</span></h3>
<div>
<ul style="text-align: left;">
<li style="text-align: justify;">Input in this case is a random input.</li>
<li style="text-align: justify;">In this case also insertion sort has quadratic running time i.e O(n<sup>2</sup>)</li>
<li style="text-align: justify;">Insertion Sort is very efficient in sorting very small arrays.</li>
<li style="text-align: justify;">Its impractical to sort very large arrays using insertion sort due to its time complexity of O(n<sup>2</sup>)</li>
</ul>
</div>
<h2 style="text-align: left;">
<span style="font-weight: normal;"><span style="color: yellow;"><a href="http://www.comp-psyche.com/2014/12/insertion-sort-algorithm-time-complexity-and-program-in-c.html#insertion sort program in c" name="insertion sort program in c">INSERTION SORT PROGRAM IN C</a></span></span></h2>
<div>
<a href="http://www.comp-psyche.com/2014/12/insertion-sort-algorithm-time-complexity-and-program-in-c.html#insertion sort">Back to Insertion Sort</a></div>
<div>
<span style="font-weight: normal;"><br />
</span></div>
<div class="mokcode">
<pre><span style="color: blue;">// Insertion sort program in c
#include<stdio.h>
void InsertionSort(int a[],int n) ;
int main()
{
int a[20],i,n;
printf("Enter number of elements in array : ");
scanf("%d",&n);
// Inputting elements
for(i=0;i<n;i++)
{
printf("Enter number %d: ",i+1);
scanf("%d",&a[i]);
}
// Displaying Elements before insertion sort
printf("Items in the array are : ");
for(i=0;i<n;i++)
{
printf("%d ",a[i]);
}
//Applying insertion sort
InsertionSort(a,n);
// Displaying elements after insertion sort
printf("\nElements after insertion sort : ");
for(i=0;i<n;i++)
{
printf("%d ",a[i]);
}
return 0;
}
void InsertionSort(int a[],int n)
{
int i,key,j;
for(i=1;i<n;i++)
{
key=a[i];
j=i-1; </span></pre>
<pre><span style="color: blue;">
</span></pre>
<pre><span style="color: blue;"> // Finding appropriate position to insert key
while((key<a[j])&&(j>=0))
{
a[j+1]=a[j];
j=j-1;
}
</span></pre>
<pre><span style="color: blue;"> // Inserting key
a[j+1]=key;
}
}</span>
</pre>
</div>
<span style="color: yellow;">More Informative Posts :</span><br />
<ul>
<li><span style="color: yellow;"><a href="http://www.comp-psyche.com/2014/12/insertion-sort-algorithm-time-complexity-and-program-in-c.html">Insertion Sort Program In C</a></span></li>
<li><span style="color: yellow;"><a href="http://www.comp-psyche.com/2014/06/merge-sort-program-in-c.html">Merge Sort Program In C</a></span></li>
<li><span style="color: yellow;"><a href="http://www.comp-psyche.com/2014/06/quick-sort-program-in-c.html">Quick Sort Program In C</a></span></li>
<li><a href="http://www.comp-psyche.com/2014/07/counting-sort-program-in-c.html">Counting Sort Program In C</a></li>
<li><a href="http://www.comp-psyche.com/2014/07/bubble-sort-program-in-c.html">Bubble Sort Program In C</a></li>
<li><a href="http://www.comp-psyche.com/2015/01/heap-sort-program-in-c.html">Heap Sort Program In C</a></li>
<li>Bucket Sort Program In C</li>
<li>Shell Sort Program In C</li>
<li>Radix Sort Program In C</li>
</ul>
</div>
Mantu Kumarhttp://www.blogger.com/profile/02897308282659594376noreply@blogger.com0tag:blogger.com,1999:blog-8285804830535272268.post-70000533321952172572015-03-01T05:53:00.000-08:002015-03-01T05:53:08.279-08:00String Programs In C<div dir="ltr" style="text-align: left;" trbidi="on">
<ol>
<li style="text-align: justify;"><a href="http://www.comp-psyche.com/2014/01/c-programs-strings.html#p1">Program to accept a string and print it</a></li>
<li style="text-align: justify;"><a href="http://www.comp-psyche.com/2014/01/c-programs-strings.html#p2">Program to accept a character in the uppercase and print in lower case</a></li>
<li style="text-align: justify;"><a href="http://www.comp-psyche.com/2014/01/c-programs-strings.html#p3">Program to accept a character in Lower case and print it in upper case</a></li>
<li style="text-align: justify;"><a href="http://www.comp-psyche.com/2014/01/c-programs-strings.html#p4">Program to accept a character in any case and print in another case</a></li>
<li style="text-align: justify;"><a href="http://www.comp-psyche.com/2014/01/c-programs-strings.html#p5">Program to accept a string and print it by using while loop</a></li>
<li style="text-align: justify;"><a href="http://www.comp-psyche.com/2014/01/c-programs-strings1.html#p6">Program to find length of a string using string function</a></li>
<li style="text-align: justify;"><a href="http://www.comp-psyche.com/2014/01/c-programs-strings1.html#p7">Program to find length of a string without using string function</a></li>
<li style="text-align: justify;"><a href="http://www.comp-psyche.com/2014/01/c-programs-strings1.html#p8">Program for Copy a String to another using String Function</a></li>
<li style="text-align: justify;"><a href="http://www.comp-psyche.com/2014/01/c-programs-strings1.html#p9">Program to find length of a string without using string function</a></li>
<li style="text-align: justify;"><a href="http://www.comp-psyche.com/2014/01/c-programs-strigns2.html#p10">Program for Compare two String using String Function</a></li>
<li style="text-align: justify;"><a href="http://www.comp-psyche.com/2014/01/c-programs-strigns2.html#p11">Program for Compare two String without using String Function</a></li>
<li style="text-align: justify;"><a href="http://www.comp-psyche.com/2014/01/c-programs-strigns2.html#p12">Program for String Reverse with String Function</a></li>
<li style="text-align: justify;"><a href="http://www.comp-psyche.com/2014/01/c-programs-strigns2.html#p13">Program for String Reverse without String Function</a></li>
<li style="text-align: justify;"><a href="http://www.comp-psyche.com/2014/01/c-programs-strigns2.html#p14">Program for String Concatenation with String Function</a></li>
<li style="text-align: justify;"><a href="http://www.comp-psyche.com/2014/01/c-programs-strigns2.html#p15">Program for String Concatenation without String Function</a></li>
<li style="text-align: justify;"><a href="http://www.comp-psyche.com/2014/01/c-programs-strings3.html#p16">Program to convert all characters in a string to lower case using string function</a></li>
<li style="text-align: justify;"><a href="http://www.comp-psyche.com/2014/01/c-programs-strings3.html#p17">Program to convert all characters in a string to lower case without using string function</a></li>
<li style="text-align: justify;"><a href="http://www.comp-psyche.com/2014/01/c-programs-strings3.html#p18">Program to convert all characters in a string to upper case using string function</a></li>
<li style="text-align: justify;"><a href="http://www.comp-psyche.com/2014/01/c-programs-strings3.html#p19">Program to convert all characters in a string to upper case without using string function</a></li>
<li style="text-align: justify;"><a href="http://www.comp-psyche.com/2014/01/c-programs-strings3.html#p20">Program to enter 5 string and print them with their length</a></li>
<li style="text-align: justify;"><a href="http://www.comp-psyche.com/2014/01/c-programs-strings4.html#p21">Program to accept a string and print each word of the string separately also print total number of words</a></li>
<li style="text-align: justify;"><a href="http://www.comp-psyche.com/2014/01/c-programs-strings4.html#p22">Program to accept a string and display vowels frequency( total number of vowels)</a></li>
<li style="text-align: justify;"><a href="http://www.comp-psyche.com/2014/01/c-programs-strings4.html#p23">Program to accept a string and display frequency of each vowel along with vowel</a></li>
<li style="text-align: justify;"><a href="http://www.comp-psyche.com/2014/01/c-programs-strings4.html#p24">Program to enter a word and check whether it is palindrome or not using string function</a></li>
<li style="text-align: justify;"><a href="http://www.comp-psyche.com/2014/01/c-programs-strings4.html#p25">Program to enter a word and check whether it is palindrome or not without using string function</a></li>
</ol>
</div>
Mantu Kumarhttp://www.blogger.com/profile/02897308282659594376noreply@blogger.com0tag:blogger.com,1999:blog-8285804830535272268.post-22415914741419719352015-02-23T04:51:00.000-08:002015-02-23T04:51:08.857-08:00Array Programs In C<div dir="ltr" style="text-align: left;" trbidi="on">
<ol>
<li style="text-align: justify;"><a href="http://www.comp-psyche.com/2014/01/c-programs-arrays.html#p1">C Program to accept elements in an array and display it</a></li>
<li style="text-align: justify;"><a href="http://www.comp-psyche.com/2014/01/c-programs-arrays.html#p2">C Program to accept elements in an array and display sum of all the elements</a></li>
<li style="text-align: justify;"><a href="http://www.comp-psyche.com/2014/01/c-programs-arrays.html#p3">C Program to insert element in between an array. ( INSERTION )</a></li>
<li style="text-align: justify;"><a href="http://www.comp-psyche.com/2014/01/c-programs-arrays.html#p4">C Program to delete element from an array. ( DELETION )</a></li>
<li style="text-align: justify;"><a href="http://www.comp-psyche.com/2014/01/c-programs-arrays.html#p5">C Program to perform Transpose of a Matrix</a></li>
<li style="text-align: justify;"><a href="http://www.comp-psyche.com/2014/01/c-programs-arrays1.html#p6">C Program to find Minimum element in an array</a></li>
<li style="text-align: justify;"><a href="http://www.comp-psyche.com/2014/01/c-programs-arrays1.html#p7">C Program to find highest minimum temperature and lowest maximum temperature</a></li>
<li style="text-align: justify;"><a href="http://www.comp-psyche.com/2014/01/c-programs-arrays1.html#p8">C Program to accept 10 numbers and print first five numbers in original order and print last five numbers in reverse order</a></li>
<li style="text-align: justify;"><a href="http://www.comp-psyche.com/2014/01/c-programs-arrays1.html#p9">C Program showing Passing array to function. Program finds the average of 5 marks input by user</a></li>
<li style="text-align: justify;"><a href="http://www.comp-psyche.com/2014/01/c-programs-arrays1.html#p10">C Program to initialize a character array and display the initialized character array in reverse order</a></li>
<li style="text-align: justify;"><a href="http://www.comp-psyche.com/2014/01/c-programs-arrays2.html#p11">C Program to generate histogram of entered number</a></li>
<li style="text-align: justify;"><a href="http://www.comp-psyche.com/2014/01/c-programs-arrays2.html#p12">C Program to enter values into a two-dimensional integer array of size (4 X 3) and then display it in matrix form</a></li>
<li style="text-align: justify;"><a href="http://www.comp-psyche.com/2014/01/c-programs-arrays2.html#p13">Write a c program to enter values into a two-dimensional integer array of size (4 X 3) and then display the elements of the second row</a></li>
<li style="text-align: justify;"><a href="http://www.comp-psyche.com/2014/01/c-programs-arrays2.html#p14">C Program to find the sum of elements that are greater than 5 within a two-dimensional array through a function receiving the array as arguments</a></li>
<li style="text-align: justify;"><a href="http://www.comp-psyche.com/2014/01/c-programs-arrays2.html#p15">C Program To Accept 5 Student - Roll No, Marks in 3 Subjects of each student and Calculate Total, Average and Print it along with student roll Number</a></li>
<li style="text-align: justify;"><a href="http://www.comp-psyche.com/2014/01/c-programs-arrays3.html#p16">C Programs to multiply two Matrices</a></li>
<li style="text-align: justify;"><a href="http://www.comp-psyche.com/2014/01/c-programs-arrays3.html#p17">C Program to print a diagonal matrix with diagonal value enter by user</a></li>
<li style="text-align: justify;"><a href="http://www.comp-psyche.com/2014/01/c-programs-arrays3.html#p18">C Program to print a anti diagonal matrix with diagonal value enter by user</a></li>
<li style="text-align: justify;"><a href="http://www.comp-psyche.com/2014/01/c-programs-arrays3.html#p19">C Program to print the sum of diagonal values and anti-diagonal values of a matrix</a></li>
</ol>
</div>
Mantu Kumarhttp://www.blogger.com/profile/02897308282659594376noreply@blogger.com0tag:blogger.com,1999:blog-8285804830535272268.post-51886103161318360722015-02-22T04:23:00.002-08:002015-03-01T04:27:30.238-08:00Pointer Programs In C<div dir="ltr" style="text-align: left;" trbidi="on">
<ol>
<li style="text-align: justify;"><a href="http://www.comp-psyche.com/2014/01/c-programs-pointers.html#p1">Program to accept two numbers and print its address along with the numbers</a></li>
<li style="text-align: justify;"><a href="http://www.comp-psyche.com/2014/01/c-programs-pointers.html#p2">Program to accept two numbers and print the sum of given two numbers by using pointers</a></li>
<li style="text-align: justify;"><a href="http://www.comp-psyche.com/2014/01/c-programs-pointers.html#p3">Program to interchange two values using pointers</a></li>
<li style="text-align: justify;"><a href="http://www.comp-psyche.com/2014/01/c-programs-pointers.html#p4">Implement a function interchange() to interchange two values using pointers </a></li>
<li style="text-align: justify;"><a href="http://www.comp-psyche.com/2014/01/c-programs-pointers.html#p5">Program to sum all the elements of an array using pointer</a></li>
<li style="text-align: justify;"><a href="http://www.comp-psyche.com/2014/01/c-programs-pointers1.html#p6">Program to find maximum element of an array of elements using pointer</a></li>
<li style="text-align: justify;"><a href="http://www.comp-psyche.com/2014/01/c-programs-pointers1.html#p7">Program to print sum of all the elements in 2D array using pointer</a></li>
<li style="text-align: justify;"><a href="http://www.comp-psyche.com/2014/01/c-programs-pointers1.html#p8">Program to sort an array of elements using pointers</a></li>
<li style="text-align: justify;"><a href="http://www.comp-psyche.com/2014/01/c-programs-pointers1.html#p9">Program to sort string using pointers</a></li>
<li style="text-align: justify;"><a href="http://www.comp-psyche.com/2014/01/c-programs-pointers1.html#p10">Program to search given element in an array using pointers</a></li>
<li style="text-align: justify;"><a href="http://www.comp-psyche.com/2014/01/c-programs-pointers1.html#p11">Program to demonstrate the use of pointer to pointer</a></li>
</ol>
</div>
Mantu Kumarhttp://www.blogger.com/profile/02897308282659594376noreply@blogger.com1tag:blogger.com,1999:blog-8285804830535272268.post-77165668999447361972015-02-22T04:20:00.004-08:002015-03-01T04:27:30.247-08:00Recursion Program In C<div dir="ltr" style="text-align: left;" trbidi="on">
<ol>
<li><a href="http://www.comp-psyche.com/2014/01/c-programs-recursion.html#p1">Program to find the factorial of a Number using recursion</a></li>
<li><a href="http://www.comp-psyche.com/2014/01/c-programs-recursion.html#p2">Program to print sum of n natural numbers from 1 to n ( Number ) using recursion </a></li>
<li><a href="http://www.comp-psyche.com/2014/01/c-programs-recursion.html#p3">Program to calculate the power using recursion. Example a^b ( Here ^ = Power sign )</a></li>
<li><a href="http://www.comp-psyche.com/2014/01/c-programs-recursion.html#p4">Program to find the GCD ( Greatest Common Divisior ) or HCD ( Highes Common Factor ) using recursion</a></li>
<li><a href="http://www.comp-psyche.com/2014/01/c-programs-recursion.html#p5">Program to Reverse a Number using recursion</a></li>
<li><a href="http://www.comp-psyche.com/2014/01/c-programs-recursion1.html#p6">Program to find whether a number is Palindrome or not using recursion</a></li>
<li><a href="http://www.comp-psyche.com/2014/01/c-programs-recursion1.html#p7">Program to find whether a number is Armstrong or not using recursion</a></li>
<li><a href="http://www.comp-psyche.com/2014/01/c-programs-recursion1.html#p8">Program to print the fibonacci series upto nth terms using recursion</a></li>
<li><a href="http://www.comp-psyche.com/2014/01/c-programs-recursion1.html#p9">Program to print first "n" natural numbers in reverse order</a></li>
<li><a href="http://www.comp-psyche.com/2014/01/c-programs-recursion1.html#p10">Program to print patter :</a><br /><div class="mokcode">
<span style="color: blue;">*</span><br />
<span style="color: blue;">* *</span><br />
<span style="color: blue;">* * *</span><br />
<span style="color: blue;">* * * *</span><br />
<span style="color: blue;">* * * * *</span></div>
</li>
<li><a href="http://www.comp-psyche.com/2014/01/c-programs-recursion1.html#p11">Program to print given pattern : </a><br /><div class="mokcode">
<span style="color: blue;">*</span><br />
<span style="color: blue;">* *</span><br />
<span style="color: blue;">* * *</span><br />
<span style="color: blue;">* * * *</span><br />
<span style="color: blue;">* * * * * till n terms</span></div>
</li>
</ol>
</div>
Mantu Kumarhttp://www.blogger.com/profile/02897308282659594376noreply@blogger.com0tag:blogger.com,1999:blog-8285804830535272268.post-79320508552027801922015-02-22T01:21:00.000-08:002015-02-22T01:21:02.504-08:00Pattern Programs In C<div dir="ltr" style="text-align: left;" trbidi="on">
<ol>
<li><a href="http://www.comp-psyche.com/2014/02/c-programs-patterns.html#p1">Program to print the given pattern :</a><br /><div class="mokcode">
<span style="color: blue;">*</span><br />
<span style="color: blue;">* *</span><br />
<span style="color: blue;">* * *</span><br />
<span style="color: blue;">* * * *</span><br />
<span style="color: blue;">* * * * * </span></div>
</li>
<li><a href="http://www.comp-psyche.com/2014/02/c-programs-patterns.html#p2">Program to print the given pattern :</a><br /><div class="mokcode">
<span style="color: blue;">*</span><br />
<span style="color: blue;">* *</span><br />
<span style="color: blue;">* * *</span><br />
<span style="color: blue;">* * * *</span><br />
<span style="color: blue;">* * * * *</span><br />
<span style="color: blue;">* * * * * * ..... till n rows</span></div>
</li>
<li><a href="http://www.comp-psyche.com/2014/02/c-programs-patterns.html#p3">Program to print the given pattern :</a><br /><div class="mokcode">
<span style="color: blue;">1</span><br />
<span style="color: blue;">1 2</span><br />
<span style="color: blue;">1 2 3</span><br />
<span style="color: blue;">1 2 3 4</span><br />
<span style="color: blue;">1 2 3 4 5 .... till n rows</span></div>
</li>
<li><a href="http://www.comp-psyche.com/2014/02/c-programs-patterns.html#p4">Program to print the given pattern :</a><br /><div class="mokcode">
<span style="color: blue;">1</span><br />
<span style="color: blue;">2 2</span><br />
<span style="color: blue;">3 3 3</span><br />
<span style="color: blue;">4 4 4 4</span><br />
<span style="color: blue;">5 5 5 5 5 .... till n rows</span></div>
</li>
<li><a href="http://www.comp-psyche.com/2014/02/c-programs-patterns.html#p5">Program to print the given pattern :</a><br /><div class="mokcode">
<span style="color: blue;">1 1 1 1 1</span><br />
<span style="color: blue;">2 2 2 2 2</span><br />
<span style="color: blue;">3 3 3 3 3</span><br />
<span style="color: blue;">4 4 4 4 4</span><br />
<span style="color: blue;">5 5 5 5 5</span></div>
</li>
<li><a href="http://www.comp-psyche.com/2014/02/c-programs-patterns1.html#p6">Program to print the given pattern :</a><br /><div class="mokcode">
<span style="color: blue;">5</span><br />
<span style="color: blue;">5 4</span><br />
<span style="color: blue;">5 4 3</span><br />
<span style="color: blue;">5 4 3 2</span><br />
<span style="color: blue;">5 4 3 2 1</span></div>
</li>
<li><a href="http://www.comp-psyche.com/2014/02/c-programs-patterns1.html#p7">Program to print the given pattern :</a><br /><div class="mokcode">
<span style="color: blue;">1 2 3 4 5</span><br />
<span style="color: blue;">1 2 3 4</span><br />
<span style="color: blue;">1 2 3</span><br />
<span style="color: blue;">1 2</span><br />
<span style="color: blue;">1</span></div>
</li>
<li><a href="http://www.comp-psyche.com/2014/02/c-programs-patterns1.html#p8">Program to print the given pattern :</a><br /><div class="mokcode">
<span style="color: blue;">5 4 3 2 1</span><br />
<span style="color: blue;">5 4 3 2</span><br />
<span style="color: blue;">5 4 3</span><br />
<span style="color: blue;">5 4</span><br />
<span style="color: blue;">5</span></div>
</li>
<li><a href="http://www.comp-psyche.com/2014/02/c-programs-patterns1.html#p9">Program to print the given pattern :</a><br /><div class="mokcode">
<pre><span style="color: blue;"> *
* *
* * *
* * * *
* * * * *</span>
</pre>
</div>
</li>
<li><a href="http://www.comp-psyche.com/2014/02/c-programs-patterns1.html#p10">Program to print the given pattern :</a><br /><div class="mokcode">
<pre><span style="color: blue;"> 1
1 2
1 2 3
1 2 3 4
1 2 3 4 5</span></pre>
</div>
</li>
<li><a href="http://www.comp-psyche.com/2014/02/c-programs-pointers2.html#p11">Program to print the given pattern :</a><div class="mokcode">
<pre><span style="color: blue;"> 5
4 5
3 4 5
2 3 4 5
1 2 3 4 5
</span></pre>
</div>
</li>
<li><a href="http://www.comp-psyche.com/2014/02/c-programs-pointers2.html#p12">Program to print the given pattern :</a><br /><div class="mokcode">
<span style="color: blue;">1</span><br />
<span style="color: blue;">* *</span><br />
<span style="color: blue;">1 2 3</span><br />
<span style="color: blue;">* * * *</span><br />
<span style="color: blue;">1 2 3 4 5 .... till n rows</span></div>
</li>
<li><a href="http://www.comp-psyche.com/2014/02/c-programs-pointers2.html#p13">Program to print the given pattern :</a><br /><div class="mokcode">
<pre><span style="color: blue;">1 1
1 2 1 2
1 2 3 1 2 3
1 2 3 4 1 2 3 4
1 2 3 4 5 1 2 3 4 5</span>
</pre>
</div>
</li>
<li><a href="http://www.comp-psyche.com/2014/02/c-programs-pointers2.html#p14">Program to print the given pattern :</a><br /><div class="mokcode">
<pre><span style="color: blue;">1 1</span>
<span style="color: blue;">1 2 2 1</span>
<span style="color: blue;">1 2 3 3 2 1</span>
<span style="color: blue;">1 2 3 4 4 3 2 1</span>
<span style="color: blue;">1 2 3 4 5 5 4 3 2 1</span>
</pre>
</div>
</li>
<li><a href="http://www.comp-psyche.com/2014/02/c-programs-pointers2.html#p15">Program to print the given pattern :</a><br /><div class="mokcode">
<pre><span style="color: blue;">1 5</span>
<span style="color: blue;">1 2 5 4</span>
<span style="color: blue;">1 2 3 5 4 3</span>
<span style="color: blue;">1 2 3 4 5 4 3 2</span>
<span style="color: blue;">1 2 3 4 5 5 4 3 2 1</span>
</pre>
</div>
</li>
<li><a href="http://www.comp-psyche.com/2014/02/c-programs-patterns3.html#16">Program to print the given pattern :</a><br /><div class="mokcode">
<span style="color: blue;">1</span><br />
<span style="color: blue;">2 6</span><br />
<span style="color: blue;">3 7 10</span><br />
<span style="color: blue;">4 8 11 13</span><br />
<span style="color: blue;">5 9 12 14 15 ... till n rows</span></div>
</li>
<li><a href="http://www.comp-psyche.com/2014/02/c-programs-patterns3.html#17">Program to print the given pattern :</a><br /><div class="mokcode">
<pre><span style="color: blue;">******** ********</span>
<span style="color: blue;">******* *******</span>
<span style="color: blue;">****** ****** </span>
<span style="color: blue;">***** *****</span>
<span style="color: blue;">**** ****</span>
<span style="color: blue;">*** ***</span>
<span style="color: blue;">** **</span>
<span style="color: blue;">* *</span>
<span style="color: blue;"></span>
<span style="color: blue;">* *</span>
<span style="color: blue;">** **</span>
<span style="color: blue;">*** ***</span>
<span style="color: blue;">**** ****</span>
<span style="color: blue;">***** ***** </span>
<span style="color: blue;">****** ******</span>
<span style="color: blue;">******* *******</span>
<span style="color: blue;">******** ********</span>
</pre>
</div>
</li>
<li><a href="http://www.comp-psyche.com/2014/02/c-programs-patterns3.html#18">Program to print the given pattern</a><br /><div class="mokcode">
<pre><span style="color: blue;">
*
***
*****
*******
*********
*******
*****
***
* </span>
</pre>
</div>
</li>
<li><a href="http://www.comp-psyche.com/2014/02/c-programs-patterns3.html#19">Program to print the given pattern :</a><br /><div class="mokcode">
<span style="color: blue;">8 4 2 1</span><br />
<span style="color: blue;">4 2 1</span><br />
<span style="color: blue;">2 1</span><br />
<span style="color: blue;">1</span></div>
</li>
<li><a href="http://www.comp-psyche.com/2014/02/c-programs-patterns3.html#20">Program to print Pascal triangle :</a></li>
</ol>
</div>
Mantu Kumarhttp://www.blogger.com/profile/02897308282659594376noreply@blogger.com0tag:blogger.com,1999:blog-8285804830535272268.post-795278278492844152015-01-01T13:23:00.002-08:002020-11-17T05:08:22.252-08:00Heap Sort Program In C<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<h2 style="text-align: left;">
<span style="font-weight: normal;"><a href="http://www.comp-psyche.com/2015/01/heap-sort-program-in-c.html#Heap Sort" name="Heap Sort">HEAP SORT</a></span></h2>
<ul style="text-align: left;">
<li><a href="http://www.comp-psyche.com/2015/01/heap-sort-program-in-c.html#Heap Sort In C">Heap Sort In C</a></li>
<li><a href="http://www.comp-psyche.com/2015/01/heap-sort-program-in-c.html#Pseudocode To Add Node">Pseudocode to Add Node In Heap</a></li>
<li><a href="http://www.comp-psyche.com/2015/01/heap-sort-program-in-c.html#Pseudocode To Remove Root">Pseudocode to Remove Root From Heap</a></li>
<li><a href="http://www.comp-psyche.com/2015/01/heap-sort-program-in-c.html#Heap Sort Performed">How Heap Sort Is Performed</a></li>
<li><a href="http://www.comp-psyche.com/2015/01/heap-sort-program-in-c.html#Heap Sort Program In C">Heap Sort Program In C</a></li>
<li><a href="http://www.comp-psyche.com/2015/01/heap-sort-program-in-c.html#Heap Sort Program With Output">Heap Sort Program Output</a></li>
</ul>
<div>
<h2 style="text-align: left;">
<span style="font-weight: normal;"><a href="http://www.comp-psyche.com/2015/01/heap-sort-program-in-c.html#Heap Sort In C" name="Heap Sort In C">HEAP SORT IN C</a></span></h2>
<div>
<span style="font-weight: normal;"><a href="http://www.comp-psyche.com/2015/01/heap-sort-program-in-c.html#Heap Sort">Back To Heap Sort</a></span></div>
<div>
<span style="font-weight: normal;"><br />
</span></div>
<div>
Heap sort uses a binary heap, which is a complete binary tree. </div>
<div>
<br /></div>
<div>
<div style="text-align: justify;">
<span style="color: lime;">Binary Tree :</span> A Binary Tree is a hierarchical structure that is either empty or consists of an element, called the root, and two distinct binary trees, called the left subtree and right subtree.</div>
</div>
<div><br /></div><div>Need HTML Homework Help: <a href="https://letstacle.com/html-homework-assignment-help-css-javascript">Get Best HTML CSS JavaScript Homework Help</a><br /></div><div class="g" style="background-color: white; clear: both; color: #202124; font-family: arial, sans-serif; font-size: 14px; line-height: 1.2; margin: 0px; padding-bottom: 16px; padding-left: 16px; padding-right: 16px; width: 600px;"><div class="rc" data-hveid="CAEQAA" data-ved="2ahUKEwj7ov_w0IntAhXJ7HMBHQs9B-QQFSgAMAF6BAgBEAA" style="clear: both; padding-bottom: 0px; position: relative;"></div></div>
<div>
<div style="text-align: justify;"> Example : </div>
</div>
<div>
<br /></div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: left; margin-right: 1em; text-align: left;"><tbody>
<tr><td style="text-align: center;"><a href="http://2.bp.blogspot.com/-a8hXEF_Z4tQ/VKWPiN2VjZI/AAAAAAAAANY/5-0iFuIFc4o/s1600/binary_tree.png" style="margin-left: auto; margin-right: auto;"><img alt="Heap Sort : Binary Tree" border="0" height="182" src="http://2.bp.blogspot.com/-a8hXEF_Z4tQ/VKWPiN2VjZI/AAAAAAAAANY/5-0iFuIFc4o/s1600/binary_tree.png" title="Heap Sort Program In C" width="200" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="color: lime;">Heap Sort : Binary Tree</span></td></tr>
</tbody></table>
<div>
<br /></div>
<br />
<br />
<div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
Heap is a binary tree with the following properties : </div>
<div>
<ul style="text-align: left;">
<li>It is a complete binary tree.</li>
<li> Each node is greater than or equal to any of its children.</li>
</ul>
</div>
<div>
<div style="text-align: justify;">
<span style="color: lime;">Complete Binary Tree :</span> A binary tree is complete if each of its levels is full, except that the last level may not be full and all the leaves on the last level are placed leftmost.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Example : </div>
<div style="text-align: justify;">
<br /></div>
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: left; margin-right: 1em; text-align: left;"><tbody>
<tr><td style="text-align: center;"><a href="http://3.bp.blogspot.com/-JcCc4yt4R9s/VKWTYvmpIwI/AAAAAAAAANk/92g56U31U-o/s1600/complete_binary_tree.png" style="clear: left; margin-bottom: 1em; margin-left: auto; margin-right: auto;"><img alt="Heap Sort : Complete Binary Tree" border="0" height="132" src="http://3.bp.blogspot.com/-JcCc4yt4R9s/VKWTYvmpIwI/AAAAAAAAANk/92g56U31U-o/s1600/complete_binary_tree.png" title="Heap Sort Program In C" width="200" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="color: lime;">Heap Sort : Complete Binary Tree</span></td></tr>
</tbody></table>
<div style="text-align: justify;">
<br /></div>
</div>
<h2 style="text-align: left;">
<span style="font-weight: normal;"><br />
</span></h2>
<h2 style="text-align: left;">
<span style="font-weight: normal;"><br />
</span></h2>
<h2 style="text-align: left;">
<span style="font-weight: normal;"><br />
</span></h2>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
Heap Example : </div>
<div style="text-align: left;">
<br /></div>
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: left; margin-right: 1em; text-align: left;"><tbody>
<tr><td style="text-align: center;"><a href="http://2.bp.blogspot.com/-ZI24XB_mzWU/VKWUy32tMQI/AAAAAAAAANs/5awI8uAIJKQ/s1600/heap.png" style="clear: left; margin-bottom: 1em; margin-left: auto; margin-right: auto;"><img alt="Heap Sort : Heap" border="0" height="114" src="http://2.bp.blogspot.com/-ZI24XB_mzWU/VKWUy32tMQI/AAAAAAAAANs/5awI8uAIJKQ/s1600/heap.png" title="Heap Sort Program In C" width="200" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="color: lime;">Heap Sort : Heap</span></td></tr>
</tbody></table>
<div style="text-align: left;">
<br /></div>
<h2 style="text-align: left;">
<span style="font-weight: normal;"><br />
</span></h2>
<h2 style="text-align: left;">
<span style="font-weight: normal;"><br />
</span></h2>
<h2 style="text-align: left;">
<span style="font-weight: normal;"><br />
</span></h2>
<h2 style="text-align: left;">
<span style="font-weight: normal;"><br />
</span></h2>
<div style="text-align: justify;">
<span style="color: lime; font-weight: normal;">Note : </span>We represent heaps in level order, going from left to right. The array corresponding to the heap above is : </div>
<div style="text-align: justify;">
<span style="color: lime;">[45, 24, 32, 16,19,12, 21].</span></div>
<div style="text-align: justify;">
<span style="color: lime;"><br />
</span></div>
<h2 style="text-align: justify;">
<span style="font-weight: normal;"><a href="http://www.comp-psyche.com/2015/01/heap-sort-program-in-c.html#Pseudocode To Add Node" name="Pseudocode To Add Node">PSEUDOCODE TO ADD NODE IN HEAP</a></span></h2>
<div>
<span style="font-weight: normal;"><a href="http://www.comp-psyche.com/2015/01/heap-sort-program-in-c.html#Heap Sort">Back To Heap Sort</a></span></div>
<div>
<br /></div>
<div style="text-align: justify;">
<div>
To add a new node to the heap, first add it to the end of the heap and then rebuild the tree as follows:</div>
<div>
<br /></div>
<div>
<span style="color: lime;">Let the last node be the current node;</span></div>
<div>
<span style="color: lime;">while (the current node is greater than its parent) {</span></div>
<div>
<span style="color: lime;">Swap the current node with its parent;</span></div>
<div>
<span style="color: lime;">Now the current node is one level up;</span></div>
<div>
<span style="color: lime;">}</span></div>
<div>
<span style="color: lime;"><br />
</span></div>
Suppose we want to insert <span style="color: lime;">3, 5, 1, 19, 11, 22. </span>We assume that the heap is initially empty.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="http://4.bp.blogspot.com/-ZM736jicFgE/VKWrwjagM3I/AAAAAAAAAOY/Ik-p7Hsd7qU/s1600/add_node.png" style="margin-left: auto; margin-right: auto;"><img alt="Heap Sort : Adding Node In Heap" border="0" height="236" src="http://4.bp.blogspot.com/-ZM736jicFgE/VKWrwjagM3I/AAAAAAAAAOY/Ik-p7Hsd7qU/s1600/add_node.png" title="Heap Sort Program In C" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="color: lime;">Heap Sort : Adding Node In Heap</span></td></tr>
</tbody></table>
<h2>
<span style="font-weight: normal;"><br />
</span></h2>
<div>
<span style="font-weight: normal;">Now lets insert a new node <span style="color: lime;">88</span> in the above heap.</span></div>
<div>
<span style="font-weight: normal;"><br />
</span></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="http://2.bp.blogspot.com/-Gd8XNUt3y0I/VKWw6_VTx6I/AAAAAAAAAPA/kHdjKjvlzO8/s1600/new_node.png" style="margin-left: auto; margin-right: auto;"><img alt="Heap Sort : Rebuilding of Heap after adding a new node" border="0" height="168" src="http://2.bp.blogspot.com/-Gd8XNUt3y0I/VKWw6_VTx6I/AAAAAAAAAPA/kHdjKjvlzO8/s1600/new_node.png" title="Heap Sort Program In C" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="color: lime;">Heap Sort : Rebuilding of Heap after adding a new node</span></td></tr>
</tbody></table>
<div>
<span style="font-weight: normal;"><br />
</span></div>
<h2>
<span style="font-weight: normal;"><a href="http://www.comp-psyche.com/2015/01/heap-sort-program-in-c.html#Pseudocode To Remove Root" name="Pseudocode To Remove Root">PSEUDOCODE TO REMOVE ROOT FROM HEAP</a></span></h2>
<div>
<span style="font-weight: normal;"><a href="http://www.comp-psyche.com/2015/01/heap-sort-program-in-c.html#Heap Sort" style="text-align: left;">Back To Heap Sort</a></span></div>
<div>
<br /></div>
<div>
<div style="text-align: justify;">
Often you need to remove the max element, which is the root in a heap. After the root is removed, the tree must be rebuilt to maintain the heap property. The algorithm for rebuilding the tree can be described as follows:</div>
</div>
<div>
<br /></div>
<div>
<div>
<span style="color: lime;">Move the last node to replace the root;</span></div>
<div>
<span style="color: lime;">Let the root be the current node;</span></div>
<div>
<span style="color: lime;">while (the current node has children and the current node is </span><span style="color: lime;">smaller than one of its children) {</span></div>
<div>
<span style="color: lime;">Swap the current node with the larger of its children;</span></div>
<div>
<span style="color: lime;">Now the current node is one level down;</span></div>
</div>
<div>
<span style="color: lime;">}</span></div>
</div>
<div style="text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="http://2.bp.blogspot.com/-ob98SM_bMjc/VKWzcoFCyZI/AAAAAAAAAPU/IL8mD0Uwpr0/s1600/remove.png" style="margin-left: auto; margin-right: auto;"><img alt="Heap Sort : Removing Root and Rebuilding Heap" border="0" height="170" src="http://2.bp.blogspot.com/-ob98SM_bMjc/VKWzcoFCyZI/AAAAAAAAAPU/IL8mD0Uwpr0/s1600/remove.png" title="Heap Sort Program In C" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td class="tr-caption" style="font-size: 13px;"><span style="color: lime;">Heap Sort : Removing Root and Rebuilding Heap<br />
</span></td></tr>
</tbody></table>
</td></tr>
</tbody></table>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
<br /></div>
<h2 style="text-align: left;">
<span style="font-weight: normal;"><a href="http://www.comp-psyche.com/2015/01/heap-sort-program-in-c.html#Heap Sort Performed" name="Heap Sort Performed">HOW HEAP SORT IS PERFORMED</a></span></h2>
<div>
<a href="http://www.comp-psyche.com/2015/01/heap-sort-program-in-c.html#Heap Sort">Back To Heap Sort</a></div>
<div>
<ul style="text-align: left;">
<li style="text-align: justify;">First we take input in an array.</li>
<li style="text-align: justify;">Then we insert these element in heap.</li>
<li style="text-align: justify;">As we know that root of the heap is maximum element so we remove root and rebuild heap so that the next maximum element is at root. Rebuilding ensures that our tree is in the form of heap.</li>
<li style="text-align: justify;">We store the root ( maximum element ) in decreasing order of array length. We could have used another array as well to store the root.</li>
</ul>
</div>
<h2 style="text-align: left;">
<br />
</h2>
<h2 style="text-align: left;">
<span style="font-weight: normal;"><a href="http://www.comp-psyche.com/2015/01/heap-sort-program-in-c.html#Heap Sort Program In C" name="Heap Sort Program In C">HEAP SORT PROGRAM IN C</a></span></h2>
</div>
<div>
<span style="font-weight: normal;"><a href="http://www.comp-psyche.com/2015/01/heap-sort-program-in-c.html#Heap Sort">Back To Heap Sort</a></span></div>
<div>
<br /></div>
<div class="mokcode">
<pre><span style="color: blue;">// C Program ( Code ) for Heap sort</span></pre>
<pre><span style="color: blue;">#include<stdio.h>
void insert(int a[], int n, int item);
int deleteheap(int a[],int n);
int main()
{
int a[20],i,n,item;
printf(" Enter number of elements in array : ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf(" Enter number %d : ",i+1);
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
item=a[i];
insert(a,i,item);
}
printf("\n Heap is : ");
for(i=0;i<n;i++)
{
printf("%d ",a[i]);
}
for(i=n;i>=1;i--)
{
item=deleteheap(a,i);
// Stores item=Maximum element in decreasing order of array length
a[i-1]=item;
}
printf("\n SORTED LIST IS!!!!\n");
for(i=0;i<n;i++)
{
printf(" %d ",a[i]);
}
}
// Used to Build Heap
void insert(int a[], int n, int item)
{
int ptr,par,temp;
ptr=n;
while(ptr>=1)
{
par=(ptr-1)/2;
if(a[par]>=item)
{
a[ptr]=item;
return;
}
else
{
a[ptr]=a[par];
ptr=par;
}
a[ptr]=item;
}
}
/* Remove root which is the maximum element in Heap and rebuild heap
so that the next maximum element is at root. Rebuilding ensures
that our tree is in the form of heap.
Returns item = a[0] wcich contains the root of the heap.
*/
int deleteheap(int a[],int n)
{
int i=0,item,temp;
// a[0] - contains the root of the heap
item=a[0];
a[0]=a[n-1];
n=n-1;
while(((a[i]<a[2*i+1])||(a[i]<a[2*i+2]))&&((2*i+1)<n))
{
if(a[2*i+1]>a[2*i+2])
{
temp=a[i];
a[i]=a[2*i+1];
a[2*i+1]=temp;
i=2*i+1;
}
else
{
temp=a[i];
a[i]=a[2*i+2];
a[2*i+2]=temp;
i=2*i+2;
}
}
// Root of the heap is returned
return item;
}
</span></pre>
</div>
<h2 style="text-align: left;">
<span style="font-weight: normal;"><a href="http://www.comp-psyche.com/2015/01/heap-sort-program-in-c.html#Heap Sort Program With Output" name="Heap Sort Program With Output">HEAP SORT PROGRAM OUTPUT</a></span></h2>
<div>
<span style="font-weight: normal;"><a href="http://www.comp-psyche.com/2015/01/heap-sort-program-in-c.html#Heap Sort">Back To Heap Sort</a></span></div>
<div>
<br /></div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: left; margin-right: 1em; text-align: left;"><tbody>
<tr><td style="text-align: center;"><a href="http://1.bp.blogspot.com/-c39rseIPm00/VKW2MwXBKtI/AAAAAAAAAPw/_X9P_8ZQZgQ/s1600/heap_output.png" style="margin-left: auto; margin-right: auto;"><img alt="Heap Sort : Heap sort code output" border="0" height="148" src="http://1.bp.blogspot.com/-c39rseIPm00/VKW2MwXBKtI/AAAAAAAAAPw/_X9P_8ZQZgQ/s1600/heap_output.png" title="Heap Sort Program In C With Output" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="color: lime;">Heap Sort Output</span></td></tr>
</tbody></table>
<div>
<span style="font-weight: normal;"><br />
</span></div>
</div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<span style="color: yellow;">More Informative Posts :</span><br />
<ul style="text-align: left;">
<li><a href="http://www.comp-psyche.com/2014/08/counting-sort-program-in-c.html">Counting Sort Program In C</a></li>
<li><a href="http://www.comp-psyche.com/2014/06/quick-sort-program-in-c.html">Quick Sort Program In C</a></li>
<li><a href="http://www.comp-psyche.com/2014/06/merge-sort-program-in-c.html">Merge Sort Program In C</a></li>
<li><a href="http://www.comp-psyche.com/2014/07/bubble-sort-program-in-c.html">Bubble Sort Program In C</a></li>
<li><a href="http://www.comp-psyche.com/2014/07/selection-sort-program-in-c.html">Selection Sort Program In C</a></li>
<li><a href="http://www.comp-psyche.com/2014/12/insertion-sort-algorithm-time-complexity-and-program-in-c.html">Insertion Sort Program In C</a></li>
<li>Shell sort Program In C</li>
<li>Radix Sort Program In C</li>
<li>Bucket Sort Program In C</li>
</ul>
</div>
Mantu Kumarhttp://www.blogger.com/profile/02897308282659594376noreply@blogger.com0tag:blogger.com,1999:blog-8285804830535272268.post-74856083923651196692014-11-07T23:00:00.003-08:002016-05-19T13:50:26.441-07:00Different Types Of Errors In C<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="text-align: justify;">
<span style="color: lime;">Errors</span> are <span style="color: lime;">mistake</span> that we programmer often commit. <span style="color: lime;">Errors</span> also called as <span style="color: lime;">bugs</span> causes the program to either run unexpectedly ( shows unexpected result ) or prevent the execution of a program. As programmer we are prone to make mistakes. So we should keep in mind the following different types of <span style="color: lime;">errors</span> in c which we might commit :<br />
<br /></div>
<h2 style="text-align: left;">
<span style="color: yellow;"><a href="http://www.comp-psyche.com/2014/11/types-of-errors-in-c-syntax-semantic-logical-linker-runtime.html#Types of Errors In C" name="Types of Errors In C" style="font-weight: normal;">TYPES OF ERRORS</a></span></h2>
<div>
<ul style="text-align: left;">
<li><a href="http://www.comp-psyche.com/2014/11/types-of-errors-in-c-syntax-semantic-logical-linker-runtime.html#Syntax error in C">Syntax Errors</a></li>
<li><a href="http://www.comp-psyche.com/2014/11/types-of-errors-in-c-syntax-semantic-logical-linker-runtime.html#Semantic error in C">Semantic Errors</a></li>
<li><a href="http://www.comp-psyche.com/2014/11/types-of-errors-in-c-syntax-semantic-logical-linker-runtime.html#Logical error in c">Logical Errors</a></li>
<li><a href="http://www.comp-psyche.com/2014/11/types-of-errors-in-c-syntax-semantic-logical-linker-runtime.html#Linker error in c">Linker Errors</a></li>
<li><a href="http://www.comp-psyche.com/2014/11/types-of-errors-in-c-syntax-semantic-logical-linker-runtime.html#Runtime error in c">Runtime Errors</a></li>
</ul>
<h2 style="text-align: left;">
<span style="font-weight: normal;"><span style="color: yellow;"><a href="http://www.comp-psyche.com/2014/11/types-of-errors-in-c-syntax-semantic-logical-linker-runtime.html#Syntax error in C" name="Syntax error in C">SYNTAX ERROR IN C</a></span></span></h2>
<div>
<a href="http://www.comp-psyche.com/2014/11/types-of-errors-in-c-syntax-semantic-logical-linker-runtime.html#Types of Errors In C">Back To Types of Errors</a></div>
<div style="text-align: left;">
</div>
<ul style="text-align: left;">
<li style="text-align: justify;"><span style="color: lime;">Syntax Errors</span> are basically <span style="color: lime;">compiler</span> errors or <span style="color: lime;">compile-time</span> errors which occurs when we do not follow the grammar of the programming language. </li>
<li style="text-align: justify;">It is detected when you compile the program by the compiler.</li>
</ul>
<br />
<div style="text-align: justify;">
<span style="color: yellow;"><b>Syntax Errors occurs :</b></span> </div>
<div style="text-align: left;">
</div>
<ul style="text-align: left;">
<li><div style="text-align: justify;">
Due to missing semicolon ( <span style="color: lime;">' ; '</span> ). It is used as an <span style="color: lime;">terminating</span> statement. So when you forget to place a semicolon or use any other alternative then it causes syntax error. </div>
<div class="mokcode">
<pre><span style="color: blue;"> #include<stdio.h>
int main()
{
int a=10 // Syntax error as semicolon is missing
int b=100 : // Syntax error as using ':' instead of ';'
return 0;
}</span>
</pre>
</div>
</li>
<li>It occurs when we use a variable which is not declared in program. </li>
<div class="mokcode">
<pre><span style="color: blue;"> #include<stdio.h>
int main()
{
printf("Value of a : %d",a); // error as 'a' is not declared anywhere in program
return 0;
}</span>
</pre>
</div>
<li>Error Occurs due to missing and unmatched parenthesis.<br />
<div class="mokcode">
<pre><span style="color: blue;"> // Syntax Error as ')' parenthesis is missing
void sum(
// Syntax Error as '}' parenthesis is missing
void product()
{ statement
// Syntax Error due to unmatched parenthesis
void a{}</span>
</pre>
</div>
</li>
</ul>
</div>
<h2 style="text-align: left;">
<span style="color: yellow; font-weight: normal;"><a href="http://www.comp-psyche.com/2014/11/types-of-errors-in-c-syntax-semantic-logical-linker-runtime.html#Semantic error in C" name="Semantic error in C">SEMANTIC ERROR IN C</a></span></h2>
<div>
<a href="http://www.comp-psyche.com/2014/11/types-of-errors-in-c-syntax-semantic-logical-linker-runtime.html#Types of Errors In C">Back To Types of Errors</a></div>
<div>
<ul style="text-align: left;">
<li style="text-align: justify;">Semantic errors occurs when the statement written in the program are not meaningful to the compiler.</li>
<li><div style="text-align: justify;">
Semantic errors indicate an improper use of Java statements.</div>
<div style="text-align: justify;">
Example : <span style="color: lime;">int a+b=c; // Semantic Error</span></div>
<div style="text-align: justify;">
Correct one : int c=a+b;</div>
<div style="text-align: justify;">
<br /></div>
<span style="color: lime;"><div style="text-align: justify;">
int a=+b; // Semantic Error</div>
</span><div style="text-align: justify;">
Correct one : <span style="color: lime;">int a+=b; // Shorthand notation </span></div>
</li>
</ul>
</div>
<h2 style="text-align: left;">
<span style="color: yellow; font-weight: normal;"><a href="http://www.comp-psyche.com/2014/11/types-of-errors-in-c-syntax-semantic-logical-linker-runtime.html#Logical error in c" name="Logical error in c">LOGICAL ERROR IN C</a></span></h2>
<div>
<a href="http://www.comp-psyche.com/2014/11/types-of-errors-in-c-syntax-semantic-logical-linker-runtime.html#Types of Errors In C">Back To Types of Errors</a></div>
<div>
<ul style="text-align: left;">
<li style="text-align: justify;"><span style="color: lime;">Logical errors</span> are errors that shows unexpected results.</li>
<li style="text-align: justify;">It occurs when you write a program that works, but does not do what you intend it to do.<br />
<span style="color: lime;"> Example :</span> Suppose you want to find the factorial of a number but instead of multiplying number you end up adding it.<br />
<div class="mokcode">
<pre><span style="color: blue;">#include<stdio.h>
int main()
{
int i;
int factorial=1;
for(i=1;i<=n;i++)
factorial=factorial+i; // Logical Error. Correct statement : factorial=factorial*i;
return 0;
}</span>
</pre>
</div>
<br />
Though the program would work fine and would not show any <span style="color: lime;">syntax</span> or <span style="color: lime;">run time</span> error. But the output which you were expecting will not be shown. </li>
</ul>
</div>
<h2 style="text-align: left;">
<span style="color: yellow; font-weight: normal;"><a href="http://www.comp-psyche.com/2014/11/types-of-errors-in-c-syntax-semantic-logical-linker-runtime.html#Linker error in c" name="Linker error in c">LINKER ERROR IN C</a></span></h2>
<div>
<a href="http://www.comp-psyche.com/2014/11/types-of-errors-in-c-syntax-semantic-logical-linker-runtime.html#Types of Errors In C">Back To Types of Errors</a></div>
<div>
<ul style="text-align: left;">
<li><div style="text-align: justify;">
<span style="color: lime;">Linker Errors</span> are errors that occurs when we do not <span style="color: lime;">include</span> <span style="color: lime;">header files</span> for the predefined functions used in a program and when we <span style="color: lime;"> misspell a standard c function.</span></div>
<div class="mokcode">
<pre><span style="color: blue;">#include<stdio.h>
int Main() // Linker error as 'main' is misspelled as 'Main'
{
printf("Hello : ");
return 0;
}</span>
</pre>
</div>
</li>
</ul>
</div>
<h2>
<span style="color: yellow; font-weight: normal;"><a href="http://www.comp-psyche.com/2014/11/types-of-errors-in-c-syntax-semantic-logical-linker-runtime.html#Runtime error in c" name="Runtime error in c">RUNTIME ERROR IN C</a></span></h2>
<div>
<a href="http://www.comp-psyche.com/2014/11/types-of-errors-in-c-syntax-semantic-logical-linker-runtime.html#Types of Errors In C">Back To Types of Errors</a></div>
<div>
<ul style="text-align: left;">
<li>Run-time errors are errors that occurs during the execution of the program.<br />
<span style="color: lime;"> Example : </span><br />
<ul>
<li>When we divide a number by zero.</li>
<li>When input data is not in the correct format.</li>
</ul>
<div class="mokcode">
<pre><span style="color: blue;">//Runtime error program in c</span>
<span style="color: blue;">#include<stdio.h>
int main()
{
int a=10,b=0,result;
int number;
result=a/b; // Runtime error
scanf("%d",&number); // Error occurs when you input some other character instead of 'numbers'
return 0;
}</span>
</pre>
</div>
</li>
</ul>
</div>
<span style="color: yellow;">More Informative Posts : </span><br />
<ul style="text-align: left;">
<li><span style="color: yellow;"><a href="http://www.comp-psyche.com/2014/07/good-programming-practices.html">Good Programming Practices</a></span></li>
<li><span style="color: yellow;"><a href="http://www.comp-psyche.com/2013/11/common-programming-error-complete-list.html">Common Programming Errors</a></span></li>
<li><span style="color: yellow;"><a href="http://www.comp-psyche.com/2013/06/escape-sequence-and-formatted-output.html">Escape Sequence in C</a></span></li>
</ul>
</div>
Mantu Kumarhttp://www.blogger.com/profile/02897308282659594376noreply@blogger.com3tag:blogger.com,1999:blog-8285804830535272268.post-34473528342780517222014-09-23T11:06:00.000-07:002014-09-23T11:06:05.645-07:00C Program to add, subtract, multiply and divide two numbers<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="text-align: left;">
The following programs takes input of two numbers from user and add, subtract and divide two numbers.<br />
<br />
<span style="color: lime;">Sample Input / Output :</span><br />
<br />
Enter any two number : <span style="color: lime;">20</span><br />
<span style="color: lime;">10</span><br />
<br />
Sum = <span style="color: lime;">30</span><br />
Subtracted value = <span style="color: lime;">10</span><br />
Multiplied value = <span style="color: lime;">200</span><br />
Division value = <span style="color: lime;">2</span><br />
<br /></div>
<div class="mokcode">
<span style="color: blue;">// C Program to add, subtract, multiply and divide two numbers</span><br />
<pre><span style="color: blue;">#include<stdio.h></span><stdio .h=""><span style="color: blue;">
</span><conio .h=""><span style="color: blue;">
int main()
{
int a, b;
printf("Enter any two number : ");
scanf("%d",&a);
scanf("%d",&b);
printf("Sum=%d",a+b);
printf("\nSubtracted value=%d",a-b);
printf("\nMultiplied value=%d",a*b);
printf("\n Division value=%d",a/b);
</span><span style="color: blue;">
return 0;
}</span></conio></stdio></pre>
</div>
</div>
Mantu Kumarhttp://www.blogger.com/profile/02897308282659594376noreply@blogger.com0tag:blogger.com,1999:blog-8285804830535272268.post-8886239954314645022014-08-04T08:39:00.001-07:002018-05-26T14:07:49.753-07:00Counting Sort Program In C<div dir="ltr" style="text-align: left;" trbidi="on">
<h2 style="text-align: left;">
<span style="font-weight: normal;"><span style="color: yellow;"><a href="http://www.comp-psyche.com/2014/08/counting-sort-program-in-c.html#Counting%20Sort" name="Counting Sort">COUNTING SORT</a></span></span></h2>
<div>
<ul style="text-align: left;">
<li><a href="http://www.comp-psyche.com/2014/08/counting-sort-program-in-c.html#Counting%20Sort%20In%20C">Counting Sort In C</a></li>
<li><a href="http://www.comp-psyche.com/2014/08/counting-sort-program-in-c.html#Counting%20Sort%20Algorithm">Algorithm for Counting Sort</a></li>
<li><a href="http://www.comp-psyche.com/2014/08/counting-sort-program-in-c.html#Counting%20Sort%20Program%20In%20C">Counting Sort Program In C</a></li>
</ul>
<div>
<br /></div>
</div>
<div>
<h2 style="text-align: left;">
<span style="color: yellow; font-weight: normal;"><a href="http://www.comp-psyche.com/2014/08/counting-sort-program-in-c.html#Counting%20Sort%20In%20C" name="Counting Sort In C">COUNTING SORT IN C</a></span></h2>
<div>
<a href="http://www.comp-psyche.com/2014/08/counting-sort-program-in-c.html#Counting%20Sort">Back To Counting Sort</a></div>
<br />
<div style="text-align: justify;">
In the code for counting sort, we assume that the input is an array A[1 . . . n] and we require two other arrays: the array B[1 . . . n] holds the sorted output, and the array C[0 . . . k] provides temporary working storage. Here<span style="color: blur;"> </span><span style="color: blue;">k = maximum element</span><span style="color: blur;"> </span>present in array.</div>
<br />
Consider following elements to be sorted using counting sort :<span style="color: blue;"> </span><span style="color: blue;">2, 5, 3, 0, 2, 3, 0, 3</span></div>
<div>
<br />
So we have in array A[1 . . . 8 ] :<br />
<table border="1"><tbody>
<tr><td> 2 </td> <td> 5 </td> <td> 3 </td> <td> 0 </td> <td> 2 </td> <td> 3 </td> <td> 0 </td> <td> 3 </td> </tr>
</tbody></table>
<br />
<div style="text-align: justify;">
Now what we have to do is initialize the auxiliary array <span style="color: blue;">C[0 . . . k]</span> with <span style="color: blue;">0.</span> Here <span style="color: blue;">k = 5.</span></div>
<div style="text-align: justify;">
So C[0 . . . 5] becomes :</div>
<table border="1"><tbody>
<tr><td> 0 </td> <td> 0 </td> <td> 0 </td> <td> 0 </td> <td> 0 </td> <td> 0 </td> </tr>
</tbody></table>
<br />
<div style="text-align: justify;">
Next step is to count the frequency of each element and store it in their respective index position i.e here <span style="color: blue;">frequency of 0 = 2.</span> So we place <span style="color: blue;">'2'</span> at index position <span style="color: blue;">'0'.</span><span style="color: blue;"> </span>Similarly we place each element and the array becomes C[0 . . . 5] :</div>
<table border="1"><tbody>
<tr><td> 2 </td> <td> 0 </td> <td> 2 </td> <td> 3 </td> <td> 0 </td> <td> 1 </td> </tr>
</tbody></table>
</div>
<div>
<br />
<div style="text-align: justify;">
Now we add the <span style="color: blue;">current index position</span> with its <span style="color: blue;">previous index position</span> and store it in the <span style="color: blue;">current index position</span> i.e <span style="color: blue;"><span style="color: blue;">C[ i ] = C[ i ] + C[ i - 1 ]</span> </span>where <span style="color: blue;">'i'</span> starts from <span style="color: blue;">'</span><span style="color: blue;">1'.</span></div>
</div>
<div>
<br /></div>
<div>
So C[ 0 . . . 5 ] becomes : </div>
<table border="1"><tbody>
<tr><td> 2 </td> <td> 2 </td> <td> 4 </td> <td> 7 </td> <td> 7 </td> <td> 8 </td> </tr>
</tbody></table>
<br />
<div style="text-align: justify;">
The final step is to place the elements in <span style="color: blue;">B[ 1 . . . 8 ]</span> with reference to<span style="color: blue;"> <span style="color: blue;"><span style="color: blue;">C[ 0 . . . 5 ]</span> </span></span>i.e Now we treat elements in <span style="color: blue;">C[ 0 . . . 5 ]</span> as index of <span style="color: blue;">B[ 1 . . . 8 ]</span> and index of <span style="color: blue;">C[ 0 . . . 5 ]</span> as elements of <span style="color: blue;"><span style="color: blue;">B[ 1 . . . 8 ].</span> </span>So at index position <span style="color: blue;">'8'</span> we have element<span style="color: blue;"> <span style="color: blue;">'5'</span></span> so we place <span style="color: blue;">'5'</span> at index position of <span style="color: blue;"><span style="color: blue;">'8'</span> of <span style="color: blue;">B[ 1 . . . 8 ]</span></span> ( B[ 8 ] = 5 ) and we reduce the index position by <span style="color: blue;"><span style="color: blue;">'1'</span> i.e <span style="color: blue;">8-1 = 7</span></span>. Now note that we have element<span style="color: blue;"> <span style="color: blue;">'7'</span></span><span style="color: blue;"> </span> in <span style="color: blue;"><span style="color: blue;">C[ 4 ]</span> </span>position but <span style="color: blue;">'4'</span> is not present in the original array so we skip it and move to <span style="color: blue;">C[ 3 ]</span> position, so we place <span style="color: blue;">'3'</span><span style="color: blue;"> </span>at index position <span style="color: blue;">'7'</span> of<span style="color: blue;"> <span style="color: blue;">B[ 1 . . . 8 ].</span></span> Similarly we place each element in <span style="color: blue;"><span style="color: blue;">B[ 1 . . . 8 ]</span> </span>and we get sorted array.</div>
<div>
<br /></div>
<div>
So the sorted array B[ 1 . . . 8 ] is :</div>
<div>
<table border="1"><tbody>
<tr><td> 0 </td> <td> 0 </td> <td> 2 </td> <td> 2 </td> <td> 3 </td> <td> 3 </td><td> 3 </td><td> 5 </td> </tr>
</tbody></table>
<div>
<div>
<br /></div>
<div>
<h2 style="text-align: left;">
<span style="font-weight: normal;"><span style="color: yellow;"><a href="http://www.comp-psyche.com/2014/08/counting-sort-program-in-c.html#Counting%20Sort%20Algorithm" name="Counting Sort Algorithm">COUNTING SORT ALGORITHM</a></span></span></h2>
</div>
<div>
<a href="http://www.comp-psyche.com/2014/08/counting-sort-program-in-c.html#Counting%20Sort">Back To Counting Sort</a></div>
<div>
<span style="font-weight: normal;"><span style="color: yellow;"><br />
</span></span></div>
<div class="mokcode">
<pre></pre>
<pre><span style="color: blue;">// Counting Sort algorithm
</span></pre>
<pre><span style="color: blue;">CountingSort(A,B,n,k)</span></pre>
<pre><span style="color: blue;"> int C[0 . . . k ]</span></pre>
<pre><span style="color: blue;"> for i=0 to k</span></pre>
<pre><span style="color: blue;"> C[i]=0</span></pre>
<pre><span style="color: blue;"> for j=1 to n</span></pre>
<pre><span style="color: blue;"> C[A[j]] = C[A[j]] + 1;</span></pre>
<pre><span style="color: blue;"> for i=1 to k</span></pre>
<pre><span style="color: blue;"> C[i] = C[i] + C[i-1];</span></pre>
<pre><span style="color: blue;"> for j=n downto 1</span></pre>
<pre><span style="color: blue;"> B[C[A[j]]] = A[j];
C[a[j]] = C[A[j]] - 1;</span></pre>
</div>
<div>
<br />
<h2 style="text-align: left;">
<span style="font-weight: normal;"><span style="color: yellow;"><a href="http://www.comp-psyche.com/2014/08/counting-sort-program-in-c.html#Counting%20Sort%20Program%20In%20C" name="Counting Sort Program In C">COUNTING SORT PROGRAM IN C</a></span></span></h2>
</div>
<div>
<a href="http://www.comp-psyche.com/2014/08/counting-sort-program-in-c.html#Counting%20Sort">Back To Counting Sort</a></div>
<div>
<span style="font-weight: normal;"><br />
</span></div>
<div class="mokcode">
<pre></pre>
<pre><span style="color: blue;">// Counting sort program in c</span></pre>
<pre><span style="color: blue;">
#include<stdio.h>
void CountingSort(int a[], int sorted_array[], int max_element, int n);
int main()
{
int a[20],i,n;
int max_element, sorted_array[20];
printf("Enter number of elements in array : ");
scanf("%d",&n);
// Inputting elements
for(i=1;i<=n;i++)
{
printf("Enter number %d: ",i+1);
scanf("%d",&a[i]);
}
// Displaying Elements before counting sort
printf("Items in the array are : ");
for(i=1;i<=n;i++)
{
printf("%d ",a[i]);
}
// Finding Maximum element
max_element=a[1];
for(i=2;i<=n;i++)
{
if(a[i] > max_element)
{
max_element = a[i];
}
}
//Applying counting sort
CountingSort(a, sorted_array, max_element, n);
// Displaying elements after count sort
printf("\nElements after count sort : ");
for(i=1;i<=n;i++)
{
printf("%d ",sorted_array[i]);
}
return 0;
}
void CountingSort(int a[],int sorted_array[],int max_element, int n)
{
int aux_array[max_element];
int i,j;
// Initializing auxiliary array</span></pre>
<pre><span style="color: blue;"> for(i=0;i<=max_element;i++)
{
aux_array[i]=0;
}
</span></pre>
<pre><span style="color: blue;"> // Placing Frequency of each element in aux_array
for(j=1;j<=n;j++)
{
aux_array[a[j]]=aux_array[a[j]]+1;
}
</span></pre>
<pre><span style="color: blue;"> // Adding elements of current and previous index position
for(i=1;i<=max_element;i++)
{
aux_array[i]=aux_array[i]+aux_array[i-1];
}
</span></pre>
<pre><span style="color: blue;"> // Placing elements in sorted_array
for(j=n;j>=1;j--)
{
sorted_array[aux_array[a[j]]] = a[j];
aux_array[a[j]] = aux_array[a[j]] - 1;
}
}</span>
</pre>
</div>
</div>
</div>
<br />
<br />
<span style="color: #4c1130;"> More Informative Posts :</span><br />
<ul>
<li><a href="http://www.comp-psyche.com/2014/12/insertion-sort-algorithm-time-complexity-and-program-in-c.html">Insertion Sort Program In C</a></li>
<li><a href="http://www.comp-psyche.com/2014/07/selection-sort-program-in-c.html">Selection Sort Program In C</a></li>
<li><a href="http://www.comp-psyche.com/2014/06/quick-sort-program-in-c.html">Quick Sort Program In C</a></li>
<li><a href="http://www.comp-psyche.com/2014/07/counting-sort-program-in-c.html">Counting Sort Program In C</a></li>
<li><a href="http://www.comp-psyche.com/2014/07/bubble-sort-program-in-c.html">Bubble Sort Program In C</a></li>
<li><a href="http://www.comp-psyche.com/2015/01/heap-sort-program-in-c.html">Heap Sort Program In C</a></li>
<li>Bucket Sort Program In C</li>
<li>Shell Sort Program In C</li>
<li>Radix Sort Program In C</li>
</ul>
</div>
Mantu Kumarhttp://www.blogger.com/profile/02897308282659594376noreply@blogger.com3tag:blogger.com,1999:blog-8285804830535272268.post-15083372206028655532014-07-26T22:34:00.000-07:002015-03-01T04:15:33.696-08:00Selection Sort Program In C<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="text-align: justify;">
<a href="http://www.comp-psyche.com/2014/07/selection-sort-program-in-c.html#Selection Sort" name="Selection Sort">Selection Sort</a><br />
<ul>
<li><a href="http://www.comp-psyche.com/2014/07/selection-sort-program-in-c.html#Selection Sort In C">Selection Sort In C</a></li>
<li><a href="http://www.comp-psyche.com/2014/07/selection-sort-program-in-c.html#Selection Sort Algorithm">Algorithm For Selection Sort</a></li>
<li><a href="http://www.comp-psyche.com/2014/07/selection-sort-program-in-c.html#Selection Sort Program In C">Selection Sort Program In C</a></li>
</ul>
<h2>
<span style="font-weight: normal;"><span style="color: yellow;"><br />
</span></span></h2>
<h2>
<span style="font-weight: normal;"><span style="color: yellow;"><a href="http://www.comp-psyche.com/2014/07/selection-sort-program-in-c.html#Selection Sort In C" name="Selection Sort In C">SELECTION SORT IN C</a></span></span></h2>
We start <span style="color: lime;">Selection Sort</span> by scanning the entire given list to find its smallest element and exchange it with the first element, putting the smallest element in its final position in the sorted list. Then we scan the list, starting with the second element, to find the smallest among the <span style="color: lime;">last n - 1</span> elements and exchange it with the second element, putting the second smallest element in its final position. Generally, on the <span style="color: lime;">ith pass</span> through the list, which we number from <span style="color: lime;">0 to n - 2,</span> the algorithm searches for the smallest item among the last <span style="color: lime;">n - i</span> elements and swaps it with <span style="color: lime;">A[i].</span></div>
<div style="text-align: justify;">
<span style="color: lime;"><br />
</span><br />
Consider the following element that is to be sorted using selection sort : <span style="color: lime;">89, 45, 68, 90, 29, 34, 17.</span><br />
The analysis of selection sort is straightforward. The input's size is given by the <span style="color: lime;">number of elements 'n'</span> and the algorithm's basic operation is the key comparison <span style="color: lime;">A[j] < A[min].</span> The number of times it is executed depends only on the array's size.<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="http://2.bp.blogspot.com/-NphjInjCYGY/U84dJsUVV6I/AAAAAAAAAK8/KpdOKU5vuUQ/s1600/Selection+Sort.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img alt="Selection Sort In C : Showing how elements are sorted" border="0" src="http://2.bp.blogspot.com/-NphjInjCYGY/U84dJsUVV6I/AAAAAAAAAK8/KpdOKU5vuUQ/s1600/Selection+Sort.png" height="252" title="Selection Sort Program In C" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="color: lime;">Selection Sort In C : Showing how elements are sorted</span></td></tr>
</tbody></table>
<br />
The above figure shows how given elements <span style="color: lime;">89, 45, 68, 90, 29, 34, 17</span> are sorted according to selection sort. Each line corresponds to one iteration of the algorithm i.e. a pass through the list tail to the right of the vertical bar. An element in bold indicates the smallest element found. Elements to the left of the vertical bar are in their final positions and are not considered in this and subsequent iterations. </div>
<h2 style="text-align: justify;">
<span style="color: yellow; font-weight: normal;"><a href="http://www.comp-psyche.com/2014/07/selection-sort-program-in-c.html#Selection Sort Algorithm" name="Selection Sort Algorithm">SELECTION SORT ALGORITHM</a></span></h2>
<div class="mokcode">
<pre><span style="color: blue;">SelectionSort(int a[],int n)
</span></pre>
<pre><span style="color: blue;"> for i=0 to n-2</span></pre>
<pre><span style="color: blue;"> min=i</span></pre>
<pre><span style="color: blue;">
</span></pre>
<pre><span style="color: blue;"> for j=i+1 to n-1</span></pre>
<pre><span style="color: blue;"> if a[min] > a[j]</span></pre>
<pre><span style="color: blue;"> min = j</span></pre>
<pre><span style="color: blue;"> </span></pre>
<pre><span style="color: blue;"> swap a[i] with a[min]</span></pre>
<pre><span style="color: blue;">
</span></pre>
</div>
<span style="color: blue;"> </span><br />
<h2 style="text-align: left;">
<span style="font-weight: normal;"><span style="color: yellow;"><a href="http://www.comp-psyche.com/2014/07/selection-sort-program-in-c.html#Selection Sort Program In C" name="Selection Sort Program In C">SELECTION SORT PROGRAM IN C</a></span></span></h2>
<div class="mokcode">
<pre><span style="color: blue;">// Selection sort program in c
#include<stdio.h>
void SelectionSort(int [],int);
int main()
{
int a[20],i,n;
printf("Enter number of elements in array : ");
scanf("%d",&n);
// Inputting elements
for(i=0;i<n;i++)
{
printf("Enter number %d: ",i+1);
scanf("%d",&a[i]);
}
// Displaying Elements before selection sort
printf("Items in the array are : ");
for(i=0;i<n;i++)
{
printf("%d ",a[i]);
}
//Applying selection sort
SelectionSort(a,n);
// Displaying elements after selection sort
printf("\nElements after selection sort : ");
for(i=0;i<n;i++)
{
printf("%d ",a[i]);
}
return 0;
}
void SelectionSort(int a[],int n)
{
int i,loc,j,min,temp;
for(i=0;i<=n-2;i++)
{
min = i;
for(j=i+1;j<=n-1;j++)
{
// Finding minimum element
if(a[min] >a[j])
{
min=j;
}
}
//Swapping a[i] with a[min]
temp=a[i];
a[i]=a[min];
a[min]=temp;
}
}</span>
</pre>
</div>
<br />
<span style="color: yellow;">More Informative Posts :</span><br />
<ul>
<li><span style="color: yellow;"><a href="http://www.comp-psyche.com/2014/12/insertion-sort-algorithm-time-complexity-and-program-in-c.html">Insertion Sort Program In C</a></span></li>
<li><span style="color: yellow;"><a href="http://www.comp-psyche.com/2014/06/merge-sort-program-in-c.html">Merge Sort Program In C</a></span></li>
<li><span style="color: yellow;"><a href="http://www.comp-psyche.com/2014/06/quick-sort-program-in-c.html">Quick Sort Program In C</a></span></li>
<li><a href="http://www.comp-psyche.com/2014/07/counting-sort-program-in-c.html">Counting Sort Program In C</a></li>
<li><a href="http://www.comp-psyche.com/2014/07/bubble-sort-program-in-c.html">Bubble Sort Program In C</a></li>
<li><a href="http://www.comp-psyche.com/2015/01/heap-sort-program-in-c.html">Heap Sort Program In C</a></li>
<li>Bucket Sort Program In C</li>
<li>Shell Sort Program In C</li>
<li>Radix Sort Program In C</li>
</ul>
</div>
Mantu Kumarhttp://www.blogger.com/profile/02897308282659594376noreply@blogger.com0tag:blogger.com,1999:blog-8285804830535272268.post-53010244307228205632014-07-23T01:35:00.000-07:002015-03-01T04:19:14.017-08:00Bubble Sort Program In C<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="text-align: justify;">
<h2>
<a href="http://www.comp-psyche.com/2014/07/bubble-sort-program-in-c.html#Bubble Sort" name="Bubble Sort" style="font-weight: normal;">Bubble Sort</a></h2>
<ul>
<li><a href="http://www.comp-psyche.com/2014/07/bubble-sort-program-in-c.html#Bubble Sort In C">Bubble Sort In C</a></li>
<li><a href="http://www.comp-psyche.com/2014/07/bubble-sort-program-in-c.html#Bubble Sort Algorithm">Algorithm for Bubble Sort</a></li>
<li><a href="http://www.comp-psyche.com/2014/07/bubble-sort-program-in-c.html#Bubble Sort Program In C">Bubble Sort Program In C</a></li>
</ul>
<br />
<h2>
<span style="color: yellow; font-weight: normal;"><a href="http://www.comp-psyche.com/2014/07/bubble-sort-program-in-c.html#Bubble Sort In C" name="Bubble Sort In C">BUBBLE SORT IN C</a></span></h2>
<span style="color: lime;"><a href="http://www.comp-psyche.com/2014/07/bubble-sort-program-in-c.html#Bubble Sort">Back To Bubble Sort</a></span><br />
<span style="color: lime;"><br />
</span> <span style="color: lime;">Bubble Sort</span> is a popular but inefficient sorting algorithm. Bubble Sort is another brute-force application to the sorting problem that compares adjacent elements of the list and exchange them if they are out of order. By doing it repeatedly, we end up "bubbling up" the largest element to the last position on the list. The next pass bubbles up the second largest element, and so on until, after <span style="color: lime;">n - 1</span> passes, the list is sorted. Pass <span style="color: lime;">i </span>(<span style="color: lime;">0 <= i <= n - 2</span>) of bubble sort can be represented by the following diagram: </div>
<div>
<div style="text-align: justify;">
<br /></div>
</div>
<div>
<div style="text-align: justify;">
Consider element to be sorted are : <span style="color: lime;">89, 45, 68, 90, 29, 34, 17</span> </div>
</div>
<div>
<br /></div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="http://4.bp.blogspot.com/-vRBUD0Sa1y4/U84K16FwyPI/AAAAAAAAAKs/t9NjWBWOKy4/s1600/bubblesort.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img alt="Bubble Sort In C : Swapping elements" border="0" src="http://4.bp.blogspot.com/-vRBUD0Sa1y4/U84K16FwyPI/AAAAAAAAAKs/t9NjWBWOKy4/s1600/bubblesort.png" title="Bubble Sort Program In C" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="color: lime;">Quick Sort In C : Showing how elements are sorted</span></td></tr>
</tbody></table>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div>
<div style="text-align: justify;">
First <span style="color: lime;">two passes</span> of bubble sort on the given list <span style="color: lime;">89, 45, 68, 90, 29, 34, 17 </span>is shown in above figure. A new line is shown after a swap of two elements is done. The elements to the right of the vertical bar are in their final positions and are not considered in subsequent iterations of the algorithm.</div>
<br />
<h2 style="text-align: left;">
<span style="font-weight: normal;"><span style="color: yellow;"><a href="http://www.comp-psyche.com/2014/07/bubble-sort-program-in-c.html#Bubble Sort Algorithm" name="Bubble Sort Algorithm">BUBBLE SORT ALGORITHM</a></span></span></h2>
</div>
<div>
<span style="font-weight: normal;"><a href="http://www.comp-psyche.com/2014/07/bubble-sort-program-in-c.html#Bubble Sort" style="text-align: justify;">Back To Bubble Sort</a></span></div>
<div>
<span style="font-weight: normal;"><br />
</span></div>
<div class="mokcode">
<pre><span style="color: blue;">// Algorithm for Bubble Sort</span></pre>
<pre><span style="color: blue;">BubbleSort(int a[],int n)</span></pre>
<pre><span style="color: blue;"> for i=0 to n-2
</span></pre>
<pre><span style="color: blue;"> for j=0 to n-2-i</span></pre>
<pre><span style="color: blue;"> if a[j] > a[j+1]</span></pre>
<pre><span style="color: blue;"> swap a[j] with a[j+1]</span></pre>
</div>
<br />
<h2 style="text-align: left;">
<span style="font-weight: normal;"><span style="color: yellow;"><a href="http://www.comp-psyche.com/2014/07/bubble-sort-program-in-c.html#Bubble Sort Program In C" name="Bubble Sort Program In C">BUBBLE SORT PROGRAM IN C</a></span></span></h2>
<div>
<span style="font-weight: normal;"><a href="http://www.comp-psyche.com/2014/07/bubble-sort-program-in-c.html#Bubble Sort" style="text-align: justify;">Back To Bubble Sort</a></span></div>
<div>
<span style="font-weight: normal;"><br />
</span></div>
<div class="mokcode">
<pre><span style="color: blue;">// Bubble sort program in c
#include<stdio.h>
void bubblesort(int a[],int n);
int main()
{
int a[20],i,n;
printf("Enter number of elements in array : ");
scanf("%d",&n);
// Inputting elements
for(i=0;i<n;i++)
{
printf("Enter number %d: ",i+1);
scanf("%d",&a[i]);
}
// Displaying Elements before bubble sort
printf("Items in the array are : ");
for(i=0;i<n;i++)
{
printf("%d ",a[i]);
}
//Applying bubble sort
bubblesort(a,n);
// Displaying elements after bubble sort
printf("\nElements after bubble sort : ");
for(i=0;i<n;i++)
{
printf("%d ",a[i]);
}
return 0;
}
void bubblesort(int a[],int n)
{
int i,j;
for(i=0; i<=n-2; i++)
{
for(j=0;j<=n-i-2;j++)
{
// Swapping elements
if(a[j]>a[j+1])
{
int temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
} </span>
</pre>
</div>
</div>
<br />
<span style="color: yellow;">More Informative Posts : </span><br />
<br />
<ul style="text-align: left;">
<li><span style="color: yellow;"><a href="http://www.comp-psyche.com/2014/07/selection-sort-program-in-c.html">Selection Sort Program In C</a></span></li>
<li><span style="color: yellow;"><a href="http://www.comp-psyche.com/2014/12/insertion-sort-algorithm-time-complexity-and-program-in-c.html">Insertion Sort Program In C</a></span></li>
<li><span style="color: yellow;"><a href="http://www.comp-psyche.com/2014/06/merge-sort-program-in-c.html">Merge Sort Program In C</a></span></li>
<li><span style="color: yellow;"><a href="http://www.comp-psyche.com/2014/06/quick-sort-program-in-c.html">Quick Sort Program In C</a></span></li>
<li><a href="http://www.comp-psyche.com/2015/01/heap-sort-program-in-c.html">Heap Sort Program In C</a></li>
<li><a href="http://www.comp-psyche.com/2014/08/counting-sort-program-in-c.html">Counting Sort Program In C</a></li>
<li>Radix Sort Program In C</li>
<li>Bucket Sort Program In C</li>
<li>Shell Sort Program In C</li>
</ul>
</div>
Mantu Kumarhttp://www.blogger.com/profile/02897308282659594376noreply@blogger.com0tag:blogger.com,1999:blog-8285804830535272268.post-15929699397688975842014-07-16T10:52:00.001-07:002014-07-16T10:55:14.229-07:00GOOD PROGRAMMING PRACTICES<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<a href="http://www.comp-psyche.com/2014/07/good-programming-practices.html#good programming practices" name="good programming practices">GOOD PROGRAMMING PRACTICES</a></div>
<br />
<ul style="text-align: left;">
<li><a href="http://www.comp-psyche.com/2014/07/good-programming-practices.html#good programming practices fundamentals">Fundamentals</a></li>
<li><a href="http://www.comp-psyche.com/2014/07/good-programming-practices.html#good programming practices control structures">Control Structures</a></li>
<li><a href="http://www.comp-psyche.com/2014/07/good-programming-practices.html#good programming practices function">Function</a></li>
<li><a href="http://www.comp-psyche.com/2014/07/good-programming-practices.html#good programming practices array">Array</a></li>
<li><a href="http://www.comp-psyche.com/2014/07/good-programming-practices.html#good programming practices string">String</a></li>
<li><a href="http://www.comp-psyche.com/2014/07/good-programming-practices.html#good programming practices pointers">Pointers</a></li>
<li><a href="http://www.comp-psyche.com/2014/07/good-programming-practices.html#good programming practices structure and union">Structure And Union</a></li>
</ul>
<h2 style="text-align: left;">
<span style="font-weight: normal;"><span style="color: yellow;"><a href="http://www.comp-psyche.com/2014/07/good-programming-practices.html#good programming practices fundamentals" name="good programming practices fundamentals">GOOD PROGRAMMING PRACTICES - FUNDAMENTALS</a></span></span></h2>
<div>
<span style="font-weight: normal;"><a href="http://www.comp-psyche.com/2014/07/good-programming-practices.html#good programming practices">Back to Good Programming Practices</a></span></div>
<div>
<ul style="text-align: left;">
<li>Every function should be preceded by a comment describing the purpose of the function.</li>
<li>Add a comment to the line containing the right brace, } that close every function, including the main(). This helps in determining that the function is ended.</li>
<li>Indent the entire body of each function. This indentation emphasizes the functional structure of a program and helps make program easier to read.</li>
<li>Set a convention for the size of indent you prefer and then uniformly apply that convention.</li>
<li>Choosing meaningful variable name helps make a program self-documenting i.e fewer comments are needed.</li>
<li>Multiple-word variable names can help make a program more readable.Separate the words with underscore eg : comp_psyche or good_programming_practices.</li>
<li>Place a space after each comma to make a program more readable.</li>
<li>Place spaces on either side of binary operator. This makes the operator stand out and makes the program more readable.</li>
<li>Although it is allowed that we can have multiple statement in a single line but to make program more readable there should be only one statement per line in a program.</li>
</ul>
<h2 style="text-align: left;">
<span style="font-weight: normal;"><a href="http://www.comp-psyche.com/2014/07/good-programming-practices.html#good programming practices control structures" name="good programming practices control structures">GOOD PROGRAMMING PRACTICES - CONTROL STRUCTURES</a></span></h2>
</div>
<div>
<div>
<a href="http://www.comp-psyche.com/2014/07/good-programming-practices.html#good programming practices">Back to Good Programming Practices</a></div>
<div>
<ul></ul>
</div>
</div>
<div>
<ul style="text-align: left;">
<li>Indent both body statement of an if...else statement.</li>
<li>If there are several level of indentation, each level should be indented with same additional amount of space.</li>
<li>When performing division by an expression whose value could be zero, explicitly test this case and handle it appropriately in your program ( such as printing an error message ) rather than allowing the fatal error to occur.</li>
<li>In a sentinel-controlled loop, the prompts requesting data entry should explicitly remind the user what the sentinel value is.</li>
<li>Too many levels of nesting can make a program difficult to understand. As a rule, try to avoid using more than three levels of nesting.</li>
<li>Limit the size of the control statement headers to a single line if possible.</li>
<li>Although the case clauses and the default case clause in a switch statement can occur in any order but its advisable to place the default clause at last.</li>
<li>In a switch statement when the default clause is last then the break statement is not required.</li>
</ul>
<h2 style="text-align: left;">
<span style="font-weight: normal;"><a href="http://www.comp-psyche.com/2014/07/good-programming-practices.html#good programming practices function" name="good programming practices function">GOOD PROGRAMMING PRACTICES - FUNCTION</a></span></h2>
</div>
<div>
<div>
<a href="http://www.comp-psyche.com/2014/07/good-programming-practices.html#good programming practices">Back to Good Programming Practices</a></div>
<div>
<ul></ul>
</div>
</div>
<div>
<ul style="text-align: left;">
<li>Familiarize yourself with rich collection of functions in C standard library.</li>
<li>Although It is not incorrect to do so but do not use the same names for a function's arguments and the corresponding parameters in function definition. This helps avoid ambiguity.</li>
<li>Choosing meaningful function names and meaningful parameter names makes program more readable and helps avoid excessive use of comments.</li>
<li>Parameter names are sometimes included in function prototype for documentation purposes. The compiler ignore these names.</li>
<li>Use only uppercase letters in the names of enumeration constants to make these constants stand out in a program and to indicate that enumeration constants are not variable. </li>
</ul>
</div>
<h2 style="text-align: left;">
<span style="font-weight: normal;"><a href="http://www.comp-psyche.com/2014/07/good-programming-practices.html#good programming practices array" name="good programming practices array">GOOD PROGRAMMING PRACTICES - ARRAY</a></span></h2>
<div>
<div>
<a href="http://www.comp-psyche.com/2014/07/good-programming-practices.html#good programming practices">Back to Good Programming Practices</a></div>
<div>
<ul></ul>
</div>
</div>
<div>
<ul style="text-align: left;">
<li>Defining the size of each array as a symbolic constant make program more readable.</li>
<li>Use only uppercase letter for symbolic constant names. This makes these constants stand out in a program and reminds you that symbolic constants are not variable.</li>
<li>In multi-word symbolic constant names, separate the words with underscores for readability.</li>
<li>Strive for program clarity. Sometimes it may be worthwhile to trade off the most efficient use of memory or processor time in favor of writing clearer programs.</li>
<li>When passing an array to a function, also pass the size of the array. This helps make function reusable in many programs.</li>
</ul>
<h2 style="text-align: left;">
<span style="font-weight: normal;"><a href="http://www.comp-psyche.com/2014/07/good-programming-practices.html#good programming practices string" name="good programming practices string">GOOD PROGRAMMING PRACTICES - STRING</a></span></h2>
<div>
<div>
<a href="http://www.comp-psyche.com/2014/07/good-programming-practices.html#good programming practices">Back to Good Programming Practices</a></div>
<div>
<ul></ul>
</div>
</div>
<div>
<ul style="text-align: left;">
<li>When storing a string of characters in a character array be sure that the array is large enough to hold the largest string that will be stored.</li>
<li>Familiarize yourself with the various predefined string function. This helps in achieving task easily.</li>
<li>When using functions from the string-handling library, include the <string.h> header.</li>
</ul>
</div>
<h2 style="text-align: left;">
<span style="font-weight: normal;"><a href="http://www.comp-psyche.com/2014/07/good-programming-practices.html#good programming practices pointers" name="good programming practices pointers">GOOD PROGRAMMING PRACTICES - POINTERS</a></span></h2>
</div>
<div>
<div>
<a href="http://www.comp-psyche.com/2014/07/good-programming-practices.html#good programming practices">Back to Good Programming Practices</a></div>
<div>
<ul></ul>
</div>
</div>
<div>
<br />
<ul style="text-align: left;">
<li>Its preferable to include the letters Ptr in pointer variable names to make it clear that these variables are pointer and thus need to be handled appropriately.</li>
<li>Initialize pointer to prevent unexpected result.</li>
<li>If a variable does not change in the body of a function to which it is passed, the variable should be declared const to ensure that it is not accidentally modified.</li>
<li>Pass large objects such as structures using pointers to constant data to obtain the performance benefits of pass-by-reference.</li>
</ul>
<div>
<h2 style="text-align: left;">
<span style="font-weight: normal;"><a href="http://www.comp-psyche.com/2014/07/good-programming-practices.html#good programming practices structure and union" name="good programming practices structure and union">GOOD PROGRAMMING PRACTICES - STRUCTURE AND UNION</a></span></h2>
<div>
<div>
<a href="http://www.comp-psyche.com/2014/07/good-programming-practices.html#good programming practices">Back to Good Programming Practices</a></div>
<div>
<ul></ul>
</div>
</div>
<div>
<ul style="text-align: left;">
<li>Always provide a structure tag name when creating structure type. The structure type name is convenient for declaring new variables of the structure type later in the program.</li>
<li>Do not use spaces around '->' and '.' operators. Omitting spaces helps emphasize that the expressions the operators are contained in are essentially single variable names.</li>
<li>Passing structure by reference is more efficient than passing structure by value.</li>
<li>Use typedef to help make a program more protable.</li>
<li>Capitalize the first letter of the typedef names to emphasize that they are synonyms for other types names.</li>
<li>Using typedef can help make a program more readable and maintainable.</li>
</ul>
</div>
<br /></div>
</div>
<div>
<span style="color: yellow;">More Informative Posts : </span><br />
<br />
<ul style="text-align: left;">
<li><a href="http://www.comp-psyche.com/2013/11/common-programming-error-complete-list.html">Common Programming Errors</a></li>
<li><a href="http://www.comp-psyche.com/2014/01/c-programs.html">C Programs</a></li>
<li><a href="http://www.comp-psyche.com/2014/03/best-c-compiler-for-windows.html">Best C Compiler for Windows</a></li>
<li><a href="http://www.comp-psyche.com/2014/03/c-programming-in-linux.html">C Programming in Linux</a></li>
</ul>
</div>
</div>
Mantu Kumarhttp://www.blogger.com/profile/02897308282659594376noreply@blogger.com0tag:blogger.com,1999:blog-8285804830535272268.post-19909260556712867102014-07-11T01:39:00.000-07:002015-02-14T04:54:38.531-08:00C Programming In Linux<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="color: lime;">C Programming in Linux :</span> In this tutorial we are going to study how to write, compile and run c program in Linux. Linux <span style="color: lime;">Wall command</span> and <span style="color: lime;">make command</span> is also explained.<br />
<br />
<h2 style="text-align: left;">
<a href="http://www.comp-psyche.com/2014/03/c-programming-in-linux.html#C%20Programming%20In%20Linux" name="C Programming In Linux">Contents</a></h2>
<div>
<ul style="text-align: left;">
<li><a href="http://www.comp-psyche.com/2014/03/c-programming-in-linux.html#How%20To%20Write%20C%20Program%20In%20Linux" itemprop="url">Writing C Program In Linux</a></li>
<li><a href="http://www.comp-psyche.com/2014/03/c-programming-in-linux.html#How%20To%20Compile%20C%20Program%20In%20Linux" itemprop="url">Compiling C Program In Linux</a></li>
<li><a href="http://www.comp-psyche.com/2014/03/c-programming-in-linux.html#Linux%20Make%20Command" itemprop="url">Linux Make Command</a></li>
<li><a href="http://www.comp-psyche.com/2014/03/c-programming-in-linux.html#Linux%20Wall%20Command">Linux Wall Command</a></li>
<li><a href="http://www.comp-psyche.com/2014/03/c-programming-in-linux.html#How%20To%20Run%20C%20Program%20In%20Linux" itemprop="url">Running C Program In Linux</a></li>
<li><a href="http://www.comp-psyche.com/2014/03/c-programming-in-linux.html#feel" itemprop="url">How Do You Feel</a></li>
<li><a href="http://www.comp-psyche.com/2014/03/c-programming-in-linux.html#post" itemprop="url">More informative posts</a></li>
</ul>
</div>
<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<h2 style="text-align: left;">
<a href="http://www.comp-psyche.com/2014/03/c-programming-in-linux.html#How%20To%20Write%20C%20Program%20In%20Linux" name="How To Write C Program In Linux" style="font-weight: normal;"><span style="color: yellow;">HOW TO WRITE C PROGRAM IN LINUX</span></a></h2>
<a href="http://www.comp-psyche.com/2014/03/c-programming-in-linux.html#C%20Programming%20In%20Linux" target="">Back to content</a><br />
<br />
<div style="text-align: justify;">
A <span style="color: lime;">c program</span> is written in a text editor and is saved with <span style="color: lime;">".c"</span> extension. <span style="color: lime;">".c"</span> helps Unix or Linux OS(operating system) to identify that it is a <span style="color: lime;">C program.</span></div>
<div style="text-align: justify;">
I am assuming that all of you can have an access to a text editor and you know how to write in it and save it.</div>
<div style="text-align: justify;">
<br /></div>
Lets write our first c program :<br />
<br />
<span style="color: lime;">#include<stdio.h></span><br />
<span style="color: lime;">int main()</span><br />
<span style="color: lime;">{</span><br />
<span style="color: lime;"> printf("Yepeeeeeee this is my first C program\n"); // Displays the string as output</span><br />
<span style="color: lime;"> return 0; // tell the OS that the program exited without errors</span><br />
<span style="color: lime;">}</span><br />
<br />
Type the above code in any editor and save it with <span style="color: lime;">".c"</span> extension say <span style="color: lime;">"firstprogram.c"</span><br />
<span style="color: lime;"><br />
</span> <br />
<h3 style="text-align: left;">
<span style="font-weight: normal;"><span style="color: yellow;">Explanation :</span></span></h3>
<div style="text-align: justify;">
The execution of a C program starts with <span style="color: lime;">main()</span> function.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
<span style="color: lime;">// ( Double slash )</span> is a single line comment and is ignored by the compiler. It is used by the programmer to explain the working of the programs. so that other programmer who reads the program written by him would understand what the program is exactly doing.</div>
<div style="text-align: justify;">
<br /></div>
<span style="color: lime;">/*</span><br />
<span style="color: lime;"><br />
</span> <span style="color: lime;">Written anything</span><br />
<span style="color: lime;">.......</span><br />
<span style="color: lime;"><br />
</span> <span style="color: lime;">*/</span><br />
<br />
<div style="text-align: justify;">
The above syntax is for multiline comment i.e any text written in between is ignored by the compiler.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
Now what does first line <span style="color: lime;">#include<stdio.h></span> mean :</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
The first line may be confusing, but it’s just a C syntax that tells the compiler to include headers for a standard<span style="color: lime;"> input/output (I/O)</span> library named <span style="color: lime;">"stdio.h"</span>. This header file is added to the program when it is compiled. It is located at <span style="color: lime;">/usr/include/stdio.h</span> and it defines several constants and function prototypes for corresponding functions in the standard<span style="color: lime;"> I/O library</span>. Since the <span style="color: lime;">main()</span> function uses the <span style="color: lime;">printf()</span> function from the standard I/O library, a<span style="color: lime;"> function prototype</span> is needed for <span style="color: lime;">printf()</span> before it can be used. This function prototype (along with many others) is included in the <span style="color: lime;">"stdio.h"</span> header file. A lot of the power of C comes from its extensibility and libraries.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
In <span style="color: lime;"> printf("Yepeeeeeee this is my first C program\n") </span>we have used <span style="color: lime;">"\n"</span> this is nothing but a <span style="color: lime;">escape sequence</span> and is known as <span style="color: lime;">newline character</span> and it causes the cursor to move to the start of the next line.</div>
<div style="text-align: justify;">
<br /></div>
<div style="text-align: justify;">
You can read more about escape sequence from : <a href="http://www.comp-psyche.com/2013/06/escape-sequence-and-formatted-output.html" target="_blank">ESCAPE SEQUENCE</a></div>
<br />
<h2 style="text-align: left;">
<a href="http://www.comp-psyche.com/2014/03/c-programming-in-linux.html#How%20To%20Compile%20C%20Program%20In%20Linux" name="How To Compile C Program In Linux"><span style="color: yellow; font-weight: normal;">HOW TO COMPILE C PROGRAM IN LINUX</span></a></h2>
<a href="http://www.comp-psyche.com/2014/03/c-programming-in-linux.html#C%20Programming%20In%20Linux" target="">Back to content</a><br />
<br />
<div style="text-align: justify;">
Linux has a compiler named CC ( The C Compiler ) for compiling the C programs written in a text editor. Most unix or linux version also contain The GNU Compiler Collection (GCC) which is a free C compiler that translates C into machine language that a processor can understand.A compiler converts a high-level language into machine language.</div>
<br />
<h3 style="text-align: left;">
<span style="font-weight: normal;"><span style="color: yellow;">How to compile C program in Linux:</span></span></h3>
<div>
<span style="font-weight: normal;"><span style="color: yellow;"><br />
</span></span></div>
<div style="text-align: justify;">
Note : The followed command should be issued carefully in terminal and keep in mind of the directory in which you are working. i.e if you have saved your file in media directory then in terminal you should type cd /media to go to that directory and then issue the following command. If you launch terminal from your taskbar or menu then the working directory is by default /home/username. It would be a better idea to open your terminal from the same directory in which your file is saved.</div>
<br />
For compiling a C program you can simply type :<br />
<br />
<span style="color: lime;">cc firstprogram.c or</span><br />
<span style="color: lime;">gcc firstprogram.c</span><br />
<br />
Now what does the above two statement does :<br />
<br />
This will try to compile <span style="color: lime;">firstprogram.c</span> and if successful will produce a runnable file called "a.out" which is a default name. If you want to give the runnable file a better name you can type :<br />
<br />
<span style="color: lime;">cc firstprogram.c -o firstprogram ( or cc firstprogram.c -o testprog.out )</span><br />
<span style="color: lime;">gcc firstprogram.c -o firstprogram ( or gcc firstprogram.c -o firstprogram.out )</span><br />
<br />
<div style="text-align: justify;">
This will compile <span style="color: lime;">firstprogram.c</span> and create a runnable file <span style="color: lime;">firstprogram</span></div>
<div style="text-align: justify;">
If you notice we have excluded the extension ".out" but not to worry with extension or without extension your runnable or executable file will work.</div>
<div style="text-align: justify;">
<br /></div>
<h2 style="text-align: left;">
<a href="http://www.comp-psyche.com/2014/03/c-programming-in-linux.html#Linux%20Make%20Command" name="Linux Make Command" style="font-weight: normal;"><span style="color: yellow;">LINUX MAKE COMMAND</span></a></h2>
<a href="http://www.comp-psyche.com/2014/03/c-programming-in-linux.html#C%20Programming%20In%20Linux">Back to content</a><br />
<br />
<div style="text-align: justify;">
UNIX or Linux also includes a very useful program called <span style="color: lime;">"make"</span>. Make allows very complicated programs to be compiled quickly, by reference to a configuration file (usually called Makefile). If your C program is a single file, you can usually use <span style="color: lime;">"make"</span> by simply typing :</div>
<br />
<span style="color: lime;">make firstprogram</span><br />
<br />
<div style="text-align: justify;">
This will compile <span style="color: lime;">firstprogram.c</span> and put the executable code in <span style="color: lime;">firstprogram</span></div>
<div style="text-align: justify;">
<span style="color: lime;">"make"</span> does the same task what <span style="color: lime;">cc firstprogram.c -o firstprogram</span> or <span style="color: lime;">gcc firstprogram.c -o firstprogram</span> does.</div>
<br />
<h2 style="text-align: left;">
<span style="font-weight: normal;"><a href="http://www.comp-psyche.com/2014/03/c-programming-in-linux.html#Linux%20Wall%20Command" name="Linux Wall Command"><span style="color: yellow;">LINUX WALL COMMAND</span></a></span></h2>
<a href="http://www.comp-psyche.com/2014/03/c-programming-in-linux.html#C%20Programming%20In%20Linux" target="">Back to content</a><br />
<br />
The <span style="color: lime;">-Wall option</span> causes the compiler to warn you about legal but dubious code constructs, and will help you catch a lot of bugs very early. To use <span style="color: lime;">-Wall option</span> you can type :<br />
<br />
<span style="color: lime;">gcc -Wall -c firstprogram.c or</span><br />
<span style="color: lime;">cc -Wall -c firstprogram.c</span><br />
<br />
If you want to be even more specific you can type :<br />
<br />
<span style="color: lime;">gcc -Wall -Wstrict-prototypes -ansi -pedantic -c firstprogram.c or</span><br />
<span style="color: lime;">cc -Wall -Wstrict-prototypes -ansi -pedantic -c firstprogram.c</span><br />
<br />
The <span style="color: lime;">-Wstrict-prototypes</span> option means that the compiler will warn you if you haven't written correct prototypes for all your functions. The <span style="color: lime;">-ansi</span> and <span style="color: lime;">-pedantic</span> options cause the compiler to warn about any non-portable construct (i.e constructs that may be legal in gcc but not in other standard C compilers. We should try to avoid such features).<br />
<br />
Note - Running the commands :<br />
<br />
<span style="color: lime;">gcc -Wall -c firstprogram.c or</span><br />
<span style="color: lime;">cc -Wall -c firstprogram.c</span><br />
<span style="color: lime;"><br />
</span> <span style="color: lime;">gcc -Wall -Wstrict-prototypes -ansi -pedantic -c firstprogram.c or</span><br />
<span style="color: lime;">cc -Wall -Wstrict-prototypes -ansi -pedantic -c firstprogram.c</span><br />
<br />
produces object file named <span style="color: lime;">firstprogram.o</span><br />
<br />
So the next step is to make a runnable or executable file from the object file. To make an runnable or executale file type :<br />
<br />
<span style="color: lime;">gcc firstprogram.o -o firstprogram or </span><br />
<span style="color: lime;">cc firstprogram.o -o firstprogram</span><br />
<br />
This produces an executable file named firstprogram<br />
<br />
To create an executable file directly without producing an object file. You can type :<br />
<br />
<span style="color: lime;">gcc -g -Wall -o firstprogram firstprogram.c or</span><br />
<span style="color: lime;">cc -g -Wall -o firstprogram firstprogram.c</span><br />
<br />
This produces an executable file named <span style="color: lime;">firstprogram</span> without producing an object file <span style="color: lime;">firstprogram.o</span><br />
<span style="color: lime;"><br />
</span> <br />
<h2 style="text-align: left;">
<a href="http://www.comp-psyche.com/2014/03/c-programming-in-linux.html#How%20To%20Run%20C%20Program%20In%20Linux" name="How To Run C Program In Linux"><span style="color: yellow; font-weight: normal;">HOW TO RUN C PROGRAM IN LINUX</span></a></h2>
<a href="http://www.comp-psyche.com/2014/03/c-programming-in-linux.html#C%20Programming%20In%20Linux">Back to content</a><br />
<br />
<div style="text-align: justify;">
Now that we are done with writing and compiling our code. Lets run it. You can run your code by simply typing the runnable or executable file name i.e type :</div>
<br />
<span style="color: lime;">firstprogram</span><br />
<span style="text-align: justify;"><br />
</span> <span style="text-align: justify;">If in case the above command show error and does not execute your runnable file then you can type :</span><br />
<br />
<span style="color: lime;">./firstprogram</span><br />
<br />
This tells the compiler that the executable file is in the current working directory.<br />
<br />
<h2 style="text-align: left;">
<a href="http://www.comp-psyche.com/2014/03/c-programming-in-linux.html#feel" name="feel" style="font-weight: normal;"><span style="color: yellow;">HOW DO YOU FEEL</span></a></h2>
<a href="http://www.comp-psyche.com/2014/03/c-programming-in-linux.html#C%20Programming%20In%20Linux">Back to content</a><br />
<br />
<div style="text-align: justify;">
Now that you have executed your first C program. Tell us how do you feel by simply dropping a comment in the comment box.</div>
<br />
<a href="http://www.comp-psyche.com/2014/02/compiling-running-program-in-linux.html#post" name="post"><span style="color: yellow;">More Informative post :</span></a><br />
<ul style="text-align: left;">
<li><span style="color: yellow;"><a href="http://www.comp-psyche.com/2013/11/learn-C.html" itemprop="url">Learn C</a></span></li>
<li><span style="color: yellow;"><a href="http://www.comp-psyche.com/2014/01/c-programs.html" itemprop="url">C Programs</a></span></li>
<li><span style="color: yellow;"><a href="http://www.comp-psyche.com/2013/11/common-programming-error-complete-list.html" itemprop="url">Common Programming Errors</a></span></li>
</ul>
</div>
</div>
Mantu Kumarhttp://www.blogger.com/profile/02897308282659594376noreply@blogger.com0tag:blogger.com,1999:blog-8285804830535272268.post-13726543984115159172014-06-15T03:10:00.002-07:002020-11-17T05:18:54.643-08:00Quick Sort Program In C<div dir="ltr" style="text-align: left;" trbidi="on">
<h2 style="text-align: left;">
<span style="font-weight: normal;"><span style="color: yellow;"><a href="http://www.comp-psyche.com/2014/06/quick-sort-program-in-c.html#Quick Sort" name="Quick Sort">Quick Sort</a></span></span></h2>
<div>
<ul style="text-align: left;">
<li><a href="http://www.comp-psyche.com/2014/06/quick-sort-program-in-c.html#Quick Sort In C">Quick Sort In C</a></li>
<li><a href="http://www.comp-psyche.com/2014/06/quick-sort-program-in-c.html#Quick Sort Algorithm">Algorithm For Quick Sort</a></li>
<li><a href="http://www.comp-psyche.com/2014/06/quick-sort-program-in-c.html#Quick Sort Program In C">Quick Sort Program In C</a></li>
<li><a href="http://www.comp-psyche.com/2014/06/quick-sort-program-in-c.html#Quick Sort Program Output">Quick Sort Program Output</a></li>
</ul>
</div>
<h2 style="text-align: left;">
</h2>
<h2 style="text-align: left;">
<span style="color: yellow; font-weight: normal;"><a href="http://www.comp-psyche.com/2014/06/quick-sort-program-in-c.html#Quick Sort In C" name="Quick Sort In C">QUICK SORT IN C</a></span></h2>
<a href="http://www.comp-psyche.com/2014/06/quick-sort-program-in-c.html#Quick Sort">Back to Quick Sort</a><br />
<br />
<span style="color: lime;">Quick Sort</span> is another sorting algorithm that is based on divide and conquer approach. Unlike merge sort that divides input elements according to their position in array, quick sort divides input element according to their values. Here is a three-step divide and conquer process for sorting a typical sub-array.<br />
<br />Need Python Homework Help: <a href="https://letstacle.com/help-with-python-homework">Get Python Homework Help from Epert</a></div><div dir="ltr" style="text-align: left;" trbidi="on"><br />
<div style="text-align: left;"><span style="color: lime;"><b>Divide </b>:</span><span style="font-weight: normal;"> Partition or rearrange the array <span style="color: lime;">a[p . . r]</span> into two sub-arrays <span style="color: lime;">a[ p . . q-1 ]</span> and <span style="color: lime;">a[q+1 . . r]</span> such that <span style="color: lime;">a[ p . . q-1 ] <= a[q] <= a[q+1 . . r] . </span>Compute the <span style="color: lime;">index q</span> as part of this partition procedure. Here <span style="color: lime;">a[q]</span> is called the pivot element.</span></div>
<br />
<div style="text-align: left;"><span style="color: lime;"><b>Conquer </b>:</span> <span style="font-weight: normal;">Sort the two sub-arrays <span style="color: lime;">a[ p . . q-1 ] </span>and <span style="color: lime;">a[q+1 . . r] </span> by recursive calls to quick sort.</span></div>
<br />
<div style="text-align: left;"><span style="color: lime;"><b>Combine </b>:</span> <span style="font-weight: normal;">Because the sub-arrays are already sorted, no work is needed to combine them : the entire array <span style="color: lime;">a[ p . . r ]</span> is now sorted.</span></div>
<div>
<span style="font-weight: normal;"><br />
</span></div>
<div>
<span style="font-weight: normal;">Lets understand Quick Sort with the help of an example : </span><br />
<span style="font-weight: normal;"><br />
</span> Array Elements ( List ) : <span style="color: lime;">2 8 7 1 3 5 6 4</span><br />
<span style="color: lime;"><br />
</span> Steps :<br />
<br />
<ul style="text-align: left;">
<li style="text-align: justify;">Select the pivot element (<span style="color: lime;"> 4</span> in this case )</li>
<li style="text-align: justify;">Rearrange elements such that elements before pivot element are less than it and element after pivot element are greater than it. This arrangement of elements in accordance with the pivot element is called <span style="color: lime;">partition operation.</span></li>
<li style="text-align: justify;">Sort the sub-array recursively. </li>
</ul>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="http://4.bp.blogspot.com/-BRSv3TNTZEw/VD34kuLh2rI/AAAAAAAAAL4/NLsvaW0gzaY/s1600/quick%2Bsort.png" style="margin-left: auto; margin-right: auto;"><img alt="Steps for Quick Sort" border="0" height="320" src="https://4.bp.blogspot.com/-BRSv3TNTZEw/VD34kuLh2rI/AAAAAAAAAL4/NLsvaW0gzaY/s1600/quick%2Bsort.png" title="Quick Sort Algorithm And Program In C" width="169" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="color: lime;">Steps for Quick Sort</span></td></tr>
</tbody></table>
<div style="text-align: justify;">
<ul>
<li>The above image shows the partition of Array elements ( Initial list ).</li>
<li>Similarly the two sub-array before and after pivot element are partitioned.</li>
<li>The complete steps of quick sort is shown below.</li>
</ul>
<div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="http://1.bp.blogspot.com/-Y38rz6vSWIg/VD4fikqsXmI/AAAAAAAAAMQ/Xh4ri6YPjoE/s1600/quick%2Bsort%2Bstep.jpg" style="margin-left: auto; margin-right: auto;"><img alt="Quick Sort Program In C" border="0" height="640" src="https://1.bp.blogspot.com/-Y38rz6vSWIg/VD4fikqsXmI/AAAAAAAAAMQ/Xh4ri6YPjoE/s1600/quick%2Bsort%2Bstep.jpg" title="Quick Sort Algorithm And Program In C" width="145" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="color: lime;">Quick Sort </span></td></tr>
</tbody></table>
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div>
<br /></div>
</div>
</div>
<h2 style="text-align: left;">
<span style="color: yellow; font-weight: normal;"><a href="http://www.comp-psyche.com/2014/06/quick-sort-program-in-c.html#Quick Sort Algorithm" name="Quick Sort Algorithm">QUICK SORT ALGORITHM</a></span></h2>
<div>
<a href="http://www.comp-psyche.com/2014/06/quick-sort-program-in-c.html#Quick Sort">Back to Quick Sort</a></div>
<div>
<br /></div>
<div class="mokcode">
<pre><span style="color: blue;">// Algorithm for Quick Sort</span></pre>
<pre><span style="color: blue;">
</span></pre>
<pre><span style="color: blue;">QUICKSORT(a, p, r)
if p<r
q = PARTITION(a, p, r)
QUICKSORT(a, p, q-1)</span></pre>
<pre><span style="color: blue;"> </span><span style="color: blue;">QUICKSORT(a, q+1, r)</span></pre>
</div>
<span style="color: #660000;"><br /></span>
<span style="color: #660000;">Partitioning the array :</span><br />
<br />
<div class="mokcode">
<pre><span style="color: blue;">PARTITION(a, p, r)
x=a[r]
i=p-1
</span></pre>
<pre><span style="color: blue;"> for j=p to r-1
if(a[j]<=x)
i=i+1
swap a[i] with a[j]</span></pre>
<pre><span style="color: blue;"> end loop</span></pre>
<pre><span style="color: blue;">
swap a[i+1] with a[r]</span></pre>
<pre><span style="color: blue;"> return i+1</span></pre>
</div>
<div>
<span style="font-weight: normal;"><br />
</span></div>
<br />
<h2 style="text-align: left;">
<span style="font-weight: normal;"><span style="color: yellow;"><a href="http://www.comp-psyche.com/2014/06/quick-sort-program-in-c.html#Quick Sort Program In C" name="Quick Sort Program In C">QUICK SORT PROGRAM IN C</a></span></span></h2>
<div>
<span style="font-weight: normal;"><a href="http://www.comp-psyche.com/2014/06/quick-sort-program-in-c.html#Quick Sort">Back to Quick Sort</a></span></div>
<div>
<br /></div>
<div class="mokcode">
<pre><span style="color: blue;">//Quick sort program ( code ) in c
#include<stdio.h>
void quicksort(int a[],int p, int r);
int partition(int a[],int p, int r);
int main()
{
int a[20],i,n;
printf("Enter number of elements in array : ");
scanf("%d",&n);
// Inputting elements
for(i=0;i<n;i++)
{
printf("Enter number %d: ",i+1);
scanf("%d",&a[i]);
}
// Displaying Elements before quick sort
printf("Items in the array are : ");
for(i=0;i<n;i++)
{
printf("%d ",a[i]);
}
//Applying quick sort
quicksort(a,0,n-1);
// Displaying elements after quick sort
printf("\nElements after quick sort : ");
for(i=0;i<n;i++)
{
printf("%d ",a[i]);
}
return 0;
}
void quicksort(int a[],int p, int r)
{
int q;
if(p<r)
{</span></pre>
<pre><span style="color: blue;"> // q - index at which pivot element lies
q=partition(a,p,r);</span></pre>
<pre><span style="color: blue;">
</span></pre>
<pre><span style="color: blue;"> // Sorting sub-array recursively
quicksort(a,p,q-1);
quicksort(a,q+1,r);
}
}
int partition(int a[],int p, int r)
{
int temp;</span></pre>
<pre><span style="color: blue;"> </span><span style="color: blue;">int i=p-1;</span></pre>
<pre><span style="color: blue;"> int j;</span></pre>
<pre><span style="color: blue;">
</span></pre>
<pre><span style="color: blue;"> // pivot element around which partition is done
int x=a[r];</span></pre>
<pre><span style="color: blue;">
for(j=p;j<=r-1;j++)
{
if(a[j]<=x)
{
i=i+1;
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
temp=a[i+1];
a[i+1]=a[r];
a[r]=temp;
return (i+1);
}</span>
</pre>
</div>
<br />
<h2 style="text-align: left;">
<span style="font-weight: normal;"><a href="http://www.comp-psyche.com/2014/06/quick-sort-program-in-c.html#Quick Sort Program Output" name="Quick Sort Program Output">Quick Sort Program Output</a></span></h2>
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="http://2.bp.blogspot.com/-B7a4fzKM-qQ/VRXCDh3WXJI/AAAAAAAAAQo/KOt-Mt0G2cU/s1600/quick%2Bsort.png" style="clear: left; margin-bottom: 1em; margin-left: auto; margin-right: auto;"><img alt="Quick Sort Program In C With Output" border="0" src="https://2.bp.blogspot.com/-B7a4fzKM-qQ/VRXCDh3WXJI/AAAAAAAAAQo/KOt-Mt0G2cU/s1600/quick%2Bsort.png" title="Quick Sort Program In C" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="color: lime;">Quick Sort : Quick Sort Program Output</span></td></tr>
</tbody></table>
<br />
<span style="color: #660000;">More Informative Posts :</span><br />
<ul>
<li><a href="http://www.comp-psyche.com/2014/08/counting-sort-program-in-c.html">Counting Sort Program In C</a></li>
<li><a href="http://www.comp-psyche.com/2015/01/heap-sort-program-in-c.html">Heap Sort Program In C</a></li>
<li><a href="http://www.comp-psyche.com/2014/06/merge-sort-program-in-c.html">Merge Sort Program In C</a></li>
<li><a href="http://www.comp-psyche.com/2014/07/bubble-sort-program-in-c.html">Bubble Sort Program In C</a></li>
<li><a href="http://www.comp-psyche.com/2014/07/selection-sort-program-in-c.html">Selection Sort Program In C</a></li>
<li><a href="http://www.comp-psyche.com/2014/12/insertion-sort-algorithm-time-complexity-and-program-in-c.html">Insertion Sort Program In C</a></li>
<li>Shell sort Program In C</li>
<li>Radix Sort Program In C</li>
<li>Bucket Sort Program In C</li>
</ul>
<ul></ul>
</div>
Mantu Kumarhttp://www.blogger.com/profile/02897308282659594376noreply@blogger.com2tag:blogger.com,1999:blog-8285804830535272268.post-46394100909472059782014-06-12T00:55:00.001-07:002015-03-01T04:13:27.415-08:00Searching And Sorting In C<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="text-align: left;">
Other Searching and Sorting technique will be published soon.</div>
<h2 style="text-align: left;">
<span style="color: yellow; font-weight: normal;">SORTING</span></h2>
<div>
<ul style="text-align: left;">
<li><a href="http://www.comp-psyche.com/2014/07/bubble-sort-program-in-c.html">Bubble Sort</a></li>
<li><a href="http://www.comp-psyche.com/2014/06/quick-sort-program-in-c.html">Quick Sort</a></li>
<li><a href="http://www.comp-psyche.com/2014/07/selection-sort-program-in-c.html">Selection Sort</a></li>
<li><a href="http://www.comp-psyche.com/2014/12/insertion-sort-algorithm-time-complexity-and-program-in-c.html">Insertion Sort</a></li>
<li><a href="http://www.comp-psyche.com/2014/06/merge-sort-program-in-c.html" target="_blank">Merge Sort</a></li>
<li><a href="http://www.comp-psyche.com/2014/08/counting-sort-program-in-c.html">Counting Sort</a></li>
<li><a href="http://www.comp-psyche.com/2015/01/heap-sort-program-in-c.html">Heap Sort</a></li>
</ul>
<ul style="text-align: left;">
</ul>
</div>
</div>
Mantu Kumarhttp://www.blogger.com/profile/02897308282659594376noreply@blogger.com0tag:blogger.com,1999:blog-8285804830535272268.post-37800739628762845262014-06-12T00:49:00.000-07:002015-03-01T04:22:58.934-08:00Merge Sort Program In C<div dir="ltr" style="text-align: left;" trbidi="on">
Here I am providing you with <span style="color: lime;">Merge Sort</span> program in c.<br />
<div class="mokcode">
<pre><span style="color: blue;">#include<stdio.h>
void mergesort(int a[],int i, int j);
void merge(int a[],int p , int q, int r1);
int main()
{
int a[20],i,n,item;
printf("Enter number of elements in array : ");
scanf("%d",&n);
// Inputting elements
for(i=0;i<n;i++)
{
printf("Enter number %d: ",i+1);
scanf("%d",&a[i]);
}
// Displaying Elements before merge sort
printf("Items in the array are : ");
for(i=0;i<n;i++)
{
printf("%d ",a[i]);
}
//Applying merge sort
mergesort(a,0,n-1);
// Displaying elements after merge sort
printf("\nElements after merge sort : ");
for(i=0;i<n;i++)
{
printf("%d ",a[i]);
}
return 0;
}
void mergesort(int a[],int i, int j)
{
int mid;
if(i>=j)
return;
else
{
mid=(i+j)/2;
mergesort(a,i,mid);
mergesort(a,mid+1,j);
merge(a,i,mid,j);
}
}
void merge(int a[],int p , int q, int r)
{
int n1=q-p+1;
int n2=r-q;
int left[n1+1];
int right[n2+1];
int i=0;
int j=0;
int k=0;
for(i=0;i<n1;i++)
{
left[i]=a[p+i];
}
for(i=0;i<n2;i++)
{
right[i]=a[q+i+1];
}
left[n1]=9999;
right[n2]=9999;
i=0;
j=0;
for(k=p;k<=r;k++)
{
if(left[i]<right[j])
{
a[k]=left[i];
i++;
}
else
{
a[k]=right[j];
j++;
}
} </span></pre>
<pre><span style="color: blue;">} </span>
</pre>
</div>
<span style="color: yellow;">More Informative Posts :</span><br />
<ul>
<li><span style="color: yellow;"><a href="http://www.comp-psyche.com/2014/12/insertion-sort-algorithm-time-complexity-and-program-in-c.html">Insertion Sort Program In C</a></span></li>
<li><span style="color: yellow;"><a href="http://www.comp-psyche.com/2014/07/selection-sort-program-in-c.html">Selection Sort Program In C</a></span></li>
<li><span style="color: yellow;"><a href="http://www.comp-psyche.com/2014/06/quick-sort-program-in-c.html">Quick Sort Program In C</a></span></li>
<li><a href="http://www.comp-psyche.com/2014/07/counting-sort-program-in-c.html">Counting Sort Program In C</a></li>
<li><a href="http://www.comp-psyche.com/2014/07/bubble-sort-program-in-c.html">Bubble Sort Program In C</a></li>
<li><a href="http://www.comp-psyche.com/2015/01/heap-sort-program-in-c.html">Heap Sort Program In C</a></li>
<li>Bucket Sort Program In C</li>
<li>Shell Sort Program In C</li>
<li>Radix Sort Program In C</li>
</ul>
</div>
Mantu Kumarhttp://www.blogger.com/profile/02897308282659594376noreply@blogger.com0tag:blogger.com,1999:blog-8285804830535272268.post-51901261494277323412014-04-07T12:10:00.000-07:002014-09-26T06:37:53.754-07:00C PROGRAM TO FIND FIBONACCI SERIES<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<h2 style="text-align: left;">
<span style="font-weight: normal;"><span style="color: yellow;">WHAT IS FIBONACCI SERIES</span></span></h2>
<span style="color: yellow; text-align: justify;">Fibonacci series :</span><span style="color: lime; text-align: justify;"> Fibonacci series</span><span style="text-align: justify;"> is one in which the nth term is sum of (n-1)th term and (n-2)th term. The first two numbers of series are 0 and 1.</span><br />
For example: <span style="color: lime;">0 1 1 2 3 5 8 13 21</span> and so on<br />
<br />
Now we can write a c program to find <span style="color: lime;">fibonacci series </span>in the following ways :<br />
<ul style="text-align: left;">
<li><a href="http://www.comp-psyche.com/2014/04/write-c-program-to-find-fibonacci-series.html#C Program to find fibonacci series using loops">C Program to find fibonacci series using loops</a></li>
<li><a href="http://www.comp-psyche.com/2014/04/write-c-program-to-find-fibonacci-series.html#C Program to find fibonacci series using function">C Program to find fibonacci series using function</a></li>
<li><a href="http://www.comp-psyche.com/2014/04/write-c-program-to-find-fibonacci-series.html#C Program to find fibonacci series using recursion">C Program to find fibonacci series using recursion</a></li>
</ul>
<h2>
<span style="font-weight: normal;">C <a href="http://www.comp-psyche.com/2014/04/write-c-program-to-find-fibonacci-series.html#C Program to find fibonacci series using loops" name="C Program to find fibonacci series using loops">PROGRAM TO FIND FIBONACCI SERIES USING LOOPS</a></span></h2>
<div class="mokcode">
<pre><span style="color: blue;">//</span><span style="color: blue;">C PROGRAM TO PRINT FIBONACCI SERIES</span><span style="color: blue;"> USING LOOPS</span></pre>
<pre><span style="color: blue;">
#include<stdio.h>
</span><span style="color: blue;">
int main()
{
/* Declaring variable for n=number, f=first, s=second,
t=third number, i=to iterate the loop */
int n,f,s,t,i;
// Inputing number till where fibonacci series is to be printed
printf("Enter the number till which you want to print fibonacci series:");
scanf("%d",&n);
// Determining and printing fibonacii series
printf("Fibonacci Series: ");
f=0;
s=1;
printf("%d %d ",f,s);
for(i=3;i<=n;i++)
{
t=f+s;
printf("%d ",t);
f=s;
s=t;
}
</span><span style="color: blue;">
return 0;
}</span>
</pre>
<div>
<span style="color: blue;"><br />
</span></div>
</div>
</div>
<h2>
<span style="font-weight: normal;"><a href="http://www.comp-psyche.com/2014/04/write-c-program-to-find-fibonacci-series.html#C%20Program%20to%20find%20fibonacci%20series%20using%20function" name="C Program to find fibonacci series using function">C PROGRAM TO FIND FIBONACCI SERIES USING FUNCTION</a></span></h2>
</div>
<div class="mokcode">
<pre><span style="color: blue;">//C PROGRAM TO FIND FIBONACCI SERIES USING FUNCTION</span></pre>
<pre><span style="color: blue;">#include<stdio.h>
void fibonacci(int n);
int main()
{</span></pre>
<pre><span style="color: blue;"> int n;</span></pre>
<pre><span style="color: blue;">
// Inputing number till where fibonacci series is to be printed
printf("Enter the number till which you want to print fibonacci series:");
scanf("%d",&n);
fibonacci(n);
return 0;
}</span></pre>
<pre><span style="color: blue;">
void fibonacci(int n)
{
/* Declaring variable for f=first, s=second,
t=third number, i=to iterate the loop */
int f,s,t,i;
// Determining and printing fibonacii series
printf("Fibonacci Series: ");
f=0;
s=1;
printf("%d %d ",f,s);
for(i=3;i<=n;i++)
{
t=f+s;
printf("%d ",t);
f=s;
s=t;
}
}</span>
</pre>
</div>
<h2 style="text-align: left;">
<span style="font-weight: normal;"><a href="http://www.comp-psyche.com/2014/04/write-c-program-to-find-fibonacci-series.html#C%20Program%20to%20find%20fibonacci%20series%20using%20recursion" name="C Program to find fibonacci series using recursion">C PROGRAM TO FIND FIBONACCI SERIES USING RECURSION</a></span></h2>
<div class="mokcode">
<pre><span style="color: blue;">//WRITE A C PROGRAM TO FIND FIBONACCI SERIES USING RECURSION
#include<stdio.h>
int fibonacci(int n);
/* Declaring variable for f=first, s=second,
t=third number, i=to iterate the loop */
int f,s,t,i;
f=0;
s=1;
int main()
{
int n;
// Inputing number till where fibonacci series is to be printed
printf("Enter the number till which you want to print fibonacci series:");
scanf("%d",&n);
printf("Fibonacci Series: ");
printf("%d %d ",f,s);
fibonacci(n);
return 0;
}</span></pre>
<pre><span style="color: blue;">
int fibonacci(int n)
{
if(n==2)
{
return 0;
}
else
{
t=f+s;
printf("%d ",t);
f=s;
s=t;
fibonacci(n-1);
}
}</span>
</pre>
</div>
Note : You can write much better code than these. So view these example and try to program by yourself. Use your own logic. This would improve your programming skills.</div>
Mantu Kumarhttp://www.blogger.com/profile/02897308282659594376noreply@blogger.com0tag:blogger.com,1999:blog-8285804830535272268.post-66236779547387089652014-04-06T06:17:00.001-07:002015-05-24T05:45:48.195-07:00List Of C Programs<div dir="ltr" style="text-align: left;" trbidi="on">
Here I am providing with random list of c programs. For complete list of c programs you can visit :<a href="http://www.comp-psyche.com/2014/01/c-programs.html" target="_blank"> C PROGRAMS</a><br />
<br />
<ul style="text-align: left;">
<li><a href="http://www.comp-psyche.com/2014/03/write-a-c-program-to-reverse-a-string.html" target="_blank">C Program to reverse a string using strerev and without using strrev, using pointers and recursion</a></li>
<li><a href="http://www.comp-psyche.com/2014/04/write-c-program-to-find-fibonacci-series.html" target="_blank">C Program to find fibonacci series using loops, function and recursion</a></li>
<li><a href="http://www.comp-psyche.com/2014/09/c-program-to-add-subtract-multiply-diviide-two-numbers.html">C Program to add, subtract, multiply and divide two numbers</a></li>
<li><a href="http://www.comp-psyche.com/2015/05/leap-year-program-in-c.html">Leap Year Program In C using if-else and ternary</a></li>
<li><a href="http://www.comp-psyche.com/2015/02/pattern-programs-in-c.html">Pattern Programs In C</a></li>
</ul>
</div>
Mantu Kumarhttp://www.blogger.com/profile/02897308282659594376noreply@blogger.com0tag:blogger.com,1999:blog-8285804830535272268.post-54046357839970421522014-03-27T11:44:00.000-07:002017-09-16T06:34:28.860-07:00Reverse String In C / Reversing String In C<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<b>Reversing string in C</b> <b>/ Reverse String In C </b>seems to be a daunting task for the newbies but after reading this post you can easily <b>reverse string in C</b>.<br />
<br />
<h2 style="text-align: left;">
What Is Reverse String In C</h2>
Reverse string in c is basically taking input( i.e sentence ) from console and then display the sentence from last character to first character.<br />
<br />
The following <span style="color: lime;">Program</span> to reverse string in c accepts a string from the user and print the <span style="color: lime;">reverse string</span>. For example consider the following input from the user :<br />
<div>
<br /></div>
<div>
<span style="color: yellow;">Input String :</span> <span style="color: lime;">The site name is comp-psyche.com</span></div>
<div>
<span style="color: yellow;">Output String </span><span style="color: yellow;">:</span> <span style="color: lime;">moc.ehcysp-pmoc si eman etis ehT</span><br />
<span style="color: lime;"><br />
</span></div>
<div>
There are various ways to reverse string in c. You can either use string function to reverse string in c or you can reverse string in c without using c string function.</div>
<div>
<ul style="text-align: left;">
<li><a href="http://www.comp-psyche.com/2014/03/write-a-c-program-to-reverse-a-string.html#Reverse String Using String Function">Reverse string in C using function ( c strrev() )</a></li>
<li><a href="http://www.comp-psyche.com/2014/03/write-a-c-program-to-reverse-a-string.html#Reverse String Without Using String Function">Reverse String in C without using string function</a></li>
<li><a href="http://www.comp-psyche.com/2014/03/write-a-c-program-to-reverse-a-string.html#C Program To Reverse String Using recursion">Reverse String in C using Recursion</a></li>
<li><a href="http://www.comp-psyche.com/2014/03/write-a-c-program-to-reverse-a-string.html#C Program To Reverse String Using Pointer">Reverse String in C using Pointer</a></li>
</ul>
<div>
<br />
<h2 style="text-align: left;">
<a href="http://www.comp-psyche.com/2014/03/write-a-c-program-to-reverse-a-string.html#Reverse String Using String Function" name="Reverse String Using String Function" style="font-weight: normal;">REVERSE STRING IN C USING STRING FUNCTION ( c strrev() )</a></h2>
</div>
</div>
<div>
In the following program we will reverse string in c using string function streev()</div>
<div>
<br /></div>
<div>
<div>
<div>
<pre class="mokcode"><code>
#include<stdio.h>
#include<string.h>
int main()
{
// Declaring variable str=string
char str[50];
// Inputing string
printf("Enter any string : ");
gets(str);
// Printing string and reversed string
printf("String : %s\n",str);
printf("Reversed string : %s",strrev(str));
return 0;
}
</code></pre>
</div>
</div>
</div>
<br />
<h2 style="text-align: left;">
<a href="http://www.comp-psyche.com/2014/03/write-a-c-program-to-reverse-a-string.html#Reverse String Without Using String Function" name="Reverse String Without Using String Function" style="font-weight: normal;">REVERSE STRING IN C WITHOUT USING STRING FUNCTION</a></h2>
<div>
In the following program we will reverse string in c without using string function</div>
<div>
<br /></div>
<div>
<pre class="mokcode"><code>
int main()
{
// Declaring variable str=string, revstr[50]=reverse string
char str[50], revstr[50];
// Declaring variable i=to iterate loop, l=length
int i, j,l=0;
// Inputing string
printf("Enter any string : ");
gets(str);
// finding length
while(str[l]!='\0')
l++;
// Reversing string
j=0;
for(i=l-1;i>=0;i--)
{
revstr[j]=str[i];
j++;
}
revstr[j]='\0';
// Printing string and reversed string
printf("String : %s\n",str);
printf("Reversed string : %s",revstr);
}</code></pre>
</div>
<br />
<h2 style="text-align: left;">
<a href="http://www.comp-psyche.com/2014/03/write-a-c-program-to-reverse-a-string.html#C Program To Reverse String Using recursion" name="C Program To Reverse String Using recursion">REVERSE STRING IN C USING RECURSION</a></h2>
<div>
In the following program we will reverse string in c using recursion</div>
<div>
<br /></div>
<div>
<pre class="mokcode"><code>
// Write a c program to reverse a string using recursion
#include<stdio.h>
void reverse (int index, char *str );
int main (void)
{
char str[100];
printf ("Enter any string : ");
gets(str);
reverse (strlen(str) , str );
return 0;
}
void reverse (int index, char *str )
{
if (--index < 0 )
{
return ;
}
else
{
putchar ( *(str + index) ) ;
reverse (index, str) ;
}
}
</code>
</pre>
</div>
<h2 style="text-align: left;">
<a href="http://www.comp-psyche.com/2014/03/write-a-c-program-to-reverse-a-string.html#C Program To Reverse String Using Pointer" name="C Program To Reverse String Using Pointer">REVERSE STRING IN C USING POINTER</a></h2>
<div>
In the following program we will reverse string in c using pointer</div>
<div>
<br /></div>
<div>
<pre class="mokcode"><code>// Write a C program to reverse a string using pointer
#include<stdio.h>
int main()
{
// Declaring variable str = string and revstr = to store the revere string
char str[50];
char revstr[50];
char *strptr = str; // strptr - holds the first position address of str
char *revptr = revstr; // revptr - holds the first position address of revstr
int i=-1;
// Inputting string
printf("Enter any string : ");
gets(str);
// strptr is pointed to the last position address
while(*strptr)
{
strptr++;
i++;
}
// string stored in str is copied to revstr
while(i>=0)
{
strptr--;
*revptr = *strptr;
revptr++;
--i;
}
*revptr='\0';
printf("Reverse of string is : %s",revstr);
return 0;
}
</code></pre>
</div>
</div>
</div>
</div>
<br />
<br /></div>
Mantu Kumarhttp://www.blogger.com/profile/02897308282659594376noreply@blogger.com3tag:blogger.com,1999:blog-8285804830535272268.post-30075630504084741422014-03-27T03:09:00.000-07:002016-05-18T11:41:48.732-07:00Best C Compiler For Windows<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="text-align: left;">
<div style="text-align: justify;">
Here I am providing you with three best c compiler for windows - <span style="color: lime;">CodeBlock, Dev C and Turbo C </span>compiler.<span style="color: lime;"> CodeBlock</span> and <span style="color: lime;">Dev C</span> are actually <span style="color: lime;">IDEs (Integrated Development Environment or Interactive Development Environment)</span> whereas <span style="color: lime;">Turbo C </span>is a basic compiler. <span style="color: lime;">CodeBlock </span>which is provided here uses <span style="color: lime;">mingw compiler</span> whereas <span style="color: lime;">Dev C</span> uses <span style="color: lime;">gcc compiler.</span> Though many suggest not to use <span style="color: lime;">Turbo C</span> to learn c programming but as it is well documented and basic program runs without errors(pretty good). So I decided to keep it here.</div>
</div>
<span style="color: yellow;"><br />
</span><br />
<h2 style="text-align: left;">
<span style="color: yellow;"><span style="color: yellow;"><span style="color: yellow; font-weight: normal;"><a href="http://www.comp-psyche.com/2014/03/best-c-compiler-for-windows.html#c compiler" name="c compiler">BEST C COMPILER</a></span></span></span></h2>
<div>
<ul color="yellow" style="text-align: left;">
<li><span style="color: yellow;"><span style="color: yellow;"><a href="http://www.comp-psyche.com/2014/03/best-c-compiler-for-windows.html#C Programming with CodeBlocks">C Programming Using CodeBlocks</a></span></span></li>
<span style="color: yellow;"> <span style="color: yellow;"> <ul type="square">
<li><a href="http://www.comp-psyche.com/2014/03/best-c-compiler-for-windows.html#Download Code Blocks">Download Code Blocks</a></li>
<li><a href="http://www.comp-psyche.com/2014/03/best-c-compiler-for-windows.html#How To Install C Compiler Code Blocks">Install C Compiler</a></li>
<li><a href="http://www.comp-psyche.com/2014/03/best-c-compiler-for-windows.html#How To Write C Program In Code Blocks">How To Write C Program </a></li>
<li><a href="http://www.comp-psyche.com/2014/03/best-c-compiler-for-windows.html#Compile And Run C Program In Code Blocks">Compile And Run C Program</a></li>
</ul>
</span></span></ul>
<ul style="text-align: left;">
<li><span style="color: yellow;"><span style="color: yellow;"><a href="http://www.comp-psyche.com/2014/03/best-c-compiler-for-windows.html#C Programming with Dev-C++">C Programming Using Dev-C++</a></span></span></li>
<span style="color: yellow;"> <span style="color: yellow;"> <ul type="square">
<li><a href="http://www.comp-psyche.com/2014/03/best-c-compiler-for-windows.html#Download Dev C">Download Dev C</a></li>
<li><a href="http://www.comp-psyche.com/2014/03/best-c-compiler-for-windows.html#How To Install C Compiler Dev-C++">Install C Compiler</a></li>
<li><a href="http://www.comp-psyche.com/2014/03/best-c-compiler-for-windows.html#How To Write C Program In Dev-C++">How To Write C Program </a></li>
<li><a href="http://www.comp-psyche.com/2014/03/best-c-compiler-for-windows.html#How To Compile And Run C Program In Dev-C++">Compile And Run C Program</a></li>
</ul>
</span></span></ul>
<ul style="text-align: left;">
<li><span style="color: yellow;"><span style="color: yellow;"><a href="http://www.comp-psyche.com/2013/06/turbo-c-compiler.html" target="_blank">C Programming Using Turbo C</a></span></span></li>
<span style="color: yellow;"> <span style="color: yellow;">
<li><a href="http://www.comp-psyche.com/2014/03/best-c-compiler-for-windows.html#More Informative Posts">More Informative Posts</a></li>
</span></span></ul>
<div>
</div>
</div>
<br />
<h2>
<a href="http://www.comp-psyche.com/2014/03/best-c-compiler-for-windows.html#C Programming with CodeBlocks" name="C Programming with CodeBlocks" style="font-weight: normal;"><span style="color: yellow;">C PROGRAMMING USING CODEBLOCKS</span></a></h2>
</div>
<h2 style="text-align: left;">
<span style="color: yellow; font-weight: normal;"><a href="http://www.comp-psyche.com/2014/03/best-c-compiler-for-windows.html#Download Code Blocks" name="Download Code Blocks">DOWNLOAD CODE BLOCKS</a></span></h2>
<div>
<a href="http://www.comp-psyche.com/2014/03/best-c-compiler-for-windows.html#c compiler">Back To Best C Compiler</a></div>
<div>
<br /></div>
<div>
<div style="text-align: justify;">
Code Blocks is an <span style="color: lime;">integrated development environment or IDE</span> which uses <span style="color: lime;">mingw compiler or gcc compiler.</span> <span style="color: lime;">Code Blocks</span> provided here uses <span style="color: lime;">mingw compiler</span> which is one of the best c compiler for windows to compile and run c program. This version of Code Block runs in Windows 7 / Windows 8. For windows XP it is not tested.</div>
<br />
You can download free c compiler for windows from : <a href="https://docs.google.com/file/d/0B-ePnpipyxGyaktFVzdvNGRLNk0/edit" target="_blank">Download Code Blocks For Free</a><br />
<br /></div>
<h2 style="text-align: left;">
<a href="http://www.comp-psyche.com/2014/03/best-c-compiler-for-windows.html#How To Install C Compiler Code Blocks" name="How To Install C Compiler Code Blocks" style="font-weight: normal;"><span style="color: yellow;">HOW TO INSTALL CODE BLOCKS</span></a></h2>
</div>
<div style="text-align: justify;">
<a href="http://www.comp-psyche.com/2014/03/best-c-compiler-for-windows.html#c compiler">Back To Best C Compiler</a><br />
<br />
Now that you have downloaded <span style="color: lime;">CodeBlocks</span> the next thing which you should know is how to install <span style="color: lime;">CodeBlocks.</span> So follow these steps to install it :</div>
<ul style="text-align: left;">
<li>Open the folder where you have downloaded <span style="color: lime;">CodeBlocks.</span></li>
<li>Run the <span style="color: lime;">exe file.</span> A window pops up.<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="http://2.bp.blogspot.com/-NTY0kddlr4c/UyUw4h9MO0I/AAAAAAAAAG0/dHGx1IkETvE/s1600/code1.gif" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img alt="Best C Compiler - How to install CodeBlocks : First step" border="0" src="http://2.bp.blogspot.com/-NTY0kddlr4c/UyUw4h9MO0I/AAAAAAAAAG0/dHGx1IkETvE/s1600/code1.gif" height="312" title="Best c compiler for windows 7 / windows 8 for free" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="color: lime;">Best c compilers : First Step</span></td></tr>
</tbody></table>
<br />
</li>
<li>Click on next. Another window of <span style="color: lime;">License Agreement</span> pops up.<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="http://1.bp.blogspot.com/-YGjJTzIrSH4/UyUyO5g0xsI/AAAAAAAAAG8/XY0MxM1TLxI/s1600/code2.gif" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img alt="Best C Compiler - How to install CodeBlocks : License Agreement" border="0" src="http://1.bp.blogspot.com/-YGjJTzIrSH4/UyUyO5g0xsI/AAAAAAAAAG8/XY0MxM1TLxI/s1600/code2.gif" height="313" title="Best c compiler for windows 7 / windows 8 for free" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="color: lime;">Best c compilers : License Agreement</span></td></tr>
</tbody></table>
</li>
<li>Click on <span style="color: lime;">I Agree.</span> A window of <span style="color: lime;">Choose Components</span> pops up.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="http://2.bp.blogspot.com/-AWkbt6rPO-g/UyU99-jpT0I/AAAAAAAAAHg/ExEZPYNO1Vs/s1600/code3.gif" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img alt="Best C Compiler - How to install CodeBlocks : Choose Components" border="0" src="http://2.bp.blogspot.com/-AWkbt6rPO-g/UyU99-jpT0I/AAAAAAAAAHg/ExEZPYNO1Vs/s1600/code3.gif" height="312" title="Best c compiler for windows 7 / windows 8 for free" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="color: lime;">Best c compilers : Choose Components</span></td></tr>
</tbody></table>
<div class="separator" style="clear: both; text-align: center;">
</div>
</li>
<li>Click on <span style="color: lime;">Next. Install windows</span> pops up.<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="http://2.bp.blogspot.com/-DJfo5C0jHic/UyU10grK38I/AAAAAAAAAHQ/S4HAMvoqmVo/s1600/code4.gif" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img alt="Best C Compiler - How to install CodeBlocks : Install Location" border="0" src="http://2.bp.blogspot.com/-DJfo5C0jHic/UyU10grK38I/AAAAAAAAAHQ/S4HAMvoqmVo/s1600/code4.gif" height="312" title="Best c compiler for windows 7 / windows 8 for free" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="color: lime;">Best c compilers : Choose Install Location</span></td></tr>
</tbody></table>
</li>
<li style="text-align: justify;">Choose the location where you want <span style="color: lime;">CodeBlocks</span> to be installed and then click on <span style="color: lime;">Install.</span></li>
<li style="text-align: justify;">After Installation a windows pops up saying if you want to run <span style="color: lime;">CodeBlocks.</span> Click on <span style="color: lime;">yes</span> to run it.</li>
<li><div style="text-align: justify;">
A window of <span style="color: lime;">Installation Completion</span> pops up.</div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="http://3.bp.blogspot.com/-Qrv5DxDu-Y0/UyU-emgYydI/AAAAAAAAAHo/r_JyVGcE3pU/s1600/code5.gif" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img alt="Best C Compiler - How to install CodeBlocks : Installation Completion" border="0" src="http://3.bp.blogspot.com/-Qrv5DxDu-Y0/UyU-emgYydI/AAAAAAAAAHo/r_JyVGcE3pU/s1600/code5.gif" height="309" title="Best c compiler for windows 7 / windows 8 for free" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="color: lime;">Best c compilers : Installation complete</span></td></tr>
</tbody></table>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
</li>
<li>Click on <span style="color: lime;">Next.</span> Another windows pops up.<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="http://1.bp.blogspot.com/-QH9dk2sR-O0/UyU-tTOg7RI/AAAAAAAAAHw/cSTYqNEU1LE/s1600/code6.gif" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img alt="Best C Compiler - How to install CodeBlocks : Finish Window" border="0" src="http://1.bp.blogspot.com/-QH9dk2sR-O0/UyU-tTOg7RI/AAAAAAAAAHw/cSTYqNEU1LE/s1600/code6.gif" height="309" title="Best c compiler for windows 7 / windows 8 for free" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="color: lime;">Best c compilers : Finishing the setup</span></td></tr>
</tbody></table>
</li>
<li>Click on <span style="color: lime;">Finish.</span> </li>
</ul>
<br />
<h2 style="text-align: left;">
<a href="http://www.comp-psyche.com/2014/03/best-c-compiler-for-windows.html#How To Write C Program In Code Blocks" name="How To Write C Program In Code Blocks" style="font-weight: normal;"><span style="color: yellow;">HOW TO WRITE C PROGRAM</span></a></h2>
<a href="http://www.comp-psyche.com/2014/03/best-c-compiler-for-windows.html#c compiler">Back To C Compiler</a><br />
<br />
Now that you have finished Installing <span style="color: lime;">Code Blocks.</span> Lets write a simple <span style="color: lime;">c program.</span><br />
<br />
<span style="color: lime;">#include<stdio.h></span><br />
<span style="color: lime;">int main()</span><br />
<span style="color: lime;">{</span><br />
<span style="color: lime;"> printf("Congratulation.. You successfully run your first Program");</span><br />
<span style="color: lime;"> return 0;</span><br />
<span style="color: lime;">}</span><br />
<br />
Note : If you want to know what the syntax of the c program then you can read it from : <a href="http://www.comp-psyche.com/2013/06/component-of-c-program.html" target="_blank">Basic Component Of C Program</a><br />
<br />
<div style="text-align: justify;">
Now the question arises where should you write this code. Follow these steps to write your first <span style="color: lime;">C Program:</span> </div>
<ul style="text-align: left;">
<li>Click on <span style="color: lime;">File - New - File...</span><br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="http://2.bp.blogspot.com/-gGt9UacxnLo/UyVIcnVm-BI/AAAAAAAAAIA/itKSub0WF0w/s1600/write1.gif" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img alt="Best C Compiler - How to write C Program : File-New-File..." border="0" src="http://2.bp.blogspot.com/-gGt9UacxnLo/UyVIcnVm-BI/AAAAAAAAAIA/itKSub0WF0w/s1600/write1.gif" title="Best c compiler for windows 7 / windows 8 for free" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="color: lime;">Best c compilers : How to write c program</span></td></tr>
</tbody></table>
<br />
</li>
<li>Select <span style="color: lime;">C/C++ Source</span> and click on <span style="color: lime;">Go.</span><br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="http://3.bp.blogspot.com/-p6W_PtsFLFM/UyVIhAf4qnI/AAAAAAAAAII/BGzpR2A8vOk/s1600/write2.gif" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img alt="Best C Compiler - How to write C Program : C/C++ Source" border="0" src="http://3.bp.blogspot.com/-p6W_PtsFLFM/UyVIhAf4qnI/AAAAAAAAAII/BGzpR2A8vOk/s1600/write2.gif" height="240" title="Best c compiler for windows 7 / windows 8 for free" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="color: lime;">Best c compilers : How to write c program</span></td></tr>
</tbody></table>
<br />
</li>
<li>A window for <span style="color: lime;">Language Selection</span> pops up. Select <span style="color: lime;">C</span> and click on <span style="color: lime;">Next.</span><br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="http://3.bp.blogspot.com/-oTqLEv3k4-c/UyVIjKR_woI/AAAAAAAAAIQ/WR-fmH_UPCo/s1600/write3.gif" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img alt="Best C Compiler - How to write C Program : Language Selection" border="0" src="http://3.bp.blogspot.com/-oTqLEv3k4-c/UyVIjKR_woI/AAAAAAAAAIQ/WR-fmH_UPCo/s1600/write3.gif" height="292" title="Best c compiler for windows 7 / windows 8 for free" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="color: lime;">Best c compilers : How to write c program</span></td></tr>
</tbody></table>
<br />
</li>
<li>Enter the <span style="color: lime;">File Location with File Name</span> i.e where you want to save your file and click on <span style="color: lime;">Finish.</span><br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="http://2.bp.blogspot.com/-pvN5JkEXtRE/UyVIk1NaezI/AAAAAAAAAIY/v9WeF7ehO3k/s1600/write4.gif" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img alt="Best C Compiler - How to write C Program : File Location with File Name" border="0" src="http://2.bp.blogspot.com/-pvN5JkEXtRE/UyVIk1NaezI/AAAAAAAAAIY/v9WeF7ehO3k/s1600/write4.gif" height="364" title="Best c compiler for windows 7 / windows 8 for free" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="color: lime;">Best c compilers : How to write c program</span></td></tr>
</tbody></table>
<br />
</li>
</ul>
</div>
<h2 style="text-align: left;">
<a href="http://www.comp-psyche.com/2014/03/best-c-compiler-for-windows.html#Compile And Run C Program In Code Blocks" name="Compile And Run C Program In Code Blocks" style="font-weight: normal;"><span style="color: yellow;">HOW TO COMPILE AND RUN C PROGRAM</span></a></h2>
<a href="http://www.comp-psyche.com/2014/03/best-c-compiler-for-windows.html#c compiler">Back To Best C Compiler</a><br />
<br />
Congratulation You successfully wrote your first <span style="color: lime;">c program. </span>Now the next step is to <span style="color: lime;">Compile and Run</span> it. To <span style="color: lime;">Compile and Run</span> your first <span style="color: lime;">c program</span> follow these steps :<br />
<ul style="text-align: left;">
<li>To <span style="color: lime;">Compile c program</span> : Click on <span style="color: lime;">Build - Compile Current File. </span>You can also use shortcut key - <span style="color: lime;">Ctrl + Shift + F9</span></li>
<li>To <span style="color: lime;">Run c program</span> : Click on <span style="color: lime;">Build - Run.</span> You can also use shortcut key - <span style="color: lime;">Ctrl + F10</span></li>
<li>To <span style="color: lime;">Compile and run c program</span> at the same time : Click on <span style="color: lime;">Build - Build and Run.</span> you can achieve the same task by pressing <span style="color: lime;">F9</span></li>
</ul>
<div>
<br />
<h2 style="text-align: left;">
<a href="http://www.comp-psyche.com/2014/03/best-c-compiler-for-windows.html#C Programming with Dev-C++" name="C Programming with Dev-C++" style="font-weight: normal;"><span style="color: yellow;">C PROGRAMMING USING DEV C</span></a></h2>
</div>
<h2 style="text-align: left;">
<span style="font-weight: normal;"><span style="color: yellow;"><a href="http://www.comp-psyche.com/2014/03/best-c-compiler-for-windows.html#Download Dev C" name="Download Dev C">DOWNLOAD DEV C</a></span></span></h2>
<a href="http://www.comp-psyche.com/2014/03/best-c-compiler-for-windows.html#c compiler">Back To Best C Compiler</a><br />
<br />
<div style="text-align: justify;">
<span style="color: lime;">Dev C</span> is another <span style="color: lime;">integrated development environment or IDE.</span> Dev C provided here uses <span style="color: lime;">gcc compiler</span> which is one of the best c compiler for windows with good graphic and user friendly environment. You can easily write, compile and run a c program using <span style="color: lime;">Dev C. </span><span style="text-align: justify;">This version of Code Block runs in Windows 7 / Windows 8. For windows XP it is not tested.</span></div>
<br />
You can download free c<span style="color: lime;"> </span>compiler for windows from : <a href="https://docs.google.com/file/d/0B-ePnpipyxGyRi1vSXJTX0tOa3M/edit" target="_blank">Download Dev C For Free</a><br />
<br />
<h2 style="text-align: left;">
<a href="http://www.comp-psyche.com/2014/03/best-c-compiler-for-windows.html#How To Install C Compiler Dev-C++" name="How To Install C Compiler Dev-C++"><span style="color: yellow; font-weight: normal;">HOW TO INSTALL C COMPILER DEV C</span></a></h2>
</div>
<a href="http://www.comp-psyche.com/2014/03/best-c-compiler-for-windows.html#c compiler">Back To Best C Compiler</a><br />
<br />
Now that you have downloaded Dev C. Lets install it. Follow these step to install Dev C.<br />
<ul style="text-align: left;">
<li>Open the folder where you have downloaded <span style="color: lime;">Dev C..</span><br />
</li>
<li>Run the <span style="color: lime;">exe file.</span> <span style="color: lime;">Installer Language</span> windows pops up. Select language according to your preference and then click <span style="color: lime;">OK.</span><br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="http://3.bp.blogspot.com/-S6LOpqbWS7M/UyVZgxd1XfI/AAAAAAAAAIo/TZYSyG9zSHc/s1600/dev-install1.gif" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img alt="Best C Compiler - How to install Dev c/c++ : Installation language" border="0" src="http://3.bp.blogspot.com/-S6LOpqbWS7M/UyVZgxd1XfI/AAAAAAAAAIo/TZYSyG9zSHc/s1600/dev-install1.gif" title="Best c compiler for windows 7 / windows 8 for free" /></a></td></tr>
<tr><td class="tr-caption"><span style="color: lime;">Best c compilers : Installer Language</span></td></tr>
</tbody></table>
<br />
</li>
<li>Another window of <span style="color: lime;">License Agreement</span> pops up. Click <span style="color: lime;">I Agree.<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="http://2.bp.blogspot.com/-QUy-V1WqVzI/UyVZj0tcwlI/AAAAAAAAAIw/YqvrfQNZY4Q/s1600/dev-install2.gif" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img alt="Best C Compiler - How to install Dev C/C++ : License Agreement" border="0" src="http://2.bp.blogspot.com/-QUy-V1WqVzI/UyVZj0tcwlI/AAAAAAAAAIw/YqvrfQNZY4Q/s1600/dev-install2.gif" height="249" title="Best c compiler for windows 7 / windows 8 for free" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="color: lime;">Best c compilers : License Agreement</span></td></tr>
</tbody></table>
</span><br />
<br />
</li>
<li>Choose Components windows Appears. Click Next.<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="http://4.bp.blogspot.com/--AGUKt5HA60/UyVZlcucIVI/AAAAAAAAAI4/m3jKMKegw7E/s1600/dev-install3.gif" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img alt="Best C Compiler - How to install Dev C/C++ : Choose component" border="0" src="http://4.bp.blogspot.com/--AGUKt5HA60/UyVZlcucIVI/AAAAAAAAAI4/m3jKMKegw7E/s1600/dev-install3.gif" height="250" title="Best c compiler for windows 7 / windows 8 for free" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="color: lime;">Best c compilers : Choose Components</span></td></tr>
</tbody></table>
<br />
</li>
<li><span style="color: lime;">Install windows</span> pops up. <span style="text-align: justify;">Choose the location where you want <span style="color: lime;">Dev-C++</span></span><span style="text-align: justify;"> to be installed and then click on </span><span style="color: lime; text-align: justify;">Install.</span><br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="http://1.bp.blogspot.com/-UeXToDFkDDU/UyVZnXEeybI/AAAAAAAAAJA/t426OsuDO4o/s1600/dev-install4.gif" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img alt="Best C Compiler - How to install Dev C/C++ : Choose Install Location" border="0" src="http://1.bp.blogspot.com/-UeXToDFkDDU/UyVZnXEeybI/AAAAAAAAAJA/t426OsuDO4o/s1600/dev-install4.gif" height="252" title="Best c compiler for windows 7 / windows 8" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="color: lime;">Best c compilers : Choose Install Location</span></td></tr>
</tbody></table>
<br />
</li>
<li style="text-align: justify;"><span style="color: lime;">Installation Completion</span> windows pops up. <span style="color: lime;">Click on Finish.</span><br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="http://4.bp.blogspot.com/-YJKSG41T4X8/UyVZo-u92bI/AAAAAAAAAJI/Wb3mKzymNI4/s1600/dev-install5.gif" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img alt="Best C Compiler - How to install Dev C/C++ : Installation Completion" border="0" src="http://4.bp.blogspot.com/-YJKSG41T4X8/UyVZo-u92bI/AAAAAAAAAJI/Wb3mKzymNI4/s1600/dev-install5.gif" height="249" title="Best c compiler for windows 7 / windows 8 for free" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="color: lime;">Best c compilers : Finishing the setup</span></td></tr>
</tbody></table>
<br />
</li>
</ul>
<h2 style="text-align: left;">
<a href="http://www.comp-psyche.com/2014/03/best-c-compiler-for-windows.html#How To Write C Program In Dev-C++" name="How To Write C Program In Dev-C++"><span style="color: yellow; font-weight: normal;">HOW TO WRITE C PROGRAM</span></a></h2>
<a href="http://www.comp-psyche.com/2014/03/best-c-compiler-for-windows.html#c compiler">Back To Best C Compiler</a><br />
<br />
Now that you have finished Installing Dev C. Lets write a simple <span style="color: lime;">c program.</span><br />
<br />
<span style="color: lime;">#include<stdio.h></span><br />
<span style="color: lime;">int main()</span><br />
<span style="color: lime;">{</span><br />
<span style="color: lime;"> printf("Congratulation.. You successfully run your first Program");</span><br />
<span style="color: lime;"> return 0;</span><br />
<span style="color: lime;">}</span><br />
<span style="color: lime;"><br />
</span>Note : If you want to know about the syntax of c program then you can read it from : <a href="http://www.comp-psyche.com/2013/06/component-of-c-program.html" target="_blank">Basic Component Of C Program</a><br />
<br />
Now where should you write the above code. Follow these steps to write your first<span style="color: lime;"> c program :</span><br />
<ul style="text-align: left;">
<li>Click on <span style="color: lime;">File - New - Source File</span></li>
<li>An editor opens up. Write your c program and then save it with <span style="color: lime;">".c" extension.</span></li>
<li>To save c program : Click on <span style="color: lime;">File - Save As...</span></li>
<li>Give a name to your file and save it as <span style="color: lime;">C source files.</span><br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="http://4.bp.blogspot.com/-cP-b7Kq8x4Q/UyVfR_C6YPI/AAAAAAAAAJY/Q31bgdUPGcQ/s1600/dev-write1.gif" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img alt="Best C Complier - Saving c program in Dev C/C++" border="0" src="http://4.bp.blogspot.com/-cP-b7Kq8x4Q/UyVfR_C6YPI/AAAAAAAAAJY/Q31bgdUPGcQ/s1600/dev-write1.gif" height="226" title="Best c compiler for windows 7 / windows 8 for free" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="color: lime;">Best c compilers : How to write c program in Dev C/C++</span></td></tr>
</tbody></table>
<br />
</li>
</ul>
<h2>
<a href="http://www.comp-psyche.com/2014/03/best-c-compiler-for-windows.html#How To Compile And Run C Program In Dev-C++" name="How To Compile And Run C Program In Dev-C++"><span style="color: yellow; font-weight: normal;">HOW TO COMPILE AND RUN C PROGRAM</span></a></h2>
<a href="http://www.comp-psyche.com/2014/03/best-c-compiler-for-windows.html#c compiler">Back To Best C Compiler</a><br />
<br />
Lets <span style="color: lime;">Compile and Run</span> your first c program. Follow these steps to compile and run c program :<br />
<ul style="text-align: left;">
<li>To <span style="color: lime;">compile c program : </span>Click on <span style="color: lime;">Execute - Compile or F9</span></li>
<li>To <span style="color: lime;">Run c program :</span> Click on <span style="color: lime;">Execute - Run or F10</span></li>
<li>To <span style="color: lime;">Compile and Run :</span> Click on <span style="color: lime;">Execute - Compile & Run or F11</span></li>
</ul>
<div>
<br />
<a href="http://www.comp-psyche.com/2014/03/best-c-compiler-for-windows.html#More Informative Posts" name="More Informative Posts"><span style="color: yellow;">More Informative Posts :</span></a></div>
<div>
<ul>
<li><a href="http://www.comp-psyche.com/2014/03/c-programming-in-linux.html">C Programming In Linux</a></li>
<li><a href="http://www.comp-psyche.com/2014/01/c-programs.html">C Programs</a></li>
<li><a href="http://www.comp-psyche.com/2013/11/learn-C.html">Learn C</a></li>
<li><a href="http://www.comp-psyche.com/2013/11/common-programming-error-complete-list.html">Common Programming Errors</a></li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
Mantu Kumarhttp://www.blogger.com/profile/02897308282659594376noreply@blogger.com0tag:blogger.com,1999:blog-8285804830535272268.post-41208511310411482682014-02-02T03:06:00.000-08:002014-07-15T20:46:52.038-07:00C PROGRAM : PATTERN<div dir="ltr" style="text-align: left;" trbidi="on">
<title>C PROGRAMS : PATTERN</title><br />
<a href="http://www.comp-psyche.com/2014/02/c-programs-patterns3.html#p16" name="p16">16. Program to print the given pattern </a><br />
<div class="mokcode">
<pre><span style="color: blue;">// Program to print the given Pattern
/*
1
2 6
3 7 10
4 8 11 13
5 9 12 14 15 ... till n rows
*/
/*
For example :
For n=3
1
2 4
3 5 6
For n=6
1
2 7
3 8 12
4 9 13 16
5 10 14 17 19
6 11 15 18 20 21
*/
#include <stdio.h>
#include<conio.h> </span><span style="color: blue;">// Linux user - Remove this</span><span style="color: blue;">
</span><span style="color: blue;">
int main()
{
// Declaring variable i, j to iterate loop
int i, j;
// Declaring variable n = maximum rows
int n;
//Declaring variable k and num to help in generating "values"
int k, num=1;
// Inputting Number of rows
printf("Enter number of rows : ");
scanf("%d",&n);
// Running loop for rows
for (i=1; i<=n ; i++)
{
num=i;
k=n-1;
// printing values
for (j=1; j<=i; j++)
{
// %-4d = reserves 4 spaces for printing "value" to obtain clarity in pattern
printf("%-4d",num);
num=num+k;
k=k-1;
}
printf("\n");
}
getch(); </span><span style="color: blue;">// Linux user - Remove this</span><span style="color: blue;">
</span><span style="color: blue;">
return 0;
}</span>
</pre>
</div>
<br />
<a href="http://www.comp-psyche.com/2014/02/c-programs-patterns3.html#p17" name="p17">17. Program to print the given pattern </a><br />
<div class="mokcode">
<pre><span style="color: blue;">// Program to print pattern : Hollow Diamond
/*
******** ********
******* *******
****** ******
***** *****
**** ****
*** ***
** **
* *
* *
** **
*** ***
**** ****
***** *****
****** ******
******* *******
******** ********
LOGIC :
BREAKING IT UP : It has 2 parts
First part :
******** ********
******* *******
****** ******
***** *****
**** ****
*** ***
** **
* *
Which is further divided into :
First Sub Part :
********
*******
******
*****
****
***
**
*
Second Sub part :
********
*******
******
*****
****
***
**
*
And ofcourse the spaces before it.
Second Part :
* *
** **
*** ***
**** ****
***** *****
****** ******
******* *******
******** ********
Which is further divided into :
First Sub Part :
*
**
***
****
*****
******
*******
********
Second Sub Part :
*
**
***
****
*****
******
*******
********
And the spaces before it.
*/
#include<stdio.h>
#include<conio.h> </span><span style="color: blue;">// Linux user - Remove this</span><span style="color: blue;">
</span><span style="color: blue;">
int main()
{
// Declaring variable i, j, s to iterate loop
int i, j, s;
// Declaring ms = maximum space
int ms = 1;
// Running loop for rows for first part
for(i=1;i<=8;i++)
{
// Printing first Sub Part :
for(j=8;j>=i;j--)
{
printf("*");
}
// Printing spaces
for(s=1;s<=ms;s++)
{
printf(" ");
}
// Incresing spaces
ms=ms+2;
// Printing Second Sub Part :
for(j=8;j>=i;j--)
{
printf("*");
}
printf("\n");
}
printf("\n");
// Initialising ms = 15 i.e the maximum space
ms = 15;
// Running loop for Second Part
for(i=1;i<=8;i++)
{
// Printing first Sub Part :
for(j=1;j<=i;j++)
{
printf("*");
}
// Printing spaces
for(s=1;s<=ms;s++)
{
printf(" ");
}
// Reducing spaces
ms=ms-2;
// Printing Second Sub Part :
for(j=1;j<=i;j++)
{
printf("*");
}
printf("\n");
}
getch(); </span><span style="color: blue;">// Linux user - Remove this</span><span style="color: blue;">
</span><span style="color: blue;">
return 0;
}</span>
</pre>
</div>
<br />
<a href="http://www.comp-psyche.com/2014/02/c-programs-patterns3.html#p18" name="p18">18. Program to print the given pattern </a><br />
<div class="mokcode">
<pre><span style="color: blue;">/*
*
***
*****
*******
*********
*******
*****
***
*
BREAKING IT UP : The above pattern has two parts
First Part :
*
***
*****
*******
*********
Second Part :
*******
*****
***
*
*/
#include<stdio.h>
#include<conio.h> </span><span style="color: blue;">// Linux user - Remove this</span><span style="color: blue;">
</span><span style="color: blue;">
int main()
{
// Declaring variable i, j, s to iterate loop
int i,j,s;
// Declaring variable ms = maximum space
int ms = 5;
// Declaring variable to print "*" ( asterik )
int as = 1;
// Running loop for First part
for(i=1;i<=5;i++)
{
// Printing Space
for(s=1;s<=ms;s++)
{
printf(" ");
}
// Reducing spaces
ms--;
// Printing First Part
for(j=1;j<=as;j++)
{
printf("*");
}
// Increasing Asterik ( "*" )
as=as+2;
printf("\n");
}
// Re-initialising ms = maximum space and aterik
ms=2;
as=7;
// Running loop for Second Part
for(i=1;i<=5;i++)
{
// Printing Space
for(s=1;s<=ms;s++)
{
printf(" ");
}
// Increasing spaces
ms++;
// Printing First Part
for(j=1;j<=as;j++)
{
printf("*");
}
// Decreasing Asterik ( "*" )
as=as-2;
printf("\n");
}
getch(); </span><span style="color: blue;">// Linux user - Remove this</span><span style="color: blue;">
</span><span style="color: blue;">
return 0;
}</span>
</pre>
</div>
<br />
<a href="http://www.comp-psyche.com/2014/02/c-programs-patterns3.html#p19" name="p19">19. Program to print the given pattern </a><br />
<div class="mokcode">
<pre><span style="color: blue;">/*
8 4 2 1
4 2 1
2 1
1
*/
#include<stdio.h>
#include<conio.h>
int main()
{
int n=8,m;
int i,j;
m=n;
for(i=4;i>=1;i--)
{
for(j=1;j<=i;j++)
{
printf("%d ",m);
m=m/2;
}
m=n/2;
n=n/2;
printf("\n");
}
getch();
return 0;
}</span>
</pre>
</div>
<br />
<a href="http://www.comp-psyche.com/2014/02/c-programs-patterns3.html#p20" name="p20">20. Program to print the given pattern </a><br />
<div class="mokcode">
<pre><span style="color: blue;">#include<stdio.h>
#include<conio.h> </span><span style="color: blue;">// Linux user - Remove this</span><span style="color: blue;">
</span><span style="color: blue;">
int main()
{
int arr[30],temp[30],i,j,k,l,n;
printf("Enter the number of lines to be printed: ");
scanf("%d",&n);
temp[0]=1;
arr[0]=1;
for(j=0;j<n;j++)
printf(" ");
printf(" 1\n");
for(i=1;i<n;i++)
{
for(j=0;j<n-i;j++)
printf(" ");
for(k=1;k<i;k++)
{
arr[k]=temp[k-1]+temp[k];
}
arr[i]=1;
for(l=0;l<=i;l++)
{
printf("%2d",arr[l]);
temp[l]=arr[l];
}
printf("\n");
}
getch(); </span><span style="color: blue;">// Linux user - Remove this</span><span style="color: blue;">
</span><span style="color: blue;">
return 0;
}
</span></pre>
</div>
<br />
<span style="color: yellow;">More Informative posts :</span><br />
<br />
<br />
<br />
<br />
<ul>
<li><a href="http://www.comp-psyche.com/2014/02/c-programs-patterns.html">C Programs Pattern ( 1-5 )</a></li>
<li><a href="http://www.comp-psyche.com/2014/02/c-programs-patterns1.html">C Programs Pattern ( 6-10 )</a></li>
<li><a href="http://www.comp-psyche.com/2014/02/c-programs-pointers2.html">C Programs Pattern ( 11-16 )</a></li>
</ul>
</div>
Mantu Kumarhttp://www.blogger.com/profile/02897308282659594376noreply@blogger.com0