Program Discussion :: Strings
52 / 60
Write a program to enter a string then convert the string into reverse order.
Answer:
#include
#include
#include
void main()
{
clrscr();
char str[100], temp;
int i=0, j;
cout
Asked In ::
Language:
Manoj Kumar
15 Jun, 2017 11:06 PM
<!DOCTYPE html>
<html>
<body>
<?php
function Reverse() {
// input string
$str ="what is your name";
echo "Input string is :" . $str."<br/>";
$name = strrev ($str);
// printing string in reverse order
echo $name;
}
Reverse();
?>
</body>
</html>
Language:
Lekha
7 Jul, 2017 9:30 AM
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
clrscr();
char str[100], temp;
int i=0, j;
printf("Enter the String : ");
gets(str);
i=0;
j=strlen(str)-1;
while(i<j)
{
temp=str[i];
str[i]=str[j];
str[j]=temp;
i++;
j--;
}
printf("Reverse of the String = %s",str);
getch();
}
Language:
Neel
7 Jul, 2017 9:30 AM
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
char str[100], temp;
int i=0, j;
cout<<"Enter the String : ";
gets(str);
i=0;
j=strlen(str)-1;
while(i<j)
{
temp=str[i];
str[i]=str[j];
str[j]=temp;
i++;
j--;
}
cout<<"Reverse of the String = "<<str;
getch();
}
Language:
Sanjay
25 Aug, 2017 12:20 AM
import java.io.*
public class ReverseEachWord
{
public static void main(String[] args)
{
System.out.println("Enter Your Name");
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String n = br.readLine();
String s1 = n;
String[] s2 = s1.split(" ");
for (String string : s2)
{
StringBuffer sb = new StringBuffer();
sb.append(string);
sb.reverse();
System.out.print(sb);
System.out.print(" ");
}
}
}
Language:
Siddhartha Paul
19 Jun, 2019 2:16 PM
import java.util.Scanner;
public class Reverse
{
public static void main(String []args)
{
String rev="";
Scanner sc=new Scanner(System.in);
System.out.println("Enter a string: ");
String str=sc.nextLine();
int len=str.length();
for(int i=len-1;i>=0;i--)
{
char ch=str.charAt(i);
rev=rev+ch;
}
System.out.println("Reverse string is: "+rev);
}
}
Language:
Dunga
11 Dec, 2020 6:13 PM
n=str(input())
print(n[::-1])