0% found this document useful (0 votes)
2 views1 page

Array Sort Program

The document contains a C program that sorts an array of integers in ascending order using the bubble sort algorithm. It prompts the user to input the number of elements and the elements themselves, then sorts and displays the array. A sample input and output are provided to illustrate the program's functionality.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views1 page

Array Sort Program

The document contains a C program that sorts an array of integers in ascending order using the bubble sort algorithm. It prompts the user to input the number of elements and the elements themselves, then sorts and displays the array. A sample input and output are provided to illustrate the program's functionality.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

C Program: Sort Array in Ascending Order

Program Code:
#include <stdio.h>

int main()
{
int n, i, j, temp;
int arr[100];

printf("Enter the number of elements: ");


scanf("%d", &n);

printf("Enter %d elements:\n", n);


for(i = 0; i < n; i++)
{
scanf("%d", &arr[i]);
}

for(i = 0; i < n - 1; i++)


{
for(j = 0; j < n - i - 1; j++)
{
if(arr[j] > arr[j + 1])
{
temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}

printf("Array in ascending order:\n");


for(i = 0; i < n; i++)
{
printf("%d ", arr[i]);
}

return 0;
}

Sample Input and Output:


Sample Input:
Enter the number of elements: 5
Enter 5 elements:
4 2 8 1 3

Sample Output:
Array in ascending order:
1 2 3 4 8

You might also like