Skip to main content

Featured

say hello world with C++ - Solution in Hacker Rank - hackerranksolutions8

  Objective This is a simple challenge to help you practice printing to  stdout . You may also want to complete  Solve Me First  in C++ before attempting this challenge. We’re starting out by printing the most famous computing phrase of all time! In the editor below, use either  printf  or  cout  to print the string  Hello ,World!  to  stdout . The more popular command form is  cout . It has the following basic form: cout<<value_to_print<<value_to_print; Any number of values can be printed using one command as shown. The  printf  command comes from C language. It accepts an optional format specification and a list of variables. Two examples for printing a string are: printf("%s", string);   printf(string); Note that neither method adds a newline. It only prints what you tell it to. Output Format Print   Hello ,World!   to stdout. Sample Output Hello, World! Solution:- //Say Hello, World! With C++ - Hacker Rank Solution #include <iostream> #include <cstdio

Input and Output in C++ – Solution in Hacker Rank - hackerranksolutions8

 

Problem

Objective

In this challenge, we’re practicing 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;

The above code reads the first word (“High”) from stdin and saves it as string s, then reads the second word (“5”) from stdin and saves it as integer n. If we want to print these values to stdout, we write the following code:

cout << s << " " << n << endl;

The above code prints the contents of string s, which is the word “High”. Then it prints a single space (” “), followed by the contents of integer n. Because we also want to ensure that nothing else is printed on this line, we end our line of output with a newline via endl. This results in the following output:

High 5

Task

numbers from stdin and print their sum to stdout.Note: If you plan on completing this challenge in C instead of C++, you’ll need to use format specifiers with printf and scanf.

Input Format

A single line containing 3 space-separated integers: ab and c.

Constraints

  •  1<=a,b,c<=1000

Output Format

Print the sum of the three numbers on a single line.


Sample Input

1 2 7

Sample Output

10

Explanation :

The sum of the three numbers is  1 + 2 + 7 = 10.


Solution :

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

int main() 
{
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */  
    int a,b,c,d;
    cin >>a >>b >>c;
    d = a+b+c;
    cout<<d;
    return 0;
}

Comments

Popular Posts