Write a program that inputs name of two students and then print the names in alphabetical order on the screen.(The student having name start with d will appear first on the screen than the student having name start with i)
#include "iostream" #include "conio.h" using namespace std; int main() { char nameOne[20],nameTwo[20]; cout << "Enter Names seperated by space:\n"; cin >> nameOne >> nameTwo; char chOne,chTwo; cout << "\n\n"; chOne = nameOne[0]; chTwo = nameTwo[0]; if(chTwo > chOne) cout << nameOne << "\n" << nameTwo; else if(chOne>chTwo) cout << nameTwo << "\n" << nameOne; else if (chOne==chTwo) cout << "Both of are same order\n"; else cout <<"Invalid Input!!!!"; }
No comments:
Post a Comment