Ad Code

Responsive Advertisement

Adding Two numbers by using user input in all language's code available PYTHON,JAVA,C,CPP

 Adding Two Numbers by using user input

PYTHON,JAVA,C,CPP

Python code

number1 = int(input("Enter the first number: "))

number2 = int(input("Enter the second number: "))

sum_result = number1 + number2

print("The sum is: ", sum_result)



Java code

import java.util.Scanner;


public class AddNumbers {

    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);

        System.out.print("Enter the first number: ");

        int num1 = input.nextInt();

        System.out.print("Enter the second number: ");

        int num2 = input.nextInt();

        int sumResult = num1 + num2;

        System.out.println("The sum is: " + sumResult);

        input.close();

    }

}



C code

#include <stdio.h>


int main() {

    int num1, num2, sumResult;

    printf("Enter the first number: ");

    scanf("%d", &num1);

    printf("Enter the second number: ");

    scanf("%d", &num2);

    sumResult = num1 + num2;

    printf("The sum is: %d\n", sumResult);

    return 0;

}




C++ code

#include <iostream>

int main() {
    int num1, num2, sumResult;
    std::cout << "Enter the first number: ";
    std::cin >> num1;
    std::cout << "Enter the second number: ";
    std::cin >> num2;
    sumResult = num1 + num2;
    std::cout << "The sum is: " << sumResult << std::endl;
    return 0;
}

Post a Comment

0 Comments

Close Menu