Reverse of a string in c:
Write a program to reverse a given string
Example:
hello
Reverse of a string: olleh
Input:
how
output:
woh
program:
#include<stdio.h>
void main()
{
int i,n;
char string[20];
int length = 0;
scanf("%s", string);
//finding length of a string
while (string[length] != '\0') {
length+=1;
}
//reverse of a string
for(i=length-1;i>=0;i--)
{
printf("%c",string[i]);
}
}
Python:
Input:
how
output:
woh
program:
n=input() #reading a string
s=n[::-1] #reverse of a string
print(s)
Tags
C&Python