I need to find the minimum value in int array, but the answer it gives me is really odd and from that I cannot even judge where the error is, I would really appreciate help. Here is the code I have written:
#include <stdio.h>
#include <iostream>
#include <cmath>
#include <iomanip>
#include <conio.h>
#include <random>
#include <cstdlib>
#include <ctime>
using namespace std;
int minVert(int minimum, int i) {
int j, array[20];
for (j = 0; j < 19; j++) {
if (array[i] < minimum ) {
minimum = array[i];
}
}
return minimum;
}
int main(int k, int minimum) {
int array[20];
srand(time(NULL));
for (int i = 0; i < 20; i++) {
k = rand() % 1000 + 2;
array[i] = k;
}
cout << "Tiek generets masivs..." << endl << "..." << endl << "..." << endl << "..." << endl << endl;
cout << "Masiva elementi ir: " << endl;
for (int j = 0; j <20; j++) {
cout << array[j] << endl;
}
cout << endl << "Masiva mazaka vertiba ir: " << endl << minimum << endl << endl;
cout << "Nospiediet jebkuru taustinu, lai izietu no programmas" << endl;
_getch();
return 0;
}
I think your trying to populate the array with random numbers and then find the minimum.
First remove those parameters from the main function if your not going to use them. You haven't really called the function you wrote in the main. so either write that inside the main or call that function. i would suggest this :
#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
int main()
{
srand(time(NULL));
int array[5];
int minimum;
for(int i = 0; i < 20; i++)
{
array[i] = rand() % 100 + 2;
}
for(int i = 0; i < 20; i++)
{
cout << array[i] << endl;
}
minimum = array[0];
for(int i = 0; i < 20; i++)
{
if(array[i] < minimum)
{
minimum = array[i];
}
}
cout << "minumum is : " << minimum;
}