Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 2

Exercise Lab#10 Write a program that separates numeric characters from alphabetic characters and merge them in ascending

order.
#include<stdio.h> #include<conio.h> #include<string.h> void main(){ char str[90],alpha[90],num[90]; int i=0,j=0,k=0,numlen,alphalen,temp; clrscr(); gets (str); while (str[i]!=NULL){ if ((str[i]>=48)&&(str[i]<=58)){ num[j]=str[i]; j++;} else { alpha[k]=str[i]; k++; }i++; } alpha[k+1]=NULL; num[j+1]=NULL; numlen=strlen(num); alphalen=strlen(alpha); for(i=0;i<numlen-1;i++){ for (j=0;j<numlen-1;j++){ if (num[j]>num[j+1]){ temp=num[j]; num[j]=num[j+1];

2k9-CSE-169 Maira Alvi

num[j+1]=temp; }}} puts (num); for(i=0;i<alphalen-1;i++){ for (j=0;j<alphalen-1;j++){ if (alpha[j]>alpha[j+1]){ temp=alpha[j]; alpha[j]=alpha[j+1]; alpha[j+1]=temp; }}} j=0; while(alpha[j]!=NULL){ num[numlen]=alpha[j]; numlen++; j++; } num[numlen]=NULL; puts (num); getch(); }

Comments:
I initialized my string as str[]=abc159dyku063 I separated the numeric characters from alphabetic characters and then I arranged them in assending order and then I merged the two strings.I got my desired output .

Output :
Num[]=159063 Alpha[]=abcdyku After sorting and merging two strings: Num[]=013569abcdkuy

2k9-CSE-169 Maira Alvi

You might also like