pgm to reverse string using arrays i.e god is love becomes
love is god)
(assumption:only space is used for seperation of words)

no addtional memory used.i.e no temporary arrays can used.

Answer Posted / santhi perumal

#include<stdio.h>
#include<conio.h>

int main()
{

int i,j,length;
char a[] = "god is love";

length = strlen(a);

printf("The Given String is\n%s\n",a);
printf("The Resulted String is\n");

for(i=length-1;i>=0;i--)
{
if(a[i] == ' ')
{
for(j=i+1; a[j] != ' ' && a[j] != '\0';j++)
{
printf("%c",a[j]);
}
printf("%c",a[i]);
}
}
i++;
while(a[i] !=' ')
{
printf("%c",a[i]);
i++;
}
printf("\n");

}

Is This Answer Correct ?    14 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is fortran faster than c?

579


Explain how can you check to see whether a symbol is defined?

661


c language interview questions & answer

1462


Add Two Numbers Without Using the Addition Operator

353


How to draw the flowchart for structure programs?

8762






What is pass by value in c?

594


Can a pointer be volatile in c?

535


What is wrong with this code?

693


write a programe to accept any two number and check the following condition using goto state ment.if a>b,print a & find whether it is even or odd and then print.and a

1451


What are predefined functions in c?

566


What is extern keyword in c?

644


write a C program:There is a mobile keypad with numbers 0-9 and alphabets on it. Take input 0f 7 keys and then form a word from the alphabets present on the keys.

14960


Why is python slower than c?

602


An expression to whose value an operater is applied a) operand b) variable c) constant d) all of the above

656


What does c mean before a date?

591