The program must accept an integer N as the input. The task is to create a new number by doubling each digit of N and return the new number. If doubling a digit results in a number greater than 9, then only the unit’s place of the result must be considered.
Boundary Condition(s):
1 <= N <= 10^9
Input Format:
The first line contains the integer N.
Output Format:
The first line contains the new number formed by doubling each digit of N.
Example Input/Output 1:
Input:
248
Output:
416
Explanation:
By doubling each digit, we get the sequences: 4, 16, 16. Using only the unit’s place from each result, we get the new number 416.
Example Input/Output 2:
Input:
359
Output:
6108
Explanation:
By doubling each digit, we get the sequences: 6, 10, 18. Using only the unit’s place from each result, we get the new number 6108.
n = input().strip()
result = ''.join(str((int(ch) * 2) % 10) for ch in n)
print(result)
#include<stdio.h>
#include<string.h>
int main() {
char n[12];
scanf("%s", n);
int len = strlen(n);
for(int i = 0; i < len; i++) {
printf("%d", (2 * (n[i] - '0')) % 10);
}
return 0;
}
#include <iostream>
#include <string>
using namespace std;
int main() {
string n;
cin >> n;
for(char ch : n) {
cout << (2 * (ch - '0')) % 10;
}
return 0;
}
import java.util.Scanner;
public class DoubleEachDigit {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String n = sc.next();
for(char ch : n.toCharArray()) {
System.out.print((2 * (ch - '0')) % 10);
}
}
}