Question

1. All functions should be written AFTER the main procedure. 2. A function prototype should be...

1. All functions should be written AFTER the main procedure.
2. A function prototype should be written for each function and placed BEFORE the main
procedure.
3. Each function should have a comment explaining what it does.
4. Each function parameter should have a comment explaining the parameter.
5. Prompt for the number of elements of the list.
6. Allocate an array whose size equals the number of elements specified by the user.
7. Read into the array the elements of the list.
8. Write a function count() which counts the number of negative elements and the number of
non-negative elements of an array. The function should take four parameters, the array, the
number of elements in the array, the number of negative elements and the number of nonnegative
elements.
The function sets the number of negative and non-negative elements but does not return any
value.
9. In the main program, call the function count() to get the number of negative elements and
the number of non-negative elements of the array.
10. Allocate an array whose size equals the number of negative elements.

12. Write a function split() which takes as input 3 arrays, A, B, and C, and stores the negative
elements of A in B and the non-negative elements of A in C. (Use better array names than A,
B, and C). The size of array B should be exactly the number of negative elements in array A.
The size of array C should be exactly the number of non-negative elements in A.
As you copy elements from A to B or C, count the number of elements copied to each array.
When the function completes, check that the number copied equals exactly the array size. If
it does not, print an error message and exit.
The function should take six parameters, array A, the size of array A, array B, the size of
array B, array C, and the size of array C.
The function modifies arrays B and C but does not return any value.
13. Write a function print_array() which prints the elements of an array.
The function should take two parameters, the array and the array length.
The function does not modify or return any values.

14. In the main program, call the function split(), passing the input array and the arrays
whose sizes equal the number of even and odd elements.
15. In the main program, print the phrase

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

#include <stdio.h>
void count(int arr[],int len,int *x, int *y);
void split(int *arr[],int *neg[],int *pos[],int Alen,int Blen,int Clen);
void print_array(int arr[],int length);
int main()
{
int elements; /*to store elements given by user */
printf("Enter how many elements you want\n");
scanf("%d",&elements);
int array[elements]; /* allocating array of of size user entered*/
int i; /* variable used for for loop to read values into integer*/
int negative=0,nonnegative=0;/* negative and non-negative store values */
for(i=0;i<elements;i++){
printf("enter number");
scanf("%d",&array[i]);
}
count(array,elements,&negative,&nonnegative);
int negative[negative]; /* declaring negative arrray */
int positive[nonnegative];
split(&array,&negative,&positive,sizeof(array),sizeof(negative),sizeod(positive));

printf("Now printing arrays\n");
print_array(array,size0f(array)); /* printing array */
print_array(negative,size0f(negative));
print_array(positive,size0f(positive));
free(array); /* making array free */
free(positive);
free(negative);
return 0;
}
void count(int arr[],int len,int *x, int *y){ /* counting values negative and non negative */
int i;
for(i=0;i<len;i++){
if(arr[i]<0){
*y++;
}
else{
*x++;
}
}
}
void split(int *arr[],int *neg[],int *pos[],int Alen,int Blen,int Clen){/* split and fill arrays*/
int i,countneg=0,countpos=0; /* calculating array for my loop and count is for checking elements */
for(i=0;i<Alen;i++){
if(*arr[i]<0){
*neg[i]=*arr[i];
countneg++;
}
else{
*pos[i]=*arr[i];
countpos++;
}
}
if(countneg!=Blen){
printf("error occured");
exit(0);
}
if(countpos!=Clen){
printf("error occured");
exit(0);
}
}
void print_array(int arr[],int length){/* printing the arrays*/
int i;/* for loop variable*/
for(i=0;i<length;i++){
printf("%d",&arr[i]);
}
printf("\n");
}

output

Enter how many elements you want 5

enter number 1

enter number 2

enter number -1

enter number -2

enter number 3

Now printing arrays

1 2 -1 -2 3

-1 -2

1 2 3

