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;
}
0 Comments