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

Write C Program please Not C++ For the program assigned below: • Observe the usu

ID: 3817383 • Letter: W

Question

Write C Program please Not C++ For the program assigned below: • Observe the usual guidelines regarding the initial comment section, indenting, and so on. • Declare all variables at the beginning of the program---not in the middle. • Place prototypes before main. Place functions following main. • Use comments before each function to explain the purpose of the function. • Submit a copy of the source code (.c – not .cpp) saved as an electronic attachment There is just one program for this assignment. In function main declare three arrays of 80 integers each (the original array, the sorted array, and the array of negatives). Do not use a symbolic constant for the size of the array, but instead declare a variable to be used to pass the number of values to the various functions. Also seed the random number generator with time in function main. In doing this assignment write a function and test it before going on to the next function. Do not write the entire program with all functions and then try to run it for the first time. a. Call a function createArray to create an array of 80 random integers in the range 1 to 750. In building the array, if the number is evenly divisible by 5 or 7 or 11, store it as a negative number. Function parameters are the array and the number of values. This function does not return any values pass by value. b. Call a function printArray to print the array, ten values per line. The function should be written with two parameters: the array and the number of values in the array. This function should have only one loop to print the values in one array. It will be called several times in the program to print various arrays, but will not have different loops to print different arrays; there should be only one loop, adaptable to any array. c. Back in function main prompt the user to enter a value to be searched for in the array. Call a function sequentialSearch to do a sequential (linear) search to determine if the value entered is in the array. Function parameters are the array, the number of values in the array, and the value to be searched for. In main, print whether the value is in the array or not and its location in the original array. You may use the algorithm found in classwork or the method in the text or you may devise a different method. In main, print whether the value is in the array or not and its location (if found) in the original array. (You must use a function for the search. Do not simply determine by inspection.) d. Call a function bubbleSort to copy the original array into a new array and then to sort the second array in ascending order. Both arrays should be in the function parameter list, as well as the number of values in the array. Use the bubble sort algorithm found under Sample Programs in Files for sorting. The nested loop used for the sort may be inserted entirely in this function. From function main call the function printArray to print the sorted array. Do not print in the bubbleSort function. e. Call a function ReverseOrder to reverse the order of elements in the original array. This function receives the original 1-dimensional integer array, an output 1-dimensional integer array, and the number of array elements. (The output array should already have been declared in function main with 80 elements.) This function has no return value. This function will assign to the second integer array the elements from the original array, but in reverse order. For instance – the first element in the input array will be put into the last element of the output array, the second element in the input array will be put into the second to last element of the output array, etc. From function main call the printArray function to print the reverse order array.

Explanation / Answer

#include<stdio.h>
#include<stdlib.h>
//Function to generate and store random number between 1 and 750 in array
void createArray(int arr[], int no)
{
int x, number;
//Loops till end of array
for(x = 0; x < no; x++)
{
//Generates a random number between 1 and 750
number = rand() % 750 + 1;
//Checks if the number is divisible by 5 or 7 or 11 convert the number to negative and store in the array
if((number % 5 == 0) || (number % 7 == 0) || (number % 11 == 0))
arr[x] = -number;
//Otherwise store the number
else
arr[x] = number;
}//End of for loop
}//End of function

//Function to print Array contents
void printArray(int arr[], int no)
{
int x, counter = 0;
//Loops till end of array
for(x = 0; x < no; x++)
{
//Checks the if the counter value is 10 then move to next line
if(counter == 10)
{
printf(" ");
//Reset the counter to zero
counter = 0;
}//End of if
//print the array contents
printf("%6d", arr[x]);
//Increase the counter for new line count
c++;
}//End of for loop
}//End of function

//To search a item in the array and returns the location
int sequentialSearch(int arr[], int no, int searchValue)
{
//Initialize the location to -1 for not found
int location = -1, x;
//Loops till end of array
for(x = 0; x < no; x++)
{
//If the searched item found
if(arr[x] == searchValue)
{
//Update the location to current counter position
location = x;
//Come out of the loop
break;
}//End of if
}//End of for loop
//Return the location
return location;
}//End of function

//To sort the array in ascending order
void bubbleSort(int originalArray[], int sortedArray[], int no)
{
int Temp, x, y;
//Loops till end of array
for(x = 0; x < no; x++)
//Creates a duplicate copy of the original array by storing each element
sortedArray[x] = originalArray[x];
//Loops till end of array
for(x = 0; x < no; x++)
{
//Loops till end of array minus sorted position minus 1
for(y = 0; y < no - x - 1; y++)
{
//Checks if the current position value is greater than the next position value than swap
if(sortedArray[y] > sortedArray[y + 1])
{
//Swapping process
Temp = sortedArray[y];
sortedArray[y] = sortedArray[y + 1];
sortedArray[y + 1] = Temp;
}//End of if
}//End of inner for loop
}//End outer for loop
}//End of function

