I recently started writing and learning C code and this forum helped me a lot so far. I would like to request the fellow developers here that are experienced in C coding, to take a quick look to this recent code i made (which i think works fine) and tell me if i did something i should avoid in the fututre and how to improve the code for better usability or output and such. Please be detailed in your explanation and note that i am still very much a beginner.Thank You in advance. Here is the code :
//Program To Input Values Into An Array And Sort Them In Ascending Order
#include<stdio.h>
//Function To Print The Array Values
void print(int tab(),int n)
{
int i;
printf("The Values Are : n");
for(i=0;i<n;i++)
{
printf("%d ",tab(i));
}
printf("n");//Line Jumping For Better Output
}
//Function To Swap The Values In The Array
void swap(int* x,int* y)
{
int temp=*x;
*x=*y;
*y=temp;
}
//Function To Sort The Values In The Array By Using Previous Function
void sort(int tab(),int n)
{
int i,j;
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(tab(i)>tab(j))
{
swap(&tab(i),&tab(j));//Swaps The Value Of Index i With The Value Of Index j In The Array
}
}
}
}
//Main Code
int main()
{
int i,n,tab(100);
printf("Give The Number Of Elements In The Array:");
scanf("%d",&n);
while(n<=0)
{
printf("The Number Of Elements MUST Be Superior To 0!n");
printf("Give The Number Of Elements In The Array:");
scanf("%d",&n);
}
printf("Insert %d Values :n",n);
for(i=0;i<n;i++)
{
scanf("%d",&tab(i));
}
print(tab,n);//Prints The Values In The Array
sort(tab,n);//Sorts The Values In The Array
printf("SORTING....n");
print(tab,n);//Prints The Values In The Array
return 0;
}