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
write a program for area of circumference of shapes
How do you verify if the two sentences/phrases input is an anagram using predefined functions in string.h and by using arrays?
What is data _null_? ,Explain with code when u need to use it in data step programming ?
how to test pierrot divisor
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 ??
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 ?
How can you relate the function with the structure? Explain with an appropriate example.
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
how to create a 3x3 two dimensional array that will give you the sums on the left and bottom columns
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
What is the match merge ? compare data step match merge with proc sql merge - how many types are there ? data step vs proc sql
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']
Design an implement of the inputs functions for event mode
What is the difference between proc means and proc tabulate ? explain with a simple example when you have to use means or tabulate?
Can you send Code for Run Length Encoding Of BMP Image in C Language in linux(i.e Compression and Decompression) ?