Sunday, 21 January 2018

Program For Sorting | general c programs |


Program For Sorting
#include<stdio.h>
#include<conio.h>
main()
{
int a[50],n,i,j,t;
clrscr();
printf("input the no of items u want to sort\n");
scanf("%d",&n);
printf("input the value's to be sorted\n");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
for(j=i;j<n;j++)
{

if(a[i]>a[j])
{
t=a[i];
a[i]=a[j];
a[j]=t;
}
}
}
printf("the sorted elements are\n");
for(i=0;i<n;i++)
{
printf("%d\n",a[i]);
}
getch();
}

Related Posts:

  • Function Declaration and prototype Function Declaration and prototype It is one of the most important feature of ANSI C.A function prototype tells the compiler the type of data returned by the function, the number of arguments the function expects to r… Read More
  • Introduction To Functions Introduction To Functions Functions are building blocks of C. The general form of C (User-defined) function is:       Return-type-function-name(parameter list)       parameter declaration &… Read More
  • GO TO Statement GO TO Statement This Keyword is used when we want to transfer the control to some point in the program which is not in the normal, step by step sequence of a program.  It takes control from one place to another un… Read More
  • Parameter Passing Technique Parameter Passing Technique The parameter passing mechanism refers to the actions taken regarding the parameters when a function is invoked. There are two parameter passing techniques available in C. They are: 1) Call B… Read More
  • Case Control Structure(SWITCH) Case Control Structure(SWITCH) Introduction:           In real life we are often faced with situations where we are required to make a choice between a number of  alternatives rather than on… Read More

0 comments:

Post a Comment