Sort array element and insert element into array in correct position in c Program Tamil


#include<stdio.h>
#include<conio.h>
void main()
{
    int i,n,t,j,m,p,v;
    int a[100],b[100];
    clrscr();
    printf("\nEnter the limit :");
    scanf("%d",&n);
    printf("\nEnter the %d values ",n);
    for(i=0;i<n;i++)
    {
	scanf("%d",&a[i]);
    }
    for(i=0;i<n;i++)
    {
	for(j=i+1;j<n;j++)
	{
		if(a[i]>a[j])
		{
			t=a[i];
			a[i]=a[j];
			a[j]=t;
		}
	}
    }
    printf("\nEnter the insert value :");
    scanf("%d",&v);
    for(i=0;i<n;i++)
    {
	if(a[i]<v)
	{
		p=i;
	}
    }
    m=p+1;
    for(i=0;i<=m;i++)
    {
	b[i]=a[i];
    }
    b[m]=v;
    for(i=m+1;i<=n+1;i++)
    {
	b[i]=a[i-1];
    }
    printf("\nAtfter sort ...");
    for(i=0;i<=n;i++)
    {
       printf("\n%d",b[i]);
    }
    getch();
}

Login To Download Source Code

Leave a Comment:

Login To Comment

List Of Programs


Goto Examples

Operators

Looping

Number Conversion

Pattern Design

Arrays

Matrix Examples

Sorting Examples

String Function

Change Case

String In C

Maths Functions

User Defined Functions

Recursive Functions

Pointer

Structure

File Concept

Calender Programming