Write a program using bubol sort algorith.
Program:
#include<stdio.h>
main()
{
int data[10], pot, k, ptr, n;
printf("How many number =");
scanf("%d", &n);
for(k=1; k<=n; k++)
{
printf("Data[%d]=",k);
scanf("%d", &data[k-1]);
}
for(k=1; k<=n-1; k++)
{
ptr=1;
while(ptr<=n-k)
{
if(data[ptr-1]>data[ptr])
{
pot=data[ptr];
data[ptr]=data[ptr-1];
data[ptr-1]=pot;
}
ptr=ptr+1;
}
}
for(k=1; k<=n; k++)
printf("Data[%d]=%d\n", k, data[k-1]);
}
Program:
#include<stdio.h>
main()
{
int data[10], pot, k, ptr, n;
printf("How many number =");
scanf("%d", &n);
for(k=1; k<=n; k++)
{
printf("Data[%d]=",k);
scanf("%d", &data[k-1]);
}
for(k=1; k<=n-1; k++)
{
ptr=1;
while(ptr<=n-k)
{
if(data[ptr-1]>data[ptr])
{
pot=data[ptr];
data[ptr]=data[ptr-1];
data[ptr-1]=pot;
}
ptr=ptr+1;
}
}
for(k=1; k<=n; k++)
printf("Data[%d]=%d\n", k, data[k-1]);
}