" />

Reverse number or string program

Reverse number or string in c

#include<stdio.h>
#include<conio.h>
#include<string.h>
void GetReverse(char arr[]);
void main()
{
	char arr[100];
	printf("Enter your input \n");
	gets(arr);
	GetReverse(arr);
	getch();
}
void GetReverse(char arr[])
{
 int j=0;
 int len=strlen(arr)-1;
 char arr1[100];
 for(int i=len;i>=0;i--)
 {
	 arr1[j]=arr[i];
	 j++;
 }
 printf("Reverse item are \n");
 for(int i=0;i<=len;i++)
	{printf("%c",arr1[i]);}
}

Output

Enter your input
123456
Reverse item are
654321

Reverse number or string in c++

#include<iostream>
#include<conio.h>
#include<string.h>
using namespace std;
class Example{
public:
void GetReverse(char arr[])
{
 int j=0;
 int len=strlen(arr)-1;
 char arr1[100];
 for(int i=len;i>=0;i--)
 {
	 arr1[j]=arr[i];
	 j++;
 }
 cout<<"Reverse item are \n";
 for(int i=0;i<=len;i++)
	{cout<<arr1[i];}
}
};
void main()
{
	char arr[100];
	cout<<"Enter your input \n";
	cin>>arr;
	Example ex;
	ex.GetReverse(arr);
	getch();
}

Output

Enter your input
mousumi
Reverse item are
imusuom

Reverse number or string in c#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Reverse
{
class Program
{
    string _input;

public string Input
{
    get { return _input; }
    set { _input = value; }
}
public void GetReverse()
{
 int j=0;
 int len=_input.Length - 1;
 char[] arr1 = new char[100] ;
 for(int i=len;i>=0;i--)
 {
     arr1[j] = _input[i];
	 j++;
 }
 Console.Write("Reverse item are \n");
 for(int i=0;i<=len;i++)
	{Console.Write(arr1[i]);}
}
static void Main(string[] args)
{
    string input;
    Console.WriteLine("Enter your input");
    input = Console.ReadLine();
    Program p1 = new Program();
    p1.Input = input;
    p1.GetReverse();
    Console.ReadLine();
}
}
}

Output

Enter your input
guriasoft
Reverse item are
tfosairug

Reverse number or string in java

import java.util.*;
class AB
{
	public void Check(String input)
	{
		int j=0;
	    int len = input.length()-1;
	    char[] arr=input.toCharArray();
	    char[] arr1=new char[100];
	    for(int i=len;i>=0;i--)
	    {
	        arr1[j] = arr[i];
	   	    j++;
	    }
	    System.out.println("Reverse item are");
	    for(int i=0;i<=len;i++)
	   	{System.out.print(arr1[i]);}
	}
	
}
class examples
{
public static void main(String[] args)
  {
     String input;
     Scanner obj= new Scanner(System.in);
     System.out.println("Enter your input");
     input=obj.next();
     AB ab=new AB();
     ab.Check(input);
  }

}

Output

Enter your input
chandan
Reverse item are
nadnahc

Write a comment


Name Email Message