Question

In: Computer Science

In C programming: Write a program that initializes an array-of-double and then copies the contents of...

In C programming:

Write a program that initializes an array-of-double and then copies the contents of the array into another arrays. To make the copy, use a function with array notation. This function takes two arguments the name of the target array and the number of elements to be copied. That is, the function calls would look like this, given the following declarations:

double source[5] ={1.1, 2.2, 3.3., 4.4, 5.5};

double target1[5];

double target2[5];

copyarr(source, target1, 5);

Solutions

Expert Solution

ANSWER: Here I am giving you the code and output before going to dislike please comment on your problem I will definitely help you. If it is helpful please like it.

CODE:

#include <stdio.h>
void copyarr(double source[], double target1[], int size){
int i;
for(i=0;i<size;i++){
target1[i]=source[i];
}
}
int main()
{
double source[5] ={1.1, 2.2, 3.3, 4.4, 5.5};
double target1[5];
double target2[5];
copyarr(source, target1, 5);// first time calling function copyarr() to copy source array to target1 array.
int i;
printf("target1 array content after copy from source array:\n");
for(i=0;i<5;i++){
printf("%.1lf ",target1[i]);
}
copyarr(source, target2, 5);// second time calling function copyarr() to copy source array to target1 array.
printf("\ntarget2 array content after copy from source array:\n");
int j;
for(j=0;j<5;j++){
printf("%.1lf ",target2[j]);
}
return 0;
}

OUTPUT:


Related Solutions

1. a. In C++, Write a program that creates an array of 20 integers and initializes...
1. a. In C++, Write a program that creates an array of 20 integers and initializes it with the even values starting from 200. i.e. 200, 202, 204…. b. Write the elements of the array to the file even.txt, each element on a separate line. Try to use a single for loop for initializing the array and writing to file. You will need a separate counter for initializing the array. 2. a. Write another program that opens the file even.txt...
In C, write a program that initializes a 3D array (the exact size doesn't matter) that...
In C, write a program that initializes a 3D array (the exact size doesn't matter) that contain what ever arbitrary integers and print out the array including the elements and use different functions so that the main only contains variables and function calls.
C Programming Write a program in C that reads in a file, stores its contents as...
C Programming Write a program in C that reads in a file, stores its contents as a character array/pointer (char*) into an unsigned character array/pointer (unsigned char* message). Note: the input file can have one line or multiple lines and vary in length
Write a program that copies the contents of one file to a destination file. This program...
Write a program that copies the contents of one file to a destination file. This program works by first prompting the user for the name of the source and destination files. Be sure to include all necessary error checking, including ensuring that the source file exists. Also, if available, you have to use Linux system calls and not standard C library functions in your program. Write/type your source code in your submission file/document. [Restrictions] For file handling operations, only use...
Write a small C program connect.c that: 1. Initializes an array id of N elements with...
Write a small C program connect.c that: 1. Initializes an array id of N elements with the value of the index of the array. 2. Reads from the keyboard or the command line a set of two integer numbers (p and q) until it encounters EOF or CTL - D 3. Given the two numbers, your program should connect them by going through the array and changing all the entries with the same name as p to have the same...
Write a small C program connect.c that: 1. Initializes an array id of N elements with...
Write a small C program connect.c that: 1. Initializes an array id of N elements with the value of the index of the array. 2. Reads from the keyboard or the command line a set of two integer numbers (p and q) until it encounters EOF or CTL - D 3. Given the two numbers, your program should connect them by going through the array and changing all the entries with the same name as p to have the same...
Write a C++program that initializes an array called resistances with the following initializer list: from file...
Write a C++program that initializes an array called resistances with the following initializer list: from file called "resistances. txt" {12.3, 98.5, 15.15, 135, 125} Using a while-loop, compute the sum of the elements of the resistances array and then obtain the average resistance and d isplay it. Then, use another loop to display the resistances that has value smaller than the average resistance that
Programming in C++ Write a program that prints the values in an array and the addresses...
Programming in C++ Write a program that prints the values in an array and the addresses of the array’s elements using four different techniques, as follows: Array index notation using array name Pointer/offset notation using array name Array index notation using a pointer Pointer/offset notation using a pointer Learning Objectives In this assignment, you will: Use functions with array and pointer arguments Use indexing and offset notations to access arrays Requirements Your code must use these eight functions, using these...
Programming In C Write a program that prints the values in an array and the addresses...
Programming In C Write a program that prints the values in an array and the addresses of the array’s elements using four different techniques, as follows: Array index notation using array name Pointer/offset notation using array name Array index notation using a pointer Pointer/offset notation using a pointer Learning Objectives In this assignment, you will: Use functions with array and pointer arguments Use indexing and offset notations to access arrays Requirements Your code must use these eight functions, using these...
Write a program in Java that initializes an array with ten random integers and then print...
Write a program in Java that initializes an array with ten random integers and then print three lines of output, containing: Every element at an odd index Every odd element All elements in reverse order   The program should use three different methods to implement the functionalities above. Call the primary source file ArrayManipulator.java
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT