google.com, pub-6167773875660516, DIRECT, f08c47fec0942fa0 Write a c program to sort n numbers in ascending order - 2nd puc computer science

Write a c program to sort n numbers in ascending order

 Write a c program to sort n numbers in ascending order, Write a c program for bubble sort

#include<stdio.h>

#include<conio.h>

void main()

{

int a[10],n,i,j,temp;

clrscr();

printf("How many elements? ");

scanf("%d",&n);

printf("Enter the elements\n");

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

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

printf("Sorted elements are\n");

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

         for(j=i+1;j<n;j++)

         {

                  if(a[i]>a[j])

                  {

                           temp=a[i];

                           a[i]=a[j];

                           a[j]=temp;

                  }

         }

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

printf("%d\n",a[i]);

getch();

}

Output:

How many elements? 5

Enter the elements                                                             

3                                                                              

5                                                                              

1                                                                              

2                                                                              

4                                                                              

Sorted elements are                                                            

1                                                                              

2                                                                              

3                                                                               

4                                                                              

5    
Write a c program to sort n numbers in ascending order  Write a c program to sort n numbers in ascending order Reviewed by Vision Academy on December 12, 2021 Rating: 5

No comments:

CheckOut

Powered by Blogger.