C LANGUAGE Randomly generate 50 integers within the range of 0 – 999. Store the integers in an array.Pass the array to different functions that perform the tasks below: i. Print out the randomly generated integers in 5 rows, each row having 10 integer. Input: array return: none Random integer generation: #include rand(); //generate random integer rand()%999; //generate random integer between 0-999 ii. Show the range of integers generated: Output the smallest and largest integer and their index in the array.
C LANGUAGE
Randomly generate 50 integers within the range of 0 – 999. Store the integers in an array.Pass the array to different functions that perform the tasks below:
i. Print out the randomly generated integers in 5 rows, each row having 10 integer.
Input: array
return: none
Random integer generation:
#include<stdlib.h>
rand(); //generate random integer
rand()%999; //generate random integer between 0-999
ii. Show the range of integers generated: Output the smallest and largest integer and their index in the array.
Input: array
return: none
iii. Sort the integers in ascending order
Input: array
return: none
findsmallestnumber(int start, int end, array)
input: start index of array, end index of array, array
return: smallest number index or position in array
iv. Generate another array of 50 integers. Compare the 2 arrays and count the similarity percentage of the 2 arrays.
Input: Array1, Array2
Return: none
** Use 2 for loops for this function, One to loop Array1 and another one inside to
loop Array2
Sort
sort(array)
{
loop(array start to end)
{
smallestNumberIndex = findsmallestnumber(array, currentindex, end);
if (currentIndex != smallestNumberIndex)
{ //swap places
temp =array[smallestNumberIndex];
array[smallestNumberIndex] = array[currentIndex];
array[currentIndex] = temp;
}
}
}
Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 5 images