//To reverse the contents of the array
void ReverseOrder (int originalArray[], int reverseArray[], int no)
{
//Initializes last position for the reverseArray
int x, last = no - 1;
//Loops till end of array
for(x = 0; x < no; x++)
{
//Store the x position (i.e., first, second, third ....) value of the original array
//in the last position (i.e., last-1, last - 2, last - 3 ...) of the reverse array
reverseArray[last-x] = originalArray[x];
}//End of for loop
}//End of function
//Main function
int main()
{
//Creates array
int originalArray[80], sortedArray[80], reverseArray[80];
int length = 80, searchValue, location;
createArray(originalArray, length);
printf(" Original Array ");
printArray(originalArray, length);
printf(" Enter the value to be searched in the array: ");
scanf("%d", &searchValue);
location = sequentialSearch(originalArray, length, searchValue);
if(location == -1)
printf(" Searched item %d not found", searchValue);
else
printf(" Searched item %d found in location %d", searchValue, location);
bubbleSort(originalArray, sortedArray, length);
printf(" Sorted Array ");
printArray(sortedArray, length);
printf(" Reverse Order Array ");
ReverseOrder(originalArray, reverseArray, length);
printArray(reverseArray, length);
}//End of main

Sample Run 1:

Original Array

-42 468 -335 251 -420 -725 229 109 713 -465
456 -396 32 328 212 492 746 -693 328 -187
142 -355 153 -154 293 383 172 717 219 -396
-198 727 522 289 -370 -413 -168 -50 536 -145
204 562 573 334 424 -165 142 212 -504 -119
48 -645 -413 508 538 -110 474 -742 -530 29
317 36 -441 -343 289 107 41 -693 -515 149
447 556 141 -730 -371 351 -7 -352 394 549
Enter the value to be searched in the array: 78

Searched item 78 not found
Sorted Array
-742 -730 -725 -693 -693 -645 -530 -515 -504 -465
-441 -420 -413 -413 -396 -396 -371 -370 -355 -352
-343 -335 -198 -187 -168 -165 -154 -145 -119 -110
-50 -42 -7 29 32 36 41 48 107 109
141 142 142 149 153 172 204 212 212 219
229 251 289 289 293 317 328 328 334 351
383 394 424 447 456 468 474 492 508 522
536 538 549 556 562 573 713 717 727 746
Reverse Order Array
549 394 -352 -7 351 -371 -730 141 556 447
149 -515 -693 41 107 289 -343 -441 36 317
29 -530 -742 474 -110 538 508 -413 -645 48
-119 -504 212 142 -165 424 334 573 562 204
-145 536 -50 -168 -413 -370 289 522 727 -198
-396 219 717 172 383 293 -154 153 -355 142
-187 328 -693 746 492 212 328 32 -396 456
-465 713 109 229 -725 -420 251 -335 468 -42

Sample Run 2:

Original Array
-42 468 -335 251 -420 -725 229 109 713 -465
456 -396 32 328 212 492 746 -693 328 -187
142 -355 153 -154 293 383 172 717 219 -396
-198 727 522 289 -370 -413 -168 -50 536 -145
204 562 573 334 424 -165 142 212 -504 -119
48 -645 -413 508 538 -110 474 -742 -530 29
317 36 -441 -343 289 107 41 -693 -515 149
447 556 141 -730 -371 351 -7 -352 394 549
Enter the value to be searched in the array: 141

Searched item 141 found in location 72
Sorted Array
-742 -730 -725 -693 -693 -645 -530 -515 -504 -465
-441 -420 -413 -413 -396 -396 -371 -370 -355 -352
-343 -335 -198 -187 -168 -165 -154 -145 -119 -110
-50 -42 -7 29 32 36 41 48 107 109
141 142 142 149 153 172 204 212 212 219
229 251 289 289 293 317 328 328 334 351
383 394 424 447 456 468 474 492 508 522
536 538 549 556 562 573 713 717 727 746
Reverse Order Array
549 394 -352 -7 351 -371 -730 141 556 447
149 -515 -693 41 107 289 -343 -441 36 317
29 -530 -742 474 -110 538 508 -413 -645 48
-119 -504 212 142 -165 424 334 573 562 204
-145 536 -50 -168 -413 -370 289 522 727 -198
-396 219 717 172 383 293 -154 153 -355 142
-187 328 -693 746 492 212 328 32 -396 456
-465 713 109 229 -725 -420 251 -335 468 -42

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