<\/span><\/h2>\n\n\n\nComplete the code in the editor below. The variables i<\/em><\/strong>, d<\/em><\/strong>, and s<\/em><\/strong> are already declared and initialized for you. You must:<\/p>\n\n\n\n- Declare 3<\/strong> variables: one of type int<\/em>, one of type double<\/em>, and one of type String<\/em>.<\/li>
- Read 3<\/strong> lines of input from stdin (according to the sequence given in the Input Format<\/em> section below) and initialize your variables.<\/li>
- Use the +<\/strong> operator to perform the following operations:
- Print the sum of i<\/em><\/strong> plus your int variable on a new line.<\/li>
- Print the sum of d<\/em><\/strong> plus your double variable to a scale of one decimal place on a new line.<\/li>
- Concatenate s<\/em><\/strong> with the string you read as input and print the result on a new line.<\/li><\/ol><\/li><\/ol>\n\n\n\n
Note:<\/strong> If you are using a language that doesn’t support using +<\/strong> for string concatenation (e.g.: C), you can just print one variable immediately following the other on the same line. The string provided in your editor must<\/em> be printed first, immediately followed by the string you read as input.<\/p>\n\n\n\n<\/span>Input Format<\/strong><\/span><\/h2>\n\n\n\nThe first line contains an integer that you must sum with i<\/em><\/strong>.
The second line contains a double that you must sum with d<\/em><\/strong>.
The third line contains a string that you must concatenate with s<\/em><\/strong>.<\/p>\n\n\n\n<\/span>Output Format<\/strong><\/span><\/h2>\n\n\n\nPrint the sum of both integers on the first line, the sum of both doubles (scaled to 1<\/strong> decimal place) on the second line, and then the two concatenated strings on the third line.<\/p>\n\n\n\nSample Input<\/strong><\/p>\n\n\n\n12\n4.0\nis the best place to learn and practice coding!<\/code><\/pre>\n\n\n\nSample Output<\/strong><\/p>\n\n\n\n16\n8.0\nHackerRank is the best place to learn and practice coding!<\/code><\/pre>\n\n\n\nExplanation<\/strong><\/p>\n\n\n\nWhen we sum the integers 4<\/strong> and 12<\/strong>, we get the integer 16<\/strong>.
When we sum the floating-point numbers 4.0<\/strong> and 4.0<\/strong>, we get 8.0<\/strong>.<\/p>\n\n\n\n<\/span>Solution – Day 1: Data Type Solution <\/strong><\/span><\/h2>\n\n\n\n<\/span>C<\/strong><\/span><\/h3>\n\n\n\n#include <stdio.h>\n#include <string.h>\n#include <math.h>\n#include <stdlib.h>\n\nint main() {\n int i = 4;\n double d = 4.0;\n char s[] = \"HackerRank \";\n\n int i2;\n double d2;\n char s2[100]; \/\/ this is not scalable for input of unknown size\n\n \/\/ Read inputs from stdin\n scanf(\"%d\", &i2);\n scanf(\"%lf\", &d2);\n scanf(\"%*[\\n] %[^\\n]\", s2); \n\n \/\/ Print outputs to stdout\n printf(\"%d\\n\", i + i2);\n printf(\"%.01lf\\n\", d + d2);\n printf(\"%s%s\", s, s2);\n\n return 0;\n}<\/pre>\n\n\n\n<\/span>C++<\/strong><\/span><\/h3>\n\n\n\n#include <iostream>\n#include <iomanip>\n#include <limits>\n\nusing namespace std;\n\nint main() {\n int i = 4;\n double d = 4.0;\n string s = \"HackerRank \";\n\n \/\/ Declare second integer, double, and String variables.\n int i2;\n double d2;\n string s2;\n \/\/ Read and save an integer, double, and String to your variables.\n \/\/ Note: If you have trouble reading the entire string, please go back and review the Tutorial closely.\n cin >> i2;\n cin >> d2;\n cin.get();\n getline(cin, s2);\n \/\/ Print the sum of both integer variables on a new line.\n cout << i+i2 << endl;\n \/\/ Print the sum of the double variables on a new line. \n cout<< std::fixed <<std::setprecision(1)<< d + d2 << endl;\n \/\/ Concatenate and print the String variables on a new line\n cout << s << s2;\n \/\/ The 's' variable above should be printed first.\n return 0;\n}<\/pre>\n\n\n\n