Question

1. Write a C function named find that receives a one-dimensional array of type integer named arr and its size of type integer
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer 1:

Code with explanation:

#include <stdio.h>
#include <math.h>

void find(int arr[],int size){
//i is for iteration and k stores the size of the array
int i,k=size-1;
int randNum;
  
//fills the array arr with values that are the power of 4^n(n is index)
for(i=0;i<size;i++){
arr[i]=pow(4,i);
}
  
//randNum select random index
randNum = (rand()%size);
printf("random index %d",randNum);
//move the arr elements around the elements stored in the randomly selected index
while(k!=randNum){
int temp=arr[size-1];
for(i=size-1;i>0;i--)
{
arr[i]=arr[i-1];
}
arr[0]=temp;
k--;
}
  
//print the elements of array arr
for(i=0;i<size;i++){
printf("\n%d",arr[i]);
}
}

//main function define the integer type array and call find function
int main()
{
int arr[5];
find(arr,5);
return 0;
}

-------------------------------

Output:

random index 3
256
1
4
16
64

---------------------------------------

Screenshot:

C (Goc 6.3) 1 2 Ninclude <stdio.h> include <math.h> } 4- void find(int arr[], int size){ 5 //i is for iteration and k stores

33 34 //main function define the integer type array and call find function 35 int main() 36 - 37 int arr[5]: 38 find(arr, 5);

Answer 2:

for array of type integer named myArr of size 10. Calling the function find(arr,size)

Code with explanation:

#include <stdio.h>
#include <math.h>

void find(int arr[],int size){
//i is for iteration and k stores the size of the array
int i,k=size-1;
int randNum;
  
//fills the array arr with values that are the power of 4^n(n is index)
for(i=0;i<size;i++){
arr[i]=pow(4,i);
}
  
//randNum select random index
randNum = (rand()%size);
printf("random index %d",randNum);
//move the arr elements around the elements stored in the randomly selected index
while(k!=randNum){
int temp=arr[size-1];
for(i=size-1;i>0;i--)
{
arr[i]=arr[i-1];
}
arr[0]=temp;
k--;
}
  
//print the elements of array arr
for(i=0;i<size;i++){
printf("\n%d",arr[i]);
}
}

//main function define the integer type array and call find function
int main()
{
int myArr[10];
find(myArr,10);
return 0;
}

-------------------------------------

Output:

random index 3
256
1024
4096
16384
65536
262144
1
4
16
64

-----------------------------------

Screenshot:

arr[i]=pow(4,1); 11 12 13 14 15 16 17 18 - 19 2e 21 - 22 23 24 25 26 27 28 29 - //randum select randon index randNum = (rand(

Add a comment
Know the answer?
Add Answer to:
1. Write a C function named find that receives a one-dimensional array of type integer named...
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
  • Write a C program to do the following: 1. Write a C function named find that...

    Write a C program to do the following: 1. Write a C function named find that receives a one-dimensional array of type character named arr and its size of type integer. After that, the function must select a random index from the array. The function must find if the character stored in the randomly selected index comes before all the characters to its left alphabetically. Finally, the function prints to the screen the element if the element meets the condition...

  • 1. Write a function named findTarget that takes three parameters: numbers, an array of integers -...

    1. Write a function named findTarget that takes three parameters: numbers, an array of integers - size, an integer representing the size of array target, a number The function returns true if the target is inside array and false otherwise 2. Write a function minValue that takes two parameters: myArray, an array of doubles size, an integer representing the size of array The function returns the smallest value in the array 3. Write a function fillAndFind that takes two parameters:...

  • In c++ 1. Write a function named findTarget that takes three parameters - numbers: an array...

    In c++ 1. Write a function named findTarget that takes three parameters - numbers: an array of integers size: an integer representing the size of array target: a number The function returns true if the target is inside the array and false otherwise 2. Write a function min Valve that takes two parameters: myArray an array of doubles - size: an integer representing the size of array The function returns the smallest value in the array 3 Wrile a funcion...

  • C++ Programming 1. Write a function (header and body) that accepts an integer as an argument...

    C++ Programming 1. Write a function (header and body) that accepts an integer as an argument and returns that number squared. 2. Write the code that will fill an integer array named multiples with 10 integers from 5 to 50 that are multiples of five. (This should NOT be in the form of an initialization statement.) 3. Write the code that will display the contents of the integer array named multiples. Recall: the size of the array is 10. 4....

  • Write a C function  f such that … function  f accepts, as input, … a two-dimensional array of...

    Write a C function  f such that … function  f accepts, as input, … a two-dimensional array of integers in which each row has three columns the number of rows in the array function  f returns the sum of the odd integers in the given array of integers and returns zero if there are no odd integers in the array COMPILER STACK TRACE None PROGRAM EXECUTION STACK TRACE None COMPILER COMMAND LINE ARGUMENTS -lm INPUT OF THE TEST CASE 1 #define NUM_ROWS 5...

  • Write the code to dynamically allocate ONE integer variable using calloc (contiguous allocation) or malloc (memory...

    Write the code to dynamically allocate ONE integer variable using calloc (contiguous allocation) or malloc (memory allocation) and have it pointed to by a pointer (of type int * ) named ptr_1. Use ptr_1 to assign the number 7 to that dynamically allocated integer, and in another line use printf to output the contents of that dynamically allocated integer variable. Write the code to dynamically allocate an integer array of length 5 using calloc or malloc and have it pointed...

  • Write out C++ code for the following: Declare a templated function that has a return type...

    Write out C++ code for the following: Declare a templated function that has a return type of T". It has two parameters: An array of T items named arr, and an integer named size. This function is assumed to work with numerical data types. Within the function, create a new T variable named sum and initialize it to 0. Use a for-loop to go from 0 (inclusive) to size (exclusive), adding each element from arr to the sum. Finally, return...

  • Write a function named numPerfect that takes as parameters: an array of integer scores between zero...

    Write a function named numPerfect that takes as parameters: an array of integer scores between zero and 100 (inclusive) the size of the array and returns the number of perfect scores in the array. Also write a main function that creates and initializes an array of ints (in the appropriate range), calls the function with that array, and prints out the return value.

  • Given an array and a starting position write a function replaceFromN, that takes an integer array...

    Given an array and a starting position write a function replaceFromN, that takes an integer array 'array', the size of the array size and a starting positions 'n' as parameters and replaces the elements starting from that index onward with the sequence 1,2,3,... The function returns nothing. void replaceFromN(int array[], int size, int n) For example, given array= {15,12,4,9,2,3} n =2 the function should modify array to be {15,12,1,2,3,4}

  • Write a C++ program: Declares an array named numberList with 50 components of the type int....

    Write a C++ program: Declares an array named numberList with 50 components of the type int. Initialize the array so that the first 25 components are equal to the square of the counter (or index) variable and the last 25 components are equal to 1, 2, 3, … , 25. Output the array so that exactly ten elements per line are printed.

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