Understand the main function and the other code given below. Complete the code f
ID: 3582641 • Letter: U
Question
Understand the main function and the other code given below. Complete the code for the following three functions: void initialize() This function receives a 2D array as a formal parameter and initializes it with random numbers in the range between 20 and 99 (including 20 and 99). void countValues() This function receives a 2D array, an integer number. The function then returns the count of all numbers less than or equal to number (ctr1), and the count of all numbers larger than number (ctr2). void exchangeColumns() This function accepts a 2D array and the indices of two columns to be swapped.Explanation / Answer
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<time.h>
//use namespace std;
void intitialized(int matrix[5][15])
{
int i,j;
for( i=0;i<5;i++)
{
for(j=0;j<15;j++)
{
matrix[i][j]=rand() % 80 + 20;
}
}
cout<<"The Final Array After intiliazation is:"<<" ";
for(i=0;i<5;i++)
{
for(j=0;j<15;j++)
{
cout<<matrix[i][j]<<" ";
}
cout<<" ";
}
}
void countvalues(int matrix[5][15], int number)
{
int less=0,greater=0;
for( int i=0;i<5;i++)
{
for(int j=0;j<15;j++)
{
if(matrix[i][j]<number)
{
less++;
}
else
{
greater++;
}
}
}
cout<<"Total Number of The Value Less Than "<<number<<" "<<" Are :"<<less;
cout<<"Total Number of The Value Greater Than "<<number<<" "<<" Are :"<<greater;
}
void exchangecolumn(int matrix[5][15],int fi,int si)
{
int i,j,temp;
for(i=0;i<15;i++)
{
temp=matrix[i][fi];
matrix[i][fi]=matrix[i][si];
matrix[i][si]=temp;
}
cout<<"the Value After Exchange Is:"<<" ";
for(i=0;i<5;i++)
{
for(j=0;j<15;j++)
{
cout<<matrix[i][j]<<" ";
}
cout<<" ";
}
}
int main()
{
int value;
int fi,si;
int arr[5][15];
clrscr();
clock_t t;
t=clock();
intitialized(arr);
cout<<"With in the Value to be counted"<<endl;
cin>>value;
countvalues(arr,value);
cout<<" ";
cout<<"Enter The Number Of Indices(between 0 to 14) that you wants to swap"<<endl;
cin>>fi;
cin>>si;
if(fi<si)
{
exchangecolumn(arr,fi,si);
}
else
cout<<"You Entered wrong Index ie First index is Greater than Second index"<<endl;
t= clock()-t;
double time_taken =((double)t)/CLOCKS_PER_SEC;
cout<<"Total Time of Exceution of this program is "<<time_taken<<" s ";
cout<<"press any key to continue.......";
getch();
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.