XXXXXXXXXXAssignment #1 Deadline: July 13, 2018 at 11:59pm 1. The following function is supposed to return true if any element of the array a has the value 0 and false if all elements are non-zeros....

1 answer below »
questions 4 and 5 only


(60-140) Assignment #1 Deadline: July 13, 2018 at 11:59pm 1. The following function is supposed to return true if any element of the array a has the value 0 and false if all elements are non-zeros. Sadly, it contains an error. Find the errors and show how to fix it. bool has_zero (int a[], int n) { int i; for (i = 0; i < n;="" i++)="" if(a[i]="=" 0)="" return="" true;="" else="" return="" false;="" }="" 2.="" the="" following="" function="" finds="" the="" median="" of="" three="" numbers.="" rewrite="" the="" function="" so="" that="" it="" has="" just="" one="" return="" statement.="" double="" median="" (double="" x,="" double="" y,="" double="" z)="" {="" if="" (x=""><= y)="" if="" (y=""><= z)="" return="" y;="" else="" if="" (x=""><= z)="" return="" z;="" else="" return="" x;="" if="" (z=""><= y)="" return="" y;="" if="" (x=""><= z)="" return="" x;="" return="" z;="" }="" 3.="" show="" the="" output="" produced="" by="" each="" of="" the="" following="" programs.="" (a)="" #include=""> int foo(int n) { if (n == 2 || n == 3) return n; else return (foo(n+1) + foo(n+2)); } int main() { int n = 3, i = 0; for(i; i<=n; i++)="" printf("%d="" ",="" foo(i));="" return="" 0;="" }="" (b)="" #include=""> #define SIZE 10 int whatIsThis( int b[], int p ) { if ( 1 == p ) return b[ 0 ]; else return b[ p - 1 ] + whatIsThis( b, p - 1 ); } int main( void ) { int x; int a[ SIZE ] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; x = whatIsThis( a, SIZE ); printf( "Result is %d\n", x ); } 4. Write a C program that generates 100 random numbers between 1 and 1000 and displays the minimum number and number of its occurrence in the array. Your program should implement the following functions: a. fillArray (int nums[], int n): To generate 100 random numbers between 1 and 1000 and stores them in array nums. b. recursiveMinimum (int nums[], int size): a recursive function that returns the smallest element of the array. The function should stop processing and return when it receives an array of one element. c. int findFreq (int nums[], int size, int key): To find and return the number of occurrence of the minimum number found by recursiveMinimum in the input array. d. void displayArray(int nums[], int size): To display the array elements (10 numbers in 10 rows). Save the program in a file named as findMin.c, and submit the file online as your solution to this question. 5. Write a C program which fills a matrix of size NxM with random integers between 0 and 100 and sorts the matrix in descending order. N and M are the numbers of rows and columns entered by the user. Your program should implement the following functions: a. void fillMatrix(int A[][],int N, int M): To generates NxM random numbers between 1 and 100 and stores them in array table. b. int sortMatrix(int A[][],int rowsize, int colsize): To sort the input array c. void displayMatrix(int A[], int size): To display the array elements (N rows and M columns). Sample Interaction: Enter number of rows: 3 Enter number of columns: 3 Before Sorting: 1 8 2 4 5 6 3 7 9 After Sorting: 9 8 7 6 5 4 3 2 1 Save the program in a file named as sort2DArray.c, and submit the file online as your solution to this question. Please ensure that the following is completed on your assignment.  Change the name of the files to your firstnameLastname_assignmentName such as minaMaleki_assignment1.pdf  Submit the following electronic files using the submission point located in the assignment 1 o firstnameLastname_assignment1.pdf (For questions 1-3) o firstnameLastname_findMin.c (For question 4) o firstnameLastname_sort2DArray.c (For question 5)  Do what is requested using the tools and knowledge that we have learned in Chapters 1-6. Code that includes anything that we have not yet covered will not be accepted.  Standard comments are included in your files. IMPORTANT: ASK QUESTIONS IF YOU GET STUCK, BUT DO YOUR OWN CODE. ANY CODE SUSPECTED TO BE SIMILAR TO ANOTHER SUBMISSION WILL CAUSE BOTH SUBMISSIONS TO RECEIVE A ZERO MARK ON ALL LABS AND BE REPORTED FOR PLAGIARISM.
Answered Same DayJul 07, 2020

Answer To: XXXXXXXXXXAssignment #1 Deadline: July 13, 2018 at 11:59pm 1. The following function is supposed to...

Sonu answered on Jul 10 2020
145 Votes
C Program/FindMin.c
#include
#include
#define MIN 1
#define MAX 1000
#defi
ne COUNT 100
int array[COUNT];
int findFreq(int nums[], int size, int key){
    int frequencyNumber = 0;
    for (int i = 0; i        if (nums[i] == key){
            frequencyNumber++;
        }
    }
    return frequencyNumber;
}
void fillArray(int nums[], int n){
    for (int i = 0; i        nums[i] = rand() % (MAX - MIN) + MIN;
    }
}
int recursiveMinimum(int nums[], int index, int size){
    int min;
    if (index >= size - 2)
    {
        return (array[index] < array[index + 1])
            ? array[index]
            : array[index + 1];
    }
    min = recursiveMinimum(array, index + 1, size);
    return (array[index] < min)
        ? array[index]
        : min;
}
void...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here