Python
1-program to add two numbers
num1=30
num2=40
print("The sum of given two number is",num1+num2)
2-program to calculate the area of triangle
height = float(input("enter the height of the triangle: "))
base = float(input("enter the base of the triangle: "))
3-program to find the square root
#1-(using Exponentiotion)
#num= 64
#num1 = int(input("enter a number here: "))
#sr = num1**(1/2)
#print("the sqaure root of the given number is",sr)
#2- (using math module)
import math
num = int(input("enter a number here:"))
sr = math.sqrt(num)
print("the square root of the given number is",sr)
area = (1/2)*base*height
print ('the area of the triangle is',area)
compiler
Adding Two Numbers
import java.util.Scanner;
public class AddTwoNumbers {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Input from the user
System.out.print("Enter the first number: ");
int num1 = scanner.nextInt();
System.out.print("Enter the second number: ");
int num2 = scanner.nextInt();
// Adding the numbers
int sum = num1 + num2;
// Displaying the result
System.out.println("Sum: " + sum);
// Closing the scanner
scanner.close();
}
Program 2: Finding the Factorial of a Number
import java.util.Scanner;
public class Factorial {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Input from the user
System.out.print("Enter a number: ");
int n = scanner.nextInt();
// Finding the factorial
long factorial = findFactorial(n);
// Displaying the result
System.out.println("Factorial of " + n + ": " + factorial);
// Closing the scanner
scanner.close();
private static long findFactorial(int n) {
if (n == 0 || n == 1) {
return 1;
} else {
return n * findFactorial(n - 1);