About the A+b+c problem three languages solution, Java, C language, Python

Source: Internet
Author: User

The original question is this way:

This is a very simple topic, designed to examine your basic ability to program. Don't think it's hard. Enter a row that includes three integers, a, B, and C separated by a space (the data range is between -40~40). The output is one row, the result of the "a+b+c" calculation.
Sample 1

Input:

22 1 3

Output:

26

Since I have just come in contact with Python, so the code is a bit long, I hope there is great God can point out, help me improve, I am grateful. Let's start with my code, in the order of Java, C, Python

Java:

Import Java.util.Scanner;
Class Main
{public
   static void Main (string[] args)  
   {   
          int a,b,c;
         Scanner input=new Scanner (system.in);
        A=input.nextint ();
        B=input.nextint ();
        C=input.nextint ();
         if ((a>=-40&&a<=40) && (b>=-40&&b<=40) && (c>=-40&&c<=40) )
        System.out.println (a+b+c);
        else
        System.out.println ("Erro");
    }

C Language:

#include <stdio.h>
int main (void) {
    int A, b, C;
    scanf ("%d%d%d", &a, &b, &c);
    if (A > | | A < -40 | | b > | | | b < -40 | | c > | | | c < -40) return
        0;
    printf ("%d", a+b+c);
    
    return 0;
}

Python:

LST = Raw_input (). Split (")
sum = 0 for
i in LST:
    sum = sum+int (i)
print sum


As for other languages, such as what C++/ruby, not yet. Just a little bit of the three languages posted. Also hope to master a lot of advice.

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.