//this code is designed by codenation.
//4:25 02/10/2020
#include<stdio.h>
#include<stdlib.h>
int main()
{
int n1,n2,i,ptr,swap=0;
char temp=' ';
printf("enter the number of letters in array : \n");
scanf("%d",&n1);
char data[n1];
int comp=0;
printf("enter the words in array : \n");
for(i=0;i<n1;i++)
{
printf("enter the %d letter :\n",i);
scanf(" %c",&data[i]);
}
for(i=0;i<n1-1;i++)
{
ptr=0;
for(ptr=0;ptr<=n1-2-i;ptr++)
{
comp++;
if(data[ptr]>data[ptr+1])
{
temp=data[ptr];
data[ptr]=data[ptr+1];
data[ptr+1]=temp;
swap=1;
}
if(swap=0)
{
break;
}
}
}
printf("the no of comparisons are : %d\n",comp);
printf("the sorted set in ascending order is :\n");
for(i=0;i<n1;i++)
{
printf("%c\n",data[i]);
}
return 0;
}
//this code is developed by codenation.
Comments
Post a Comment