Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort array in asc order in C #43

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

mouli1441
Copy link

`#include <stdio.h>

void main()
{
int arr1[100];
int n, i, j, tmp;

   printf("\n\nsort elements of array in ascending order :\n ");
   printf("----------------------------------------------\n");	

printf("Input the size of array : ");
scanf("%d", &n);

   printf("Input %d elements in the array :\n",n);
   for(i=0;i<n;i++)
        {
      printf("element - %d : ",i);
      scanf("%d",&arr1[i]);
    }

for(i=0; i<n; i++)
{
    for(j=i+1; j<n; j++)
    {
        if(arr1[j] <arr1[i])
        {
            tmp = arr1[i];
            arr1[i] = arr1[j];
            arr1[j] = tmp;
        }
    }
}
printf("\nElements of array in sorted ascending order:\n");
for(i=0; i<n; i++)
{
    printf("%d  ", arr1[i]);
}
        printf("\n\n");

}`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant