samedi 24 janvier 2015

Random Array of long

Can someone tell me why there was no error while compiling but while the program was running it gave false return. I want to create a random array of long and find the max. Thanks you so much and sorry because of my English.



#include <iostream>
#include <stdlib.h>
#include <ctime>
#include <conio.h>
#include <malloc.h>

using namespace std;

void main()
{
long max,dem;
//srand(time(0));
long *A=(long *)malloc(1000000*sizeof(long));
srand(time(NULL));
for(long i=0;i<1000000;i++)
{
A[i]=rand();
}
max=A[0];
for(long i=0;i<1000000;i++)
{
if(A[i]<max)
max=A[i];
}
dem=0;
for(long i=0;i<1000000;i++)
{if(A[i]==max) dem++;}
cout <<"\n Gia tri lon nhat: "<<max;
cout <<"\n Tan so xuat hien: "<<dem;
getch();
}




Aucun commentaire:

Enregistrer un commentaire