Posts

Showing posts with the label Bubble sort

C Program | Bubble sort User Define :

Image
Write a C Program to Sort an array using Bubble sort , User Define Array : Code: #include<stdio.h> void main() { int a[20]; int n,i,j,k; printf("Enter the size of array [20]:\n"); scanf("%d",&n); printf("Enter the elements:\n"); for(i=0;i<n;i++) scanf("%d",&a[i]); for(i=0;i<n;i++) for(j=0;j<n-1;j++) { if(a[j]>a[j+1]) { k=a[j]; a[j]=a[j+1]; a[j+1]=k; } } for(i=0;i<n;i++) printf("%d\t",a[i]); } Output: ---------------------------------------------------------------------------- Bubble sort : Using Pointer