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

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...
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
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
Write Program in C: Write a program that: program starts; declares and initializes to 7.25% constant...
Write Program in C: Write a program that: program starts; declares and initializes to 7.25% constant float variable NJSALES_TAX; declares and initializes to 1000 an integer variable total; declares and initializes to zero a float variable grand_total; prompt and input on new line total; calculate grand_total to equal total plus (total*NJSALES_TAX); if grand_total <= 1000 print on new line “Grand total is less than or equal to 1000 it is $” and the grand_total to two decimal places; else if...
Write a program that initializes an array of 6 random integers and then prints 4 lines...
Write a program that initializes an array of 6 random integers and then prints 4 lines of output, containing the following: 1. Only the first and last element 2. Every element at an odd index 3. Every odd element 4. All elements in reverse order
C programming. Write a program that prompts the user to enter a 6x6 array with 0...
C programming. Write a program that prompts the user to enter a 6x6 array with 0 and 1, displays the matrix, and checks if every row and every column have the even number of 1’s.
Using the C Programming language, write a program that sums an array of 50 elements. Next,...
Using the C Programming language, write a program that sums an array of 50 elements. Next, optimize the code using loop unrolling. Loop unrolling is a program transformation that reduces the number of iterations for a loop by increasing the number of elements computed on each iteration. Generate a graph of performance improvement. Tip: Figure 5.17 in the textbook provides an example of a graph depicting performance improvements associated with loop unrolling. Marking:- Optimize the code for an array of...
The C++ program below simply copies the contents of one file to another file using standard...
The C++ program below simply copies the contents of one file to another file using standard in and standard out. Do a line-by-line conversion of the complete program into a closely equivalent C program that produces the same output given the same input. Note that the underscores are used solely to force indentation in Canvas. #include using namespace std; int main(void) { char symbol; cin.get(symbol); while (!cin.eof()) ___ { ___ cout.put(symbol); ___ cin.get(symbol); ___ } return 0; }
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT