1: A + B problem

Source: Internet
Author: User
Total time limit:
1000 ms
Memory limit:
65536kb
Description

Calculate A + B

Input
Two integer a, B (0 ≤ a, B ≤ 10)
Output
Output A + B
Sample Input
1 2
Sample output
3
Prompt
Q: Where are the input and the output?

A: Your program shall always read input from stdin (standard input) and write output to stdout (standard output ). for example, you can use 'scanf' in C or 'cin' in C ++ to read from stdin, and use 'printf' in C or 'cout' in C ++ to write to stdout.

You shall not output any extra data to standard output other than that required by the problem, otherwise you will get a "Wrong answer ".

User Programs are not allowed to open and read from/write to files. You will get a "runtime error" or a "Wrong answer" if you try to do so.

Here is a sample solution for problem 1000 using C ++/g ++:
[CPP]View plaincopyprint?
  1. # Include <iostream>
  2. Using namespace STD;
  3. Int main ()
  4. {
  5. Int A, B;
  6. Cin> A> B;
  7. Cout <a + B <Endl;
  8. Return 0;
  9. }

It's important that the return type of main () must be int when you use g ++/GCC, or you may get compile error.

Here is a sample solution for problem 1000 using C/GCC:
[CPP]View plaincopyprint?
  1. # Include <stdio. h>
  2. Int main ()
  3. {
  4. Int A, B;
  5. Scanf ("% d", & A, & B );
  6. Printf ("% d \ n", A + B );
  7. Return 0;
  8. }

Here is a sample solution for problem 1000 using Pascal:
[Plain]View plaincopyprint?
  1. Program p1000 (input, output );
  2. VaR
  3. A, B: integer;
  4. Begin
  5. Readln (A, B );
  6. Writeln (A + B );
  7. End.

Here is a sample solution for problem 1000 using Java:

Now Java compiler is JDK 1.5, next is program for 1000
[Java]View plaincopyprint?
  1. Import java. Io .*;
  2. Import java. util .*;
  3. Public class main
  4. {
  5. Public static void main (string ARGs []) throws exception
  6. {
  7. Cin = new partition (system. In );
  8. Int A = cin. nextint (), B = cin. nextint ();
  9. System. Out. println (A + B );
  10. }
  11. }

Old program for JDK 1.4.
[Java]View plaincopyprint?
  1. Import java. Io .*;
  2. Import java. util .*;
  3. Public class main
  4. {
  5. Public static void main (string ARGs []) throws exception
  6. {
  7. Bufferedreader stdin =
  8. New bufferedreader (
  9. New inputstreamreader (system. In ));
  10. String line = stdin. Readline ();
  11. Stringtokenizer ST = new stringtokenizer (line );
  12. Int A = integer. parseint (St. nexttoken ());
  13. Int B = integer. parseint (St. nexttoken ());
  14. System. Out. println (A + B );
  15. }
  16. }
Source code:

 
  
 
 
[Java]View plaincopyprint?
  1. <PRE name = "code" class = "CPP"> int main (void)
  2. {
  3. Int A, B;
  4. Scanf ("% d", & A, & B );
  5. Printf ("% d", A + B );
  6. Return 0;
  7. }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.