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.
Answers were Sorted based on User's Feedback
#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 |
Answer / abdur rab
#include <stdio.h>
void reverse_string ( char* cp_string, int start, int end )
{
if ( cp_string && ( start < end ) ) {
*( cp_string + start ) ^= *( cp_string +
end )
^= *( cp_string + start ) ^= *(
cp_string + end );
reverse_string ( cp_string, ++start, --
end );
}
}
int main ( int argc, char* argv [] )
{
char ca_array [12]={"Hello World"};
char* cp_ptr = NULL;
char* cp_ptr_temp = NULL;
printf ( "\n Before Reverse :%s", ca_array );
reverse_string ( ca_array, 0, strlen ( ca_array ) -
1 );
cp_ptr_temp = cp_ptr = ca_array;
while ( NULL != ( cp_ptr_temp = (char*) strchr (
cp_ptr_temp, ' ' ) ) ) {
reverse_string ( cp_ptr, 0, ( cp_ptr_temp -
cp_ptr ) - 1 );
cp_ptr = ++cp_ptr_temp;
}
// change the final word
reverse_string ( cp_ptr, 0, ( ( strlen (
ca_array ) - 1 ) - ( cp_ptr - ca_array ) ) );
printf ( "\n After Reverse by Words :%s",
ca_array );
return ( 0 );
}
Is This Answer Correct ? | 1 Yes | 0 No |
Answer / ruchi
#include<stdio.h>
#include<conio.h>
int main()
{
int i=0,c;
char a[20];
printf("\nEnter the string");
while((a[i++]=getchar())!='\n');
printf("\nReverse of the string is ");
for(c=i;c>=0;c++)
{
printf("%c"a[c]);
}
getch();
}
Is This Answer Correct ? | 1 Yes | 5 No |
Answer / paaru
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char a[20],i;
printf("\n\nEnter the string:");
gets(a);
for(i=strlen(a)-1;i>=0;i++)
{
printf("%d"a[i]);
}
getch();
}
Is This Answer Correct ? | 1 Yes | 7 No |
Write a program to print all permutations of a given string.
main() { intj; while9j<=10) { printf("\n%d",j); j=j+1; } }
How can I call system when parameters (filenames, etc.) Of the executed command arent known until run time?
What are the different types of pointers?
How to reverse a linked list
1 Answers Aricent, Fidelity, IBM, TCS,
write a program structure to find average of given number
What is the difference between break and continue?
How can I implement sets or arrays of bits?
What is the difference between variable declaration and variable definition in c?
main() { float a=8.8; double b=8.8; if(a==b) printf("Equal"); else printf("not equal"); getch(); } what is the output? with reason
a linearly ordered set of data elements that have the same structure and whose order is preserved in storage by using sequential allocation a) circular b) ordinary c) array d) linear list
write a program of palindrome(madam=madam) using pointer?