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);
}
}