Microsoft Interview Question
Software Engineer / Developers#include <stdio.h>
#include <string.h>
int reverse(char* str)
{
char* head =str;
char* tail = head + strlen(str)-1;
char temp;
do{
temp = *head;
*head = *tail;
*tail = temp;
}while(head++ < tail--);
printf("the output is %s\n",str);
return 0;
}
int main()
{
char a[] = "abcdefghijk";
int ret = reverse(a);
printf("the output is %s\n",a);
return 0;
}
/* Takes the string to reverse as argument */
- Amit March 15, 2006#include <stdio.h>
int main(int args, char *argv[])
{
int length, i;
length = strlen(argv[1]);
for(i=length; i>=0; i--)
printf("%c", argv[1][i]);
return 0 ;
}