Number of Numbers (10 pts)
Enter the number of numbers:
Enter the number of numbers: 4
Enter 4 numbers:
Number 1: 3.2
Number 2: 6.7
Number 3: 2.9
Number 4: 4.6
The sum of the numbers is: 17.4
And the product is: 286.0
Enter the number of numbers: 8
Enter 8 numbers:
Number 1: 2.1
Number 2: -5.6
Number 3: 9.0
Number 4: 8.7
Number 5: -2.2
Number 6: 8.2
Number 7: 9.5
Number 8: 1.4
The sum of the numbers is: 31.1
And the product is: 220931.3
**Please don't use format to do this one.
import java.util.Scanner; import java.lang.Math; public class Nums { public static void main(String[] args) { /* creating the scanner object */ Scanner s = new Scanner(System.in); System.out.print("Enter the number of numbers: "); /* scanning the length of array */ int n = s.nextInt(); /* declaring the integer array with the size n */ double arr[] = new double[n]; /* initializing the variables to store sum and product of elements of array */ double sum = 0; double product = 1; System.out.println("Enter " + n + " numbers:\n"); /* scanning the user input for array */ for (int i = 0; i < n; i++) { /* scanning the array elements */ System.out.print("Number " + (i + 1) + " : "); arr[i] = s.nextFloat(); /* calculating the sum and product of elements */ sum = sum + arr[i]; product = product * arr[i]; } /* rounding the results to one decimal place */ sum = Math.round((sum) * 10.0) / 10.0; product = Math.round((product) * 10.0) / 10.0; /* displaying the result */ System.out.println(); System.out.println("The sum of the numbers is: " + sum); System.out.println("And the product is: " + product); } }
o/p:
For help please comment.
Number of Numbers (10 pts) For this assignment you will be working with arrays. Open a...
1. Write a program that reads in two arrays (a1 and a2) of numbers and creates a new array (a3) of numbers such that the new array contains all the unique numbers of a1 and a2. Assume the input array elements are unique elements. In the main function, ask the user to enter the length of each array, declare and reads in the numbers for each array, and calculate and display the output array. Example input/output #1: Enter the length...
1. print mesage to user to prompt user to enter 10 numbers 2 have program accept 10 numbers from user and populate 10 occurrances of an array (use a loop to do this). 3. print message to user to advise user contents of array follows 4. have program display array contents (use loop to do this) end program comment in java please
need help!! c++ HW_6b - Calculate the average Use a do-while loop Write a program that first prompts the user for an upper limit: Enter the number of entries: 5 € (user enters 5) After the user enters a number, the program should prompt the user to enter that many numbers. For example, if the user enters 5, then the program will ask the user to enter 5 values. Use a do-while loop to add the numbers. o With each...
Using Java In this assignment we are working with arrays. You have to ask the user to enter the size of the integer array to be declared and then initialize this array randomly. Then use a menu to select from the following Modify the elements of the array. At any point in the program, if you select this option you are modifying the elements of the array randomly. Print the items in the array, one to a line with their...
Ask uFor Ex. "Prompt user to enter a number" = user enters 10, your program should output 1, 2, 3, 4, 5, 6, 7, 8, 9, 10.ser to input a number, and then using a loop control statement (While, For, Do-While), output to the console the numbers beginning from 1, up to and including the number input by the user.
USE C++ 2.) Write a program that will prompt the use to enter 10 numbers in an array, then display: the 1st, the 5th and the last number. Example, if the user entered 1 2 3 4 5 6 7 8 9 10, the output shall be: 1st is 1 5th is 5 last is 10
FUNCTIONS In this assignment, you will revisit reading data from a file, and use that data as arguments (parameters) for a number of functions you will write. You will need to: Write and test a function square_each(nums) Where nums is a (Python) list of numbers. It modifies the list nums by squaring each entry and replacing its original value. You must modify the parameter, a return will not be allowed! Write and test a function sum_list(nums) Where nums is a...
Thank you! /*Lab 8 : Practicing functions and arrays Purpose: */ #include<iostream> #include<fstream> using namespace std; int read_function(int array[], int, int); int main() { int array[300], numba; read_function(array[300]); cout << "Enter a whole number between 2-20: " << endl; cin >> numba; read_function(numba); return 0; } int read_funtion (int arr[300], int num, int Values) { int sum=0; ifstream array_file; array_file.open("Lab8.dat"); for(int i=0; i < 300; i++) { array_file >> arr[i]; cout << arr[i]; sum += i; } cout << sum;...
In this assignment, you will revisit reading data from a file, and use that data as arguments (parameters) for a number of functions you will write. You will need to: Write and test a function square_each(nums) Where nums is a (Python) list of numbers. It modifies the list nums by squaring each entry and replacing its original value. You must modify the parameter, return will not be allowed! Write and test a function sum_list(nums) Where nums is a (Python) list...
use c++ language, keep it simple i am using code block Exercise#2: Arrays with Random Numbers Write a program that generates n random numbers as follows: Asks the user to input a positive integer n Asks the user to input the maximum value (say m) for the integers to be generated. Write a program that generates the n numbers in the range 0 to m. The program stores the generated numbers in an array A[ Asks the user to enter...