Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

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 »
XXXXXXXXXXAssignment #1
Deadline: July 13, 2018 at 11:59pm

1. The following function is supposed to return true if any element of the a
ay a has the value
0 and false if all elements are non-zeros. Sadly, it contains an e
or. Find the e
ors and
show how to fix it.
ool has_zero (int a[], int n) {
int i;
for (i = 0; i < n; i++)
if(a[i] == 0)
XXXXXXXXXXreturn true;
else
XXXXXXXXXXreturn 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;
eturn 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 occu
ence in the a
ay. Your program should
implement the following functions:
a. fillA
ay (int nums[], int n): To generate 100 random numbers between
1 and 1000 and stores them in a
ay nums.
. recursiveMinimum (int nums[], int size): a recursive function that returns
the smallest element of the a
ay. The function should stop processing and return
when it receives an a
ay of one element.
c. int findFreq (int nums[], int size, int key): To find and return the
number of occu
ence of the minimum number found by recursiveMinimum in the
input a
ay.
d. void displayA
ay(int nums[], int size): To display the a
ay 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 a
ay table.
. int sortMatrix(int A[][],int rowsize, int colsize): To sort the input a
ay
c. void displayMatrix(int A[], int size): To display the a
ay elements (N
ows 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 sort2DA
ay.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_sort2DA
ay.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 Day Jul 07, 2020

Solution

Sonu answered on Jul 10 2020
150 Votes
C Program/FindMin.c
#include #include #define MIN 1
#define MAX 1000
#define COUNT 100
int a
ay[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 fillA
ay(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 (a
ay[index] < a
ay[index + 1])
            ? a
ay[index]
            : a
ay[index + 1];
    }
    min = recursiveMinimum(a
ay, index + 1, size);
    return (a
ay[index] < min)
        ? a
ay[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