i need a program written in C++ that if given three names will put the three names in alphabetical order.
maybe use ASCII codes for letters
use strcmp(string1,string2).
Hi i have write this custom solution for you try this , #include<iostream.h> #include<conio.h> #include<string.h> void main() { clrscr(); char st[10],st2[10],st3[10]; cout<<"Enter String 1\n"; cin>>st; cout<<"Enter String 2\n"; cin>>st2; cout<<"Enter String 3\n"; cin>>st3; // cout<<"1"<<st<<"2"<<st2<<"3"<<st3; char g[10],m[10],low[10]; if(strcmp(st,st2)>0&&strcmp(st,st3)>0) { strcpy(g,st); if(strcmp(st2,st3)>0) { strcpy( m,st2); strcpy(low,st3); } else { strcpy( m,st3); strcpy(low,st2); } } if(strcmp(st2,st)>0&&strcmp(st2,st3)>0) { strcpy(g,st2); if(strcmp(st,st3)>0) { strcpy( m,st); strcpy(low,st3); } else { strcpy(m,st3); strcpy(low,st); } } if(strcmp(st3,st)>0&&strcmp(st3,st2)>0) { strcpy(g,st3); if(strcmp(st2,st)>0) { strcpy (m,st2); strcpy (low,st); } else { strcpy(m,st); strcpy(low,st2); } } cout<<"\low is = \n "<<low<<"\nmiddle is= \n"<<m<<"\nhigh is=\n"<<g; getch(); }
Join our real-time social learning platform and learn together with your friends!