Add a comment
Know the answer?
Add Answer to:
1. All functions should be written AFTER the main procedure. 2. A function prototype should be...
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
  • in C++ and also each function has its own main function so please do the main...

    in C++ and also each function has its own main function so please do the main function as well. Previously when i asked the question the person only did the function and didn't do the main function so please help me do it. 1-1. Write a function that returns the sum of all elements in an int array. The parameters of the function are the array and the number of elements in the array. The function should return 0 if...

  • Code written in NASM Function called findLargest Write a function called findLargest that receives two parameters:...

    Code written in NASM Function called findLargest Write a function called findLargest that receives two parameters: an unsigned doubleword array and the length of the array. The function must return the value of the largest array member in eax. Preserve all registers (except eax) that are modified by the function. Write a test program in main that calls findLargest three times, each call using a different array with different lengths. Function called countHits Write a function called named countHits that...

  • In C++, write two functions named printArray and deleteRepeats along with a main to test them...

    In C++, write two functions named printArray and deleteRepeats along with a main to test them according to the following specifications. Be sure to use function prototypes and place the actual function definitions after main. printArray will take two parameters: an array of characters and an integer representing the number characters stored in the array. It will print the characters from the array, labeled by their index, to the screen up to the specified size. deleteRepeats will take the same...

  • IN C++ ADD COMMENTS AS MUCH AS POSSIBLE Exercise 1: Duplicate the Arrays Suppose you are...

    IN C++ ADD COMMENTS AS MUCH AS POSSIBLE Exercise 1: Duplicate the Arrays Suppose you are developing a program that works with arrays of integers, and you find that you frequently need to duplicate the arrays. Rather than rewriting the array-duplicating code each time you need it, you decide to write a function that accepts an array and its size as arguments. Creates a new array that is a copy of the argument array, and returns a pointer to the...

  • 4. [8] Write a C function with prototype void letter_freq(const char wordll, int freaq ); This...

    4. [8] Write a C function with prototype void letter_freq(const char wordll, int freaq ); This function computes the number of appearances of each letter in the string word and stores them irn array freq of size 26. The letters are the 26 letters of the Latin alphabet whose ASCII values are in the range 97-122 for the lower case letters, and in the range 65-90 for the uppercase letters. You must account for uppercase and lowercase letter variants, which...

  • - Write a program that performs several operations on an array of positive ints. The program...

    - Write a program that performs several operations on an array of positive ints. The program should prompt the user for the size of the array (validate the size) and dynamically allocate it. Allow the user to enter the values, do not accept negative values in the array. - Your program should then define the functions described below, call them in order, and display the results of each operation: a) reverse: This function accepts a pointer to an int array...

  • Write a program that will do the following. The main function should ask the user how...

    Write a program that will do the following. The main function should ask the user how many numbers it will read in. It will then create an array of that size. Next, it will call a function that will read in the numbers and fill the array (fillArray). Pass the array that was made in themain function as a parameter to this function. Use a loop that will read numbers from the keyboard and store them in the array. This...

  • c++ write a program that reads all values from a text file "data.txt" and stores them in ID array valuesl I. The input process from the file should be terminated when a negative value is detec...

    c++ write a program that reads all values from a text file "data.txt" and stores them in ID array valuesl I. The input process from the file should be terminated when a negative value is detected. (An example of such a file is shown below). Also, the program should copy from values[ 1 any value which has even sum of digits and its index (location) to two new arrays evenArr 1 and idxArrl I, respectively. In addition, the program must...

  • Use C: 3. In function main, declare a two-dimensional integer array with 5 rows and 4...

    Use C: 3. In function main, declare a two-dimensional integer array with 5 rows and 4 columns. Call the following functions from function main. Call a function createArray to seed the random number generator and to fill the two-dimensional array with random integers between -20 and +20. Parameters for this function should be the array and the number of rows and columns). Call a function signs to count the number of positive values, number of negative values and number of...

  • Write a C function named isSymmetric, the prototype of which is given below, that returns 1...

    Write a C function named isSymmetric, the prototype of which is given below, that returns 1 if the elements of an array of integers named myArray of size n are symmetric around the middle. If the array elements are not symmetric, the function should return 0. Both the array and its size are specified as parameters.

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