Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a function, called constantMultiple , that multiplies positive values in an array by a constant and multiplies negative values in an array by a

Write a function, called constantMultiple, that multiplies positive values in an array by a constant and multiplies negative values in an array by a different constant. Print out the resulting array after your function is called.

Function outputs: the modified array (arrays are automatically passed by pointer so your function should return void)

Function inputs: an array, the size of the array, an integer to multiply the positive values by, an integer to multiply the negative values by

Example output with a positive multiplier of 2 and a negative multiplier of 4 entered in as [2, 4]:

 Positive multiplier and negative multiplier [P, N]: Seed: Original array: 6 -9 -7 2 -5 9 -10 9 8 -3 Modified array: 12 -36 -28 4 -20 18 -40 18 16 -12 

USE THE TEMPLATE PROVIDED BELOW

#include

#include

// WRITE FUNCTION HERE. Your function must be called constantMultiple.

int main( void )

{

// declare 2D array

const int SIZE = 10;

int sig[SIZE];

// read in positive and negative multipliers

int pos, neg;

printf("Positive multiplier and negative multiplier [P, N]: ");

scanf("[%d,%d]", &pos, &neg);

// read in seed point

int seed;

printf("Seed: ");

scanf("%d", &seed);

srand( seed );

// fill array with random values between -10 and 10

printf("Original array: ");

for( int i = 0; i < SIZE; i++) {

sig[i] = rand()%20-10; // put random value into array

printf("%3d ", sig[i]); // print our array

}

printf(" ");

// CALL FUNCTION HERE

constantMultiple( sig, SIZE, pos, neg );

// PRINT OUT ARRAY RESULTS HERE

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Sybase Database Administrators Handbook

Authors: Brian Hitchcock

1st Edition

0133574776, 978-0133574777

More Books

Students also viewed these Databases questions