Input and Output Cpp - Hackerrank Solution

 

Input and Output


Objective


In this challenge, we practice reading input from stdin and printing output to stdout.

In C++, you can read a single whitespace-separated token of input using cin, and print output to stdout using cout. For example, let's say we declare the following variables:

string s;
int n;
and we want to use cin to read the input "High 5" from stdin. We can do this with the following code:

cin >> s >> n;
This reads the first word ("High") from stdin and saves it as string s, then reads the second word ("") from stdin and saves it as integer n. If we want to print these values to stdout, separated by a space, we write the following code:

cout << s << " " << n << endl;
This code prints the contents of string s, a single space (" "), then the integer n. We end our line of output with a newline using endl. This results in the following output:

High 5


Task
Read 3 numbers from stdin and print their sum to stdout.


Solution:

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;


int main() {
    int a,b,c;
    cin>>a>>b>>c;
    cout<<a+b+c;  
    return 0;
}


Note:

This Code is Verified by all Test Cases.If any error occurs then Comment correct code Below in comment box.

Disclaimer:-

The above hole problem statement is given by hackerrank.com, but the solution is generated by the CodexRitik . if any of the query regarding this post or website fill the following contact form Thank You.

Input and Output Cpp - Hackerrank Solution Input and Output Cpp - Hackerrank Solution Reviewed by CodexRitik on October 16, 2020 Rating: 5

No comments:

Powered by Blogger.