3. (upload as source) Write an algorithm which initializes the contents of an ar
ID: 3590075 • Letter: 3
Question
3. (upload as source) Write an algorithm which initializes the contents of an array to random values between 0 and 99 and then finds the minimum values which exists in the array. You can use the following code to generate a random number in range [0, 99] srand(time(NULL)) int number = rand() % 100; Note that you need to include library "time.h" in your program to make this code work. 4. (upload as source) Write a loop which initializes the contents of an array to random values between 0 and 99 and then reverses the order of the array without the creation of a second array. Example: 27948 0 1 2 34 Becomes: 34972 01 234Explanation / Answer
A)
#include<iostream.h>
#include<time.h>
//#include<ctime>
using namespace std;
int main()
{
int array[100], min, j, loc=-1;
srand(time(NULL));
for(j=0;j<100;j++)
{
array[j]=rand()%100;
}
min=array[0];
for(j=1;j<100;j++)
{
if(array[j]<min)
{
min=array[j];
loc=j+1;
}
}
cout<<”minimum element present at location”<<loc<<”and its value”<<min;
return 0;
}
B)
#include<iostream.h>
#include<time.h>
//#include<ctime>
using namespace std;
int main()
{
int array[100], i,j, num,temp
srand(time(NULL));
for(j=0;j<100;j++)
{
array[j]=rand()%100;
}
i=0;
j=i-1;
while(i<j)
{
temp=array[i];
array[i]=array[j];
array[j]=temp;
i++;
j--;
}
cout<<”array elements after reversal:”;
for(i=0;i<100<i++)
{
cout<<array[i]<<” ”;
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.