Append the Number’s Mirror Image to Itself

The program must accept an integer N as the input. The task is to mirror the number and append it to the end of the original number. The program should print the resultant number.

Boundary Condition(s):
1 <= N <= 10^6

Input Format:
The first line contains the number N.

Output Format:
The first line contains the resultant number after appending its mirror image.

Example Input/Output 1:
Input:
123

Output:
123321

Explanation:
The mirror image of 123 is 321. Appending it to the original number, we get 123321.

Example Input/Output 2:
Input:
9876

Output:
98766789

Explanation:
The mirror image of 9876 is 6789. Appending it to the original number, we get 98766789.

n = input().strip()
mirror = n[::-1]
print(n + mirror)
#include<stdio.h>
#include<string.h>

int main() {
    char num[7];
    scanf("%s", num);
    char mirror[strlen(num)+1];
    for(int i = 0; i < strlen(num); i++) {
        mirror[i] = num[strlen(num) - 1 - i];
    }
    mirror[strlen(num)] = '';
    printf("%s%s", num, mirror);
    return 0;
}
#include <iostream>
#include <string>
using namespace std;

int main() {
    string num;
    cin >> num;
    string mirror = num;
    reverse(mirror.begin(), mirror.end());
    cout << num + mirror;
    return 0;
}
import java.util.Scanner;

public class AppendMirror {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String num = sc.next();
        StringBuilder mirror = new StringBuilder(num);
        mirror.reverse();
        System.out.println(num + mirror);
    }
}
Previous Article

Count Digits That Are Fibonacci Numbers

Next Article

Count Zeroes Surrounded by the Same Digit

Write a Comment

Leave a Comment

Your email address will not be published. Required fields are marked *