String reverse with time complexity of n/2 with out using
temporary variable.

Answer Posted / gayathri sundar

#include<stdio.h>
#include<string.h>
main(int argc, char *argv[])
{
char *string = argv[1];
int len = strlen(string);
int i = 0;
int j = len - 1;
printf("string before is %s\n", string);
printf("len is %d\n", len);
while(i <= j)
{
*(string+i) += *(string+j);
*(string+j) = *(string+i) - *(string+j);
*(string+i) = *(string+i) - *(string+j);
i++;
j--;
if(len % 2)
if(i == j) break;
}
printf("reversed string is %s\n", string);
}

Is This Answer Correct ?    9 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

write a program for area of circumference of shapes

2026


How do you verify if the two sentences/phrases input is an anagram using predefined functions in string.h and by using arrays?

2013


What is data _null_? ,Explain with code when u need to use it in data step programming ?

2817


how to test pierrot divisor

2251


Write a Program in 'C' To Insert a Unique Number Only. (Hint: Just Like a Primary Key Numbers In Database.) Please Some One Suggest Me a Better Solution for This question ??

1768






why do you use macros? Explain a situation where you had to incorporate macros in your proc report? use a simple instream data example with code ?

2253


How can you relate the function with the structure? Explain with an appropriate example.

2913


can you use proc sql to manpulate a data set or would u prefer to use proc report ? if so why ? make up an example and explain in detail

2321


how to create a 3x3 two dimensional array that will give you the sums on the left and bottom columns

3117


create a C-code that will display the total fare of a passenger of a taxi if the driver press enter,the timer will stop. Every 10 counts is 2 pesos. Initial value is 25.00

6304


What is the match merge ? compare data step match merge with proc sql merge - how many types are there ? data step vs proc sql

2399


To Write a C program to remove the repeated characters in the entered expression or in entered characters(i.e) removing duplicates. String contains only lowercase characters ['a'-'z']

488


Design an implement of the inputs functions for event mode

2955


What is the difference between proc means and proc tabulate ? explain with a simple example when you have to use means or tabulate?

3704


Can you send Code for Run Length Encoding Of BMP Image in C Language in linux(i.e Compression and Decompression) ?

3843