InterviewSolution
Saved Bookmarks
| 1. |
Suppose 7 names are stored in a array of pointers names[] as shown below:char *names [ ]= { "Anand","Naureen","Banjot","Wahid","sheena" }; Write a program to reverse the order of these names. |
|
Answer» #include<iostream.h> #include<conio.h> #include<string.h> void main() { clrscr(); char *name[]={"anand","naureen","banjot","wahid","sheena"}; int i,j; cout<<"\nOriginal string\n"; for(i=0;i<5;i++) cout<<name[i]<<end1; char *t; for(i=0,j=4;i<5/2;i++,j--) { t=name[i]; name[i]=name[j]; name[j]=t; } cout<<"\nReversed string:\n"; for(i=0;i<5;i++) cout<<name[i]<<end1; getch(); } |
|