Question

C Programming:

Write a function that takes a size DIM array of double's as input and sets every value in the array to zero.

If not too much trouble, please annotate your work (so I'm learning and not just blindly copying), thankyou

The exact info I was given is shown below. I have not idea what size DIM array means.

arrayZero Function The first function you need to write this week is extremely simple. I takes a size DIM array of doubles as input, and sets every value in the array to zero. This is a very small function and should be quite easy, however it will give you important practice in accessing each dimension of a vector.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <stdio.h>
#include<malloc.h>

int main(void)
{
void set(double *,int); //function prototype takes integer and DIM
double *arr;
int dim;
printf("\n Enter the DIMENSION of the array");
scanf("%d",&dim); //Enter the dimension of array
arr=(double *)malloc(dim*sizeof(double)); //dynamically allocate the array
set(arr,dim); //call the function to assign the values to 0
return 0;
}
void set(double *arr,int n)
{
int i;
for(i=0;i<dim;i++) //Loop to access each element of array
*(arr+i)=0; //array 0 to all the elements of array
printf("\n The array elements are");
for(i=0;i<dim;i++)
printf(" %lf",*(arr+i)); //display the elements of array after assign to 0
}
  

OUTPUT

Enter the DIMENSION of the array5 The arrau elements are 0.00 0.00 0.00 0.00 0.00

Add a comment
Know the answer?
Add Answer to:
C Programming: Write a function that takes a size DIM array of double's as input and...
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
  • a) Write a function that takes as input 2 parameters, an array and its size (both...

    a) Write a function that takes as input 2 parameters, an array and its size (both ints) and returns the max. Include the driving (main program also. To pass an array to a function, do the following: return_type my_function(int my_array[], int size) b) Write a function that does the above but can contain duplicate numbers and is capable of removing them. Scan in input. Note you may need the sizeof( ) function which is one of the standard libraries.Thus you...

  • Write program in C++: Function name: Average1D: The Function takes an integer array of 1 Dimension...

    Write program in C++: Function name: Average1D: The Function takes an integer array of 1 Dimension of any size that is given from the main program. The function returns the average of the numbers that less than or equal to 50.

  • C++ ProgrammingWrite a function that takes an integer array, the array size and a number....

    C++ ProgrammingWrite a function that takes an integer array, the array size and a number. And it determines how many times that number appears in the array. Just copy the following code and paste it to your answer. And fill the corresponding part. #include < iostream >using namespace atd; int howmany (int array lint , int number){ //Your code comes here} int main() {const int N =10; int array[N] = [11,3,2,1,3,4,6,9,1.3); int count = howlany(array,N,3);cout << 3 < "appesa" << cout << "times!"; return 0;

  • Write a function with two input parameters: an array of numbers and the size of the...

    Write a function with two input parameters: an array of numbers and the size of the array (the number of elements). The function should return the count of even numbers in the array. For example, if the input to the function is the array [3, 2, 45, 56, 12], the function would return the integer 3. Use the following function header: int countEvens(int nums[], int size) { }

  • Using the programming language Java or C++, Write a function that takes an integer as input....

    Using the programming language Java or C++, Write a function that takes an integer as input. Return true if this integer is a palindrome integer; false otherwise;

  • C programming Write a function that accepts an array of integers as an input, and output...

    C programming Write a function that accepts an array of integers as an input, and output the sum of all values and the multiplication of all values. e.g. Suppose that the array contained the following values: 1 2 3 -4 5. The function should calculate and output the sum of values (i.e. 1+2+3+(-4)+5=7) and the multiplication of all values (i.e. 1*2*3*-4*5=-120). Start by carefully writing the function prototype - put some thought into this. Think about the good programming habits,...

  • Write a C++ function, smallestIndex, that takes as parameters an int array and its size and...

    Write a C++ function, smallestIndex, that takes as parameters an int array and its size and returns the index of the first occurrence of the smallest element in the array. To test your function, write a main that prompts a user for a list of 15 integers and outputs the index and value of the first occurrence of the smallest value. The program should print out Enter 15 integers: The position of the first occurrence of the smallest element in...

  • PYTHON Programming short Questions: 1. Write a function takes as input name (string) and age (number)...

    PYTHON Programming short Questions: 1. Write a function takes as input name (string) and age (number) and prints: My name is <name> and I am <age> years old(where name and age are the inputs) 2. Write a function that takes as input a and b and returns the result of: ??ab 3. Write a function that takes as input a and b and returns the result of: ??ab if it is valid to divide a and b 4. Write a...

  • Write in C. Write a function that takes an array of integers and its size as...

    Write in C. Write a function that takes an array of integers and its size as parameters and prints the two largest values in the array. In this question, the largest value and the second largest value cannot be the same, even if the largest value occurs multiple times. In the first sample, the two largest values are 9 and 8 (even though the value 9 appears twice). In the second sample, all the values are equal and the program...

  • Write a C++ function, lastLargestIndex that takes as parameters an int array and its size and...

    Write a C++ function, lastLargestIndex that takes as parameters an int array and its size and returns the index of the "last occurrence" of the largest element in the array. Include another function to print the array. Also, write a program to test your function. [HINTS) Create an array of size 15 in the main function and initialize it with the values shown in the below sample output. Pass the array and its size to function lastLargestindex; function lastLargestindex returns...

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