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

PLease i have a problrm with this program it keeps on crashing Purpose of progra

ID: 3685057 • Letter: P

Question

PLease i have a problrm with this program it keeps on crashing
Purpose of program: The program initializes a function initialization by repeatedly calling the rand()
a swap function is then use to swap the int contents of two memory locations. Then a sorting function is
use to implement a modified version of the initialization function
The program prompts the user to input the value to search for and it prints out the result of the search

#define _CRT_SECURE_NO_WARNINGS // Needed to avoid error message when using scanf
#include <stdio.h>
#include <stdlib.h>

//function prototype
void initiaization(int val[], int size); //initializes the val array
void swap(int **, int **);// Swaps the int contents of two memory locations
void modifiedSort(int*[], int); //This function should implement a modified version of the above Bubble Sort
void display(int[], int);//displays output
void displayPointedTo(int*[], int);//displays output
int binarySearch(int Val[], int Ind[], int key, int min, int max);//Binary search

int main()
{
   int i; //declares i and key

   //create the Val array
   int Val[100];

   //call the function to initialize the Val array
   initiaization(Val, 100);

   //create the Ind array initialize the Ind array
   int *point = &Val;
  
  
   //displays “Now displaying data in the original order”
   printf("Now displaying data in the original order ");

   //call the display function
   display(Val, 100);

   modifiedSort(&Val, 100);

   //display “Now displaying data in sorted order”
   printf(" Now displaying data in sorted order ");

   //call the display function
   displayPointedTo(&Val, 100);

   //display "Now displaying data in the original order"
   printf(" Now displaying data in the original order ");

   //call the display function
   display(Val, 100);

   system("pause");
   return 0;
}//end main

//Function definition
void initiaization(int Val[], int size)
{
   int i; //declares i
   size = 100; //initializes size to 100

   //For loop to use to initialize the value of each index
   for (i = 0; i<size; i++)
   {
       Val[i] = rand() % 1000;
   }//end for loop
}//end function

//Function definition
void swap(int **x, int **y)
{
   int *temp;//holds temp
   temp = *x; //initializes temp to *x
   *x = *y; //swaps the contents pointed by the 2 pointers
   *y = temp; //initializes temp to *y
}//end function

//function definition

void modifiedSort(int *Point[], int size)
{
   int i, j;//declares i and j

   //outer forloop continue till iterate till i Is greater than or equal to 1
   for (i = size - 1; i >= 1; i--)
   {
       //inner for loop continue to iterate till j is less than or equal to i -1
       for (j = 0; j <= i - 1; j++)
       {
           if (*Point[i] > *Point[j + 1])
           {
               //calls the swap function
               swap(*Point[j],*Point[j + 1]);
           }//end if expression
       }//end for loop
   }//end for loop
}//end function

//Function definition
void display(int arr[], int size)
{
   int i; //holds i
   int count = 1; //declares and initializes count to 1
   for (i = 0; i<size; i++)
   {
       //Prints output
       printf("%6d", arr[i]);
       count++;//postfix incrementation of count

       //If count is 11 a new line is printed
       if (count == 11)
       {
           printf(" ");
           count = 1;//initializes count to 1
       }//end of if statement
   }//end of for loop
}//end of function

//Function definition
void displayPointedTo(int *Point[], int size)
{
   int i; //declares i
   int count = 1; //initializes count to 1

   //for loops which continues to iterate till i is less than size
   for (i = 0; i<size; i++)
   {
       //prints the value of Val[Ind[i]]
       printf("%6d", *Point[i]);
       count++;//increments count

       //If count is 11 a new line is printed
       if (count == 11)
       {
           printf(" ");
           count = 1;//initializes count to 1
       }//end if statement
   }//end for loop
}//end function

Explanation / Answer

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

#define _CRT_SECURE_NO_WARNINGS // Needed to avoid error message when using scanf

//function prototype
void initiaization(int val[], int size); //initializes the val array
void swap(int *, int *);// Swaps the int contents of two memory locations
void modifiedSort(int[], int); //This function should implement a modified version of the above Bubble Sort
void display(int[], int);//displays output
void displayPointedTo(int[], int);//displays output
int binarySearch(int Val[], int Ind[], int key, int min, int max);//Binary search


int main()
{
int i; //declares i and key
//create the Val array
int Val[100];
//call the function to initialize the Val array
initiaization(Val, 100);
//create the Ind array initialize the Ind array
//int *point = &Val;
  
  
//displays “Now displaying data in the original order”
printf("Now displaying data in the original order ");
//call the display function
display(Val, 100);

modifiedSort(Val, 100);

//display “Now displaying data in sorted order”
printf(" Now displaying data in sorted order ");
//call the display function
displayPointedTo(Val, 100);

//display "Now displaying data in the original order"
printf(" Now displaying data in the original order ");
//call the display function
display(Val, 100);

system("pause");
return 0;
}//end main


//Function definition
void initiaization(int Val[], int size)
{
int i; //declares i
size = 100; //initializes size to 100
//For loop to use to initialize the value of each index
for (i = 0; i<size; i++)
{
Val[i] = rand() % 1000;
}//end for loop
}//end function


//Function definition
void swap(int *x, int *y)
{
int temp;//holds temp
temp = *x; //initializes temp to *x
*x = *y; //swaps the contents pointed by the 2 pointers
*y = temp; //initializes temp to *y
}//end function


//function definition
void modifiedSort(int Point[], int size)
{
int i, j;//declares i and j
//outer forloop continue till iterate till i Is greater than or equal to 1
for (i = size - 1; i >= 1; i--)
{
//inner for loop continue to iterate till j is less than or equal to i -1
for (j = 0; j <= i - 1; j++)
{
if (Point[i] > Point[j + 1])
{
//calls the swap function
swap(&(Point[j]),&(Point[j + 1]));
}//end if expression
}//end for loop
}//end for loop
}//end function


//Function definition
void display(int arr[], int size)
{
int i; //holds i
int count = 1; //declares and initializes count to 1
for (i = 0; i<size; i++)
{
//Prints output
printf("%6d", arr[i]);
count++;//postfix incrementation of count
//If count is 11 a new line is printed
if (count == 11)
{
printf(" ");
count = 1;//initializes count to 1
}//end of if statement
}//end of for loop
}//end of function


//Function definition
void displayPointedTo(int Point[], int size)
{
int i; //declares i
int count = 1; //initializes count to 1
//for loops which continues to iterate till i is less than size
for (i = 0; i<size; i++)
{
//prints the value of Val[Ind[i]]
printf("%6d", Point[i]);
count++;//increments count
//If count is 11 a new line is printed
if (count == 11)
{
printf(" ");
count = 1;//initializes count to 1
}//end if statement
}//end for loop
}//end function

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