Question

Create a function that takes two parameters : pointer to the array and the size of...

Create a function that takes two parameters : pointer to the array and the size of the array. Print out the array's values and their memory addresses inside the function. Then create another function that takes two parameters : pointer to the array. Inside the function, multiply each of the array's values by two ad print the modified values out in the main function.
With C programming language

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


ANSWER:-

CODE:-

#include <stdio.h>
void multiplyAd(int *a, int n){
   int i,mul;
   mul = *a * *(a+1);
   *(a) = mul;
   for(i=1;i<n-1;i++){
       mul = *(a+i-1) * *(a+i+1) * *(a+i);
       *(a+i) = mul;
   }
   *(a+i) = *(a+i) * *(a+i-1);
}
void printValues(int *a,int n){
   int i;
   for(i=0;i<n;i++){
       printf("Address:%d\tValue:%d\n",(a+i),*(a+i));
   }
   printf("\n");
}
int main(){
   int a[] = {1,2,3,4,5};
   int *arr = a;
   printValues(arr,5);
   multiplyAd(arr,5);
   printf("After calling multiplyAd function:\n");
   printValues(arr,5);
}

NOTE:- If you have any modifications in the code, please comment below.Please give positive rating.THUMBS UP.

                  THANK YOU!!!

OUTPUT:-

Add a comment
Know the answer?
Add Answer to:
Create a function that takes two parameters : pointer to the array and the size of...
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
  • -Create a function output() in C that takes the pointer to the array and its size...

    -Create a function output() in C that takes the pointer to the array and its size and prints the arrays' contests. (malloc format) (function prototype : void output(int *arrayPtr, int size); -Create a function check() in C that takes the pointer to the array and a number and checks if the number is in the array. If the number is in the array, returns the index of the element of the array holding the number. Otherwise, returns -1.

  • C++ Write a function that takes as input parameters (using call by pointer) 3 integers. It...

    C++ Write a function that takes as input parameters (using call by pointer) 3 integers. It generates a random number between 25 and 50 (not including 50). It then creates an array on the memory heap of that length. It generates a random high number (mine was between 5 and 10) and a random low number (between -5 and -10) and fills in the array iteratively with random numbers between the high and the low numbers*, and it returns that...

  • C language 3. (10 pts) Write a function readSegment that takes three parameters, a float array...

    C language 3. (10 pts) Write a function readSegment that takes three parameters, a float array as a pointer p as the first parameter, and two int indices startldx and endldx. The function readSegment reads the content of the array between startIdx and endldx, without using additional local variables. 4. (10 pts) Write a function called doubleOdds that takes two parameters, an array of double pointed to by pointer p and endldx of int type. The function doubleOdds doubles (multiply...

  • 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...

  • A function that takes three parameters: an int array, an int n that is the size...

    A function that takes three parameters: an int array, an int n that is the size of the array and an int pointer max that is to assign the maximum value in the array. The function will find and return the index of the first occurrence of the maximum value in the array and assign the maximum value to the pointer. For example, in the array {1, 2, 6, 5, 6, 4, 3, 6, 4}, the maximum value is 6...

  • Homework Question Write a void function called transformArray that takes two parameters - a reference to...

    Homework Question Write a void function called transformArray that takes two parameters - a reference to a pointer to a dynamically allocated array of ints, and the size of that array.  The pointer is passed by referencebecause you want to change the value of the pointer. The function should dynamically allocate an array that is twice as long, filled with the values from the original array followed by each of those values times 2. For example, if the array that was...

  • 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...

  • In c++ 1. Write a function named findTarget that takes three parameters - numbers: an array...

    In c++ 1. Write a function named findTarget that takes three parameters - numbers: an array of integers size: an integer representing the size of array target: a number The function returns true if the target is inside the array and false otherwise 2. Write a function min Valve that takes two parameters: myArray an array of doubles - size: an integer representing the size of array The function returns the smallest value in the array 3 Wrile a funcion...

  • 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...

  • Create 3 variables, (int, chart and float) and give give each of them some value. Print...

    Create 3 variables, (int, chart and float) and give give each of them some value. Print out the values. Then create a pointer for each variable and initialize the pointers. Then make them point to the memory address of the corresponding variables. Print out the pointers (=memory addresses where the pointers point to, use %p). Finally, print out the values that are in the memory locations where the pointers point to(so print out the values using the pointers, not the...

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