Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to code in professional manner?
    primarykey
    data
    text
    <p>I was wondering, how a program can be written in a perfect professional style. Many times it happens that we write a very good program/code which gives the accurate output.One might use the best algorithm to solve the given problem.</p> <p>But for a person who is reading your code for his/her reference, it becomes difficult to understand the code because of improper use of variable/function names.(And many other issues)</p> <p>So how one can achieve this perfection of writing code in professional manner?</p> <p><strong>You can elaborate your thoughts by directly editing the following code.</strong> (Don't edit the code in the question :)</p> <p>You can also rewrite the complete code at the end in professional way.Will be a lot of help.</p> <p>(A simple heap sort algorithm in C)</p> <pre><code>#include&lt;stdio.h&gt; #include&lt;conio.h&gt; void insert(int i); void swap(int *,int *); void heap_sort(int); int a[20]; void main() { int n,i; clrscr(); printf("Enter the no of elements : "); scanf("%d",&amp;n); printf("\nEnter the elements : \n"); for(i=0;i&lt;n;i++) scanf("%d",&amp;a[i]); heap_sort(n); printf("\nSorted array is : \n"); for(i=0;i&lt;n;i++) printf("\t%d",a[i]); getch(); } void swap(int *p,int *q) { int temp; temp=*p; *p=*q; *q=temp; } void heap_sort(int n) { int x=1,i; while(x&lt;n) { for(i=1;i&lt;=n-x;i++) insert(i); swap(&amp;a[0],&amp;a[n-x]); x++; } } void insert(int i) { int j=(i-1)/2,item=a[i]; while((i&gt;0) &amp;&amp; (item&gt;a[j])) { a[i]=a[j]; i=j; j=(i-1)/2; } a[i]=item; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload