Write a C Program to perform non recursive Bubble Sort. - Data Structure using C

Translate

Thursday, December 10, 2020

Write a C Program to perform non recursive Bubble Sort.

            Write a Program to perform non-recursive Bubble Sort.

Input Format:

 The first line consists of an integer N denoting the size of the array. The next line contains N space-separated integers denoting the elements of the array.

  Output Format

Print N space-separated integers in ascending order

Code👇👇👇👇👇👇👇👇


#include<stdio.h>


int main(){


   int count, temp, i, j, number[30];


   printf("How many numbers are u going to enter?: ");

   scanf("%d",&count);


   printf("Enter %d numbers: ",count);


   for(i=0;i<count;i++)

   scanf("%d",&number[i]);



   for(i=count-2;i>=0;i--){

      for(j=0;j<=i;j++){

        if(number[j]>number[j+1]){

           temp=number[j];

           number[j]=number[j+1];

           number[j+1]=temp;

        }

      }

   }


   printf("Sorted elements: ");

   for(i=0;i<count;i++)

      printf(" %d",number[i]);


   return 0;

}





No comments:

Post a Comment

Introduction to Arrays

  Introduction to Arrays An array is a data structure that allows you to store a collection of elements of the same type. Each element in th...