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:

  • Pointers And Structures Pointers And Structures  We know that the name of an array stands for the address of its zeroth element.The same thing is true of the names of  arrays of structure variables.Suppose product is an array variabl… Read More
  • Introduction To Storage Classes Introduction To Storage Classes strong class provides information about their location and visibility.The storage class decides the portion of the program within which the variables are recognized. A variables storage cl… Read More
  • Two-Dimentional Arrays Two-Dimentional Arrays So far we have discussed the array variable that can store a list of values .There will be situation where a table of values will have to be stored.Consider the following data table, which shows t… Read More
  • Initialization of Arrays Initialization of Arrays We can initialize the elements of the array in the same way as the ordinary variables when they are declared.The general form of initialization of array is:  static  type  array-… Read More
  • Declaration of Arrays Declaration of Arrays  Like any other variables, arrays must be declared before they are used.The general form of array declaration is type variable-name [size]; The type specifies the type of elements that will be… Read More

0 comments:

Post a Comment