I need help with one.c please! I have completed as much as I know but I need hel
ID: 3811135 • Letter: I
Question
I need help with one.c please! I have completed as much as I know but I need help, I have supplied what I have done so far but please help!
CS 100 Exam Three-Coding Spring 2017 Create a directory called exam3 using mkdir exam3 and move into that directory with cd exam3 to complete the two programs shown below. The skeleton code for each problem (shown below) can be downloaded from the course Blackboard site. You are not allowed to use the Internet while coding You can log into the cs-intro server to test your programs. Name this program. This program ds in a matrix of 2. Name this program two.c This program builds a linked list of ten integers. It then calls hasDups to see if there are any duplicates in numbers and then prompts the user for a value. It counts how many the matrix (a given value occurs more than once). You must write times that val ue occurs in the linked list. Complete the howMany hasDups. Hint create a helper function that takes a value x and the matrix and returns how many times x occurs in the matrix. Your hasDu s calls this hel r function for !includeExplanation / Answer
HI, Please find my implementation.
Please let me know in case of any issue.
#include <stdio.h>
#include <stdlib.h>
int **allocateArray(int r, int c) {
int **array;
array = (int **) malloc ( sizeof(int *) * r);
for (int a=0; a<r; a++)
array[a] = (int *) malloc (sizeof(int) * c);
return array;
}
void readArray(int **array, int r, int c) {
for (int a=0; a<r; a++)
for (int b=0; b<c; b++)
scanf("%d", &array[a][b]);
return;
}
void printArray(int **array, int r, int c) {
for (int a=0; a<r; a++) {
for (int b=0; b<c; b++)
printf("%d ", array[a][b]);
printf(" ");
}
return;
}
int hasDupsHelper(int **data, int r, int c, int x){
int count = 0;
for (int a=0; a<r; a++) {
for (int b=0; b<c; b++)
if(data[a][b] == x)
count++;
}
return count;
}
int hasDups(int **data, int r, int c){ // returns 1 if dups exist, else 0
for (int a=0; a<r; a++) {
for (int b=0; b<c; b++)
if(hasDupsHelper(data, r, c, data[a][b]) > 1) // found duplicate
return 1;
}
return 0; // no duplicate
}
int main(void) {
int **data = allocateArray(5,5);
readArray(data, 5, 5);
printArray(data, 5, 5);
if ( hasDups(data, 5, 5) )
printf("The matrix has duplicate values ");
else
printf("No duplicates found ");
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.