Computer Science, asked by rakshanivasini31, 6 months ago

Write a program to input a number. Evaluate and display the results based on the number entered by the user: a) Natural logarithm of the number b) Absolute value of the number c) Square root of the number d) Cube of the number e) Random numbers between 0 (zero) and 1 (one)

Answers

Answered by luisecubero77
9

Answer:

Python

Explanation:

import math

import random

number=int(input("Number: "))

print("a) Natural logarithm of the number")

print("b) Absolute value of the number")

print("c) Square root of the number")

print("d) Cube of the number")

print("e) Random numbers between 0 (zero) and 1 (one)")

opc=input("Choose option: ")

if opc == "a":

   if number > 0:

      print(math.log(number))

   else:

      print("No natural logarithm of zero of negative")  

if opc == "b":

   print(abs(number))

if opc == "c":

   if number > 0:

      print(math.sqrt(number))

   else:

      print("No Square root of negative number")  

if opc == "d":

   print(pow(number,3))

if opc == "e":

   print(random.uniform(0, 1))

Attachments:
Answered by SnehaKesharwani
12

Answer:

import java.util.Scanner;

public class Number

{

public static void main(String args[]) {

Scanner in = new Scanner(System.in);

System.out.print("Enter Number: ");

double n = in.nextDouble();

System.out.println("Natural logarithm = " + Math.log(n));

System.out.println("Absolute value = " + Math.abs(n));

System.out.println("Square root = " + Math.sqrt(n));

System.out.println("Cube root= " + Math.cbrt(n));

System.out.println("Random number = " + Math.random());

}

}

Similar questions