programmera
Jun 11th, 2000, 12:17 AM
It's a function "my" that takes a integer array that arguments.
Function shall return a pointers to the smallest numbers.
Problems is:
Why receives I 11 numbers instead receives 10 and that answer latest numbers of them ?????
Examples code:
#include <iostream.h>
#include <stdlib.h>
#include <time.h>
int *my (int *ta, int an)
{
int *temp;
temp = talen;
for (int i=0;i<an;i++)
{
if (ta < temp)
{
temp = ta;
}
ta++;
}
return (temp);
}
main()
{
int ta[10];
int *sv;
srand ((unsigned) time(NULL) );
ta[0]=rand();
for (int i=0; i<10; i++)
cout<<rand()<<endl;
cout << ta [0]<< " ";
cout << endl;
sv = my(ta, sizeof(ta) /sizeof(ta[0]));
cout<< " Smallest numbers is: " << *sv << endl << endl;
cout <<"\nPress any key to continue\n";
getch();
return(0);
}
Function shall return a pointers to the smallest numbers.
Problems is:
Why receives I 11 numbers instead receives 10 and that answer latest numbers of them ?????
Examples code:
#include <iostream.h>
#include <stdlib.h>
#include <time.h>
int *my (int *ta, int an)
{
int *temp;
temp = talen;
for (int i=0;i<an;i++)
{
if (ta < temp)
{
temp = ta;
}
ta++;
}
return (temp);
}
main()
{
int ta[10];
int *sv;
srand ((unsigned) time(NULL) );
ta[0]=rand();
for (int i=0; i<10; i++)
cout<<rand()<<endl;
cout << ta [0]<< " ";
cout << endl;
sv = my(ta, sizeof(ta) /sizeof(ta[0]));
cout<< " Smallest numbers is: " << *sv << endl << endl;
cout <<"\nPress any key to continue\n";
getch();
return(0);
}