Question

In C code prompt and read from the user an integer number, 'N', of double precision...

In C code prompt and read from the user an integer number, 'N', of double precision floating point numbers to allocate for the purpose of the current test run. Dynamically allocate an array of N double precision floating point numbers; i.e. the array will require "N*sizeof(double)" bytes of RAM for storage, call this M.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <stdio.h>
#include <malloc.h>

int main() {
    int i, N;
    double *M;
    printf("How many doubles? ");
    scanf("%d", &N);
    M = malloc(N*sizeof(double));
    printf("Enter %d double precision numbers: ", N);
    for (i = 0; i < N; ++i) {
        scanf("%lf", M+i);
    }

    printf("You entered: ");
    for (i = 0; i < N; ++i) {
        printf("%lf ", M[i]);
    }
    printf("\n");
    free(M);
    return 0;
}
Add a comment
Know the answer?
Add Answer to:
In C code prompt and read from the user an integer number, 'N', of double precision...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • write a c++ program that prompts a user for a number then attempts to allocate an...

    write a c++ program that prompts a user for a number then attempts to allocate an array of as many integers as the user enters. In other words, the program might prompt the user with a line like: “How many integers would you like to allocate?” It should then allocate as many integers as the user enters. The program should then wait for the user to press enter before deleting the allocated array and quitting. We will use this time...

  • Here is the Prompt for problem 1: Write a C++ program that reads in a test file. The first numbe...

    Here is the Prompt for problem 1: Write a C++ program that reads in a test file. The first number in the file will be an integer, and will indicate the amount of decimal numbers to follow. Once you have the read the numbers from the file into an array then compute the following properties on the set of numbers: the sum, the average (mean), the variance, the standard deviation, and the median. Don’t try to do the entire program...

  • Write a program that prompts the user to enter an integer, n , and then n...

    Write a program that prompts the user to enter an integer, n , and then n floating point numbers. As the numbers are read, the program will calculate the average of the negative numbers. In C language.

  • Write a C code that can store a floating point number to any accuracy specified by the user. For instance, both float and double have round-off errors due to their data sizes, i.e. 4 bytes and 8 bytes...

    Write a C code that can store a floating point number to any accuracy specified by the user. For instance, both float and double have round-off errors due to their data sizes, i.e. 4 bytes and 8 bytes, respectively. Implement a C function that can store a floating number to any user specified round-off error.

  • Write a code segment as specified below. // 1. Prompt the user to enter a positive...

    Write a code segment as specified below. // 1. Prompt the user to enter a positive integer number (say n). // 2. Calculate the sum of all the reciprocals of the numbers from 1 to n. For example, sum = (1 / 1) + ( 1 / 2 ) + ( 1 / 3) + ( 1 / 4 ) + … + ( 1 / n ) // 3. Print out the integer number and the sum. • NOTE:...

  • 1. Prepare C++ code that prompts the user for an input integer n, creates a vector...

    1. Prepare C++ code that prompts the user for an input integer n, creates a vector consisting of numbers 0,1,2,…,n-1, runs the STL algorithm random_shuffle on it and then prints out the resulting outcome, i.e. the resulting random permutation. 2. Prepare C++ code that prompts the user for an input integer n, creates a vector consisting of numbers 0,1,2,…,n-1, runs the STL algorithm random_shuffle on it and creates three copies of the resulting outcome (probably 3 .txt files).

  • Assembly Language////Write a program that read in 10 integers from the user. Save the numbers into...

    Assembly Language////Write a program that read in 10 integers from the user. Save the numbers into an array; reverse the array and display the reversed array. .data arrayInt DWORD 10 DUP(?) Your program consists of 4 procedures: 1. main procedure: call procedures getInput, reverseArray, displayArray 2. getInput procedure: prompt user to enter 10 integer numbers, save the numbers into the memory for the arrayInt 3. reverseArray: reverse arrayInt 4. displayArray: display the reversed array

  • Write a complete C++ program that do following. 1) Read a positive integer from the user...

    Write a complete C++ program that do following. 1) Read a positive integer from the user with proper prompt. Assume that this user is nice and he/she would not start the integer with digit 0. 2) Create a size 10 array as counters for digits 0 - 9. 3) Use a while loop for processing a) Single out the current last digit using modular 10 technique b) Increment the corresponding counter through the index derived in a). 4) At the...

  • . In the method main, prompt the user for a non-negative integer and store it in...

    . In the method main, prompt the user for a non-negative integer and store it in an int variable num (Data validation is not required for the lab). Create an int array whose size equals num+10. Initialize the array with random integers between 0 and 50 (including 0 and excluding 50). Hint: See Topic 4 Decision Structures and File IO slides page 42 for how to generate a random integer between 0 (inclusive) and bound (exclusive) by using bound in...

  • C Programming For this task, you will have to write a program that will prompt the...

    C Programming For this task, you will have to write a program that will prompt the user for a number N. Then, you will have to prompt the user for N numbers, and print then print the sum of the numbers. For this task, you have to create and use a function with the following signature: int sum(int* arr, int n); Your code should look something like this (you can start with this as a template: int sum(int* arr, int...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT