Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a function of the form: lnt isPresentlnArray(int n, int x(), lnt value) wh

ID: 3936572 • Letter: W

Question

Write a function of the form: lnt isPresentlnArray(int n, int x(), lnt value) which given an array x [] of length n. checks to sec if value is present as one of the elements. If value is present return I: otherwise, return 0. Write a function of the form void randperm(int n, int array[]), which computes a random permutation of the integers 0 ... n - 1 and stores the results in array[]. Number Systems Write the following functions involving a single hex digit char dec2hexNibble(n). which given an integer n (where 0 lessthanorequalto n lessthanorequalto 15), returns the corresponding hex character (single digit) Note: getHex (7) returns the character '7'. not the number? int hex2docNibblo(char. which given a hex character (0 - F). returns the corresponding decimal value void hex2binNlbble (char c, int binArray[]); which given a hex character, returns the corresponding 4-bit binary number (in binArray). char bin2h

Explanation / Answer

#include <stdio.h>
#include <time.h>
#include <stdlib.h>

int isPresentInArray(int n, int x[], int value){
int i;
for(i = 0;i < n;++i){
if(x[i] == value)return 1;
}
return 0;
}

void randperm(int n, int array[]){
int i, a[n];
for(i = 0;i < n; ++i)a[i] = i;

time_t t;
//initialize random number generator
srand((unsigned) time(&t));

//use knuth shuffle to get the permutation
for(i = 0;i < n; ++i){
int r = i + (rand() % (n - i));
int temp = a[i];
a[i] = a[r];
a[r] = temp;
}
i = 0;
while(i < n){
array[i] = a[i];
i++;
}
}

char dec2hexNibble(int n){
char c[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A','B', 'C', 'D', 'E', 'F'}; // all the hex value between 0 to 15

return c[n];
}

int hex2decNibble(char c){
int i;
for(i = 0;i <= 15;++i){
// it the number is equal to given character
if(dec2hexNibble(i) == c)
return i;
}
return -1;// wrong hex value
}

void hex2binNibble(char c, int binary[]){
int dec = hex2decNibble(c); // get the decimal value
int bin[] = {0, 0, 0, 0};
int index= 0;
while(dec){
bin[index++] = dec % 2;
dec /= 2;
}

// assign the bin array to binary in reverse order to get binary
binary[0] = bin[3];binary[1] = bin[2]; binary[3] = bin[0];binary[2] = bin[1];

}

char bin2hexNibble(int binArray[]){
int dec = 8*binArray[0] + 4*binArray[1] + 2*binArray[2] + binArray[3];
return dec2hexNibble(dec);
}

int main(){

int x[] = {1, 3, 5, 4, 2, 6};
printf("if number is present in the array %d ", isPresentInArray(5, x, 4));
randperm(6, x);
printf(" ");
printf("After random permutation elements ");
int i = 0;
for(i = 0;i < 6; ++i){
printf("%d ", x[i]);
}
printf(" ");
printf(" ");
printf("dec to hex is %c ", dec2hexNibble(10));
printf("hex to dec is %d ", hex2decNibble('F'));
int binary[] = {0, 0, 0, 0};
hex2binNibble('B', binary);
printf("hex to binary is %d%d%d%d ", binary[0], binary[1], binary[2], binary[3]);
printf("binary to hex is %c ", bin2hexNibble(binary));


return 0;
}

First two question solution. you can take the hint and can do try for others or otherwise ask for rest part.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote