EQuestionAnswers.com Computer/Electronics Questions and Answers
C, C++, VC++, COM/DCOM, DLL and more
#Login #Sign up  Facebook Twitter TGoogle+
 

Write a program to sort the given array in descending order using bubble sort within a function.

Source Code

#include<stdio.h>
#include<conio.h>
void bubble(int ar[100],int r)
{
  int i,j,t=0;
  for(i=0;i<r;i++)
  {
        for(j=i;j<r;j++)
        {
10      if(ar[i]>ar[j])
11      {
12        t=ar[i];
13        ar[i]=ar[j];
14        ar[j]=t;
15      }
16          }
17    }
18    printf("\n The Sorted array:\n");
19    for(i=0;i<r;i++)
20    {
21         printf("%d ",ar[i]);
22    }
23  }
24  int main (int argc, char *argv[])
25  {
26    clrscr();
27    int ar[100],r=0,i;
28    for(i=0;i<100;i++)
29    {
30      ar[i]=0;
31    }
32    printf("\n Enter the range:(less than 100) ");
33    scanf("%d",&r);
34    printf("\n Enter the elements of the array:");
35    for(i=0;i<r;i++)
36    {
37         printf("\n Enter element number: %d ",(i+1));
38         scanf("%d",&ar[i]);
39    }
40    bubble(ar,r);
41    getch();
42  }

Find More from our code collection
Armstrong number, binary number to a decimal number, bubble sort, decimal number to binary number, factorial of the given number factors, fibonacci numbers, HCF and LCM, matrix, mergesort, salary of the employee. palindrome, quadratic equation, star patterns, series etc. and much more...
#Return to Example Source Code