Addition
2 minutes to read
We are given the following website to write a coding solution:
Problem
We need to write a program that is able to take two numbers as input and print their sum. For instance:
1
,2
->3
Solution
Since we are allowed to use C, C++, Python and Rust, let’s write a solution on every language, just because.
C
#include <stdio.h>
int main() {
// take in the numbers
int a;
int b;
scanf("%d", &a);
scanf("%d", &b);
// calculate answer
int answer = a + b;
// print answer
printf("%d\n", answer);
return 0;
}
C++
#include <iostream>
int main() {
// take in the numbers
int a;
int b;
std::cin >> a;
std::cin >> b;
// calculate answer
int answer = a + b;
// print answer
std::cout << answer << std::endl;
return 0;
}
Python
# take in the numbers
a = int(input())
b = int(input())
# calculate answer
answer = a + b
# print answer
print(answer)
Rust
use std::io;
fn main() {
// take in the numbers
let mut input = String::new();
io::stdin()
.read_line(&mut input)
.expect("Failed to read line");
let a: i32 = input.trim().parse().expect("Please enter a valid number");
input.clear();
io::stdin()
.read_line(&mut input)
.expect("Failed to read line");
let b: i32 = input.trim().parse().expect("Please enter a valid number");
// calculate answer
let answer = a + b;
// print answer
println!("{}", answer);
}
Flag
Using any of these programs, we are able to solve the chalenge and capture the flag:
HTB{aDd1nG_4lL_tH3_waY_up_2_th3_t0p}