Question

1. Write a C code that do the following: Generate array of random integer numbers of...

1. Write a C code that do the following:

  • Generate array of random integer numbers of size 25
  • Fill the array with random integers ranging from [1-100]
  • Find the maximum number of the array and its location
  • Find the minimum number of the array and its location
  • Search for a number in the array
  • Print the array
  • Flip the array
  • Sort this array
  • Quit the program when the user choose to exit
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program:

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


void maxAndLocation(int[]);
void minAndLocation(int[]);
void print(int[]);
void search(int[]);
void flip(int[]);
void sort(int[]);

int main()
{
int arr[25];
int i;
char ch;

while(1)
{

for(i=0;i<=24;i++)
{
arr[i]=rand()%(100-1+1)+1;
}


maxAndLocation(arr);
minAndLocation(arr);
print(arr);
search(arr);
flip(arr);
sort(arr);

  
printf("\n\nDo you want to continue(y/n): ");
scanf(" %c",&ch); // a space before %c
if(ch=='n')
{
printf("Bye!!");
break;
}
  
}
return 0;
}


void maxAndLocation(int arr[25])
{
int max=arr[0];
int i,location;
for(i=0;i<=24;i++)
{
if(max<arr[i])
{
max=arr[i];
location=i;
}
}

printf("\nThe maximum number is %d and its location is %d\n",max,location);
}

void minAndLocation(int arr[25])
{
int min=arr[0];
int i,location;
for(i=0;i<=24;i++)
{
if(min>arr[i])
{
min=arr[i];
location=i;
}
}

printf("\nThe minimum number is %d and its location is %d\n",min,location);
}

void print(int arr[25])
{
int i;
printf("\nArray elements: \n");
for(i=0;i<=24;i++)
{   
printf("%d ",arr[i]);
  
}
printf("\n");
}


void search(int arr[25])
{
int i,no,s=0;
printf("\nEnter a number to be searched: ");
scanf("%d",&no);
for(i=0;i<=24;i++)
{
if(arr[i]==no)
{
s=1;
}
}
if(s==1)
{
  
printf("%d is present in the given array\n",no);
}
else
{
printf("%d is not present in the given array\n",no);
}
}

void flip(int arr[25])
{
int i;
printf("\nReverse Array : \n");
for(i=24;i>=0;i--)
{
printf("%d ",arr[i]);
}
  
}


void sort(int arr[25])
{
int i,t,j;
printf("\n\nSorted Array : \n");
  
for(i=0;i<=24;i++)
{
for(j=i+1;j<=24;j++)
{
if(arr[i]>arr[j])
{
t=arr[i];
arr[i]=arr[j];
arr[j]=t;
}
  
}
}
  
for(i=0;i<=24;i++)
{
printf("%d ",arr[i]);
}
  
}

Output:

Add a comment
Know the answer?
Add Answer to:
1. Write a C code that do the following: Generate array of random integer numbers of...
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
  • Task 1 Main Function: Declare and fill an array with 1000 random integers between 1 -...

    Task 1 Main Function: Declare and fill an array with 1000 random integers between 1 - 1000. You will pass the array into functions that will perform operations on the array. Function 1: Create a function that will output all the integers in the array. (Make sure output is clearly formatted. Function 2: Create a Function that will sum and output all the odd numbers in the array. Function 3: Create a Function that will sum and output all the...

  • Write a Java program with a single-dimension array that holds 11 integer numbers and sort the...

    Write a Java program with a single-dimension array that holds 11 integer numbers and sort the array using a bubble sort. Next, identify the median value of the 11 integers. Here are the steps your program must accomplish. algorithm (either flowchart or pseudocode) that you will use to write the program Step 1. Create an Place the algorithm in a Word document. 6. Ste the Step 2. Code the program in Eclipse and ensure the following steps are accomplished. 1....

  • Please code in C thank you. 1. Create an array with 20 random numbers between 1...

    Please code in C thank you. 1. Create an array with 20 random numbers between 1 and 100. Incorporate the following specifications. • Send the base address of the array and an integer to a function called sort(). • The integer is a user input which is either 0 or 1. If the user does not enter either 0 or 1, keeping asking the user until you get the right input. • If the user input is 0, sort the...

  • **C++ only, use standard library, no vectors Write a program to generate a list of 5000...

    **C++ only, use standard library, no vectors Write a program to generate a list of 5000 random numbers between 1 and 10,000 stored in an array. Sorts: Print out the middle 50 numbers of the original list to show the results. Now sort the original numbers using bubble sort. Print out the number of swaps made. Now sort the original numbers using selection sort. Print out the number of swaps made. Now sort the original numbers using insertion sort. Print...

  • C programming Strictly - Write a program to sort an array of integers via arrays of...

    C programming Strictly - Write a program to sort an array of integers via arrays of pointers to those integers as shown in the figure. Problem 1 (68 points): Write a program to sort an array of integers via arrays of pointers to those integers as shown in the figure. The code should contain the following functions: 1)to randomly generate an array of integer numbers; 2) to allocate memory and build the arrays of pointers as shown in the figure...

  • Create a CodeBlocks project "HW 9" Write the code to ask the user to enter the...

    Create a CodeBlocks project "HW 9" Write the code to ask the user to enter the size of an array. Then create an integer array of that exact size. Ask the user to enter a maximum value and then write a loop to fill the array with random numbers with value in the range of 1 to the maximum value. For example, if the maximum value is 100, random numbers must have value 1 to 100 inclusive. Input size of...

  • In C++ 1. Write a program that allows a user to enter 10 integer values from...

    In C++ 1. Write a program that allows a user to enter 10 integer values from the keyboard. The values should be stored in an array. 2. The program should then ask the user for a number to search for in the array: The program should use a binary search to determine if the number exists in a list of values that are stored in an array (from Step #1). If the user enters a number that is in the...

  • (+30) Provide a python program which will Populate an array(list) of size 25 with integers in...

    (+30) Provide a python program which will Populate an array(list) of size 25 with integers in the range -100 (negative 100)   to +100 inclusive Display the array and its length (use the len function) Display the average of all the integers in the array Display the number of even integers (how many) Display the number of odd integers (how many) Display the number of integers > 0   (how many) Display the number of integers < 0   (how many) Display the...

  • Create a class with an array of type integer of size 15. Fill the array with...

    Create a class with an array of type integer of size 15. Fill the array with random integers of size 1 to 1000. Sort the array. Print out the contents of the array. Thank you in advance

  • Java 1. Create a 1D array of 4096 Unique random integer numbers of 1 to 5...

    Java 1. Create a 1D array of 4096 Unique random integer numbers of 1 to 5 digits. Of those numbers give me the following information: - Mean , Mode, Median, Range. - Five times, ask the user for a number within the range (from above) and record the time to find the number in the range. (Loop count) 2. Using a any sort algorithm, build sorted 2D array of random numbers (1 TO 5 digits ) with the x direction...

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