Programming Concepts Question:
Write a C program to reverse the string without using strrev() function?

Answer:
#include <stdio.h>
#include <conio.h>
#include <string.h>
void main()
{
char *str;
int i,len;
//not using any temp variable and assume we can use only string array and length
printf("Enter String : ");
scanf("%s",str);
len=strlen(str)-1;
for(i=0;i<strlen(str)/2;i++)
{
str[i]+=str[len];
str[len]=str[i]-str[len];
str[i]=str[i]-str[len--];
}
printf("Reverse String is : %s",str);
getch();
}
#include <conio.h>
#include <string.h>
void main()
{
char *str;
int i,len;
//not using any temp variable and assume we can use only string array and length
printf("Enter String : ");
scanf("%s",str);
len=strlen(str)-1;
for(i=0;i<strlen(str)/2;i++)
{
str[i]+=str[len];
str[len]=str[i]-str[len];
str[i]=str[i]-str[len--];
}
printf("Reverse String is : %s",str);
getch();
}
Previous Question | Next Question |
Explain difference between computer architecture, structure, and organization? | Tell me how to execute 13,000 test cases in a faster way in manual testing? |