Develop a program to sort the given set of N number using Bubble sort

All QuestionsCategory: C LanguageDevelop a program to sort the given set of N number using Bubble sort
nikhil.d asked 3 years ago
2 Answers
nikhil.d answered 3 years ago

#include <stdio.h>
int main()
{
    int a[20], n, i, temp = 0, j;
    printf(“Enter number of array elements\n”);
    scanf(“%d”, &n);
    printf(“Enter array elements\n”);
    for (i = 0; i < n; i++)
        scanf(“%d”, &a[i]);
    for (i = 1; i < n; i++)
    {
        for (j = 0; j < n – i; j++)
        {
            if (a[j] > a[j + 1])
            {
                temp = a[j];
                a[j] = a[j + 1];
                a[j + 1] = temp;
            }
        }
    }
    printf(“The sorted array is \n”);
    for (i = 0; i < n; i++)
        printf(“%d\n”, a[i]);
}

Anonymous answered 3 years ago

Note: Change the double inverted comma ( ” ) in the code to avoid an error.