Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > C/C++
You last visited: Today at 12:34

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



[HELP] find closes number from array??

Discussion on [HELP] find closes number from array?? within the C/C++ forum part of the Coders Den category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Apr 2012
Posts: 372
Received Thanks: 21
[HELP] find closes number from array??

Hi,
well i have a userinput for an integer. And i have to get sqrt of that number and find the closes number from array... and i dont rly know how to do that... can anyone help?

heres the part for my input:
Code:
int poljubnostevilo;
cin >> poljubnostevilo;
cout <<endl;
int koren = sqrt (poljubnostevilo);
cout << koren << endl;
and here's the function i use to fill in the array with prime numbers,.. etc...so this function also has to return the closest number from the array to the sqrt of the inputed integer...

Code:
int funkcijatri(int x, int n){

n = 4;
int praarray[x];
int a=0;
int sum;
    while(a<x){
              n++;
              if(IsPrime(n) && (n>=a)){
                            praarray[a] = n;
                            cout << praarray[a] << ", ";
                            sum+= praarray[a];
                            a++;

                           
              }//konec if  
            
    }//konec while
    
    
    return sum/x;
       


    
}
Hope anyone can help me
Hikarim is offline  
Old 11/25/2012, 21:16   #2

 
マルコ's Avatar
 
elite*gold: 1329
Join Date: Jun 2009
Posts: 1,873
Received Thanks: 960
Personally I would do the following:
- Generate prime numbers by making an array of prime numbers by trying to devide each new number by every prime number. If there is always a rest, you have a new prime number. You then add it to the array
- Create a binary search tree (I think, if you fill it using the array, it will even be a Heap Tree).

Instead of an array in step 1, you should utilize the tree directly. This will speed up things pretty well.

- You now can just test if the number you are looking for is larger or smaller, then go left or right, again compare the value. If your value is in between the last and the current value tested (taken from the tree nodes), you just have to subtract the the tested numbers from the input number, use the absolute number, and then use the number with the smaller result. If the results are equal, your program has to choose one of both. You then just output it.
This way you will have quick algos for creating prime numbers and searching the closest number to the one you look for.
Please first create a list of prime numbers as this process is very very slow (especially when the numbers are getting higher. It took my friend's PC about 10h to find the first prime number with 11 digits based on CPU calculations. You could speed it up with GPU calculations by utilizing OpenCL).
You should also save this list and reload it next time to guarantee a fast startup.

Maybe this would be an overkill, but just consider how much you can learn from it
You should use google and search for the methods stated above.
マルコ is offline  
Old 11/25/2012, 21:41   #3
 
elite*gold: 0
Join Date: Apr 2012
Posts: 372
Received Thanks: 21
thanks for the answer but the problem is i have to use an array in step 1,... thats the requirement... the whole program is correct according to the rules i got so far,... but i have no idea how to do this part now...
Hikarim is offline  
Old 11/25/2012, 22:02   #4

 
マルコ's Avatar
 
elite*gold: 1329
Join Date: Jun 2009
Posts: 1,873
Received Thanks: 960
As I just said, you could use a tree. The performance will be great. If you have to stick to an array, why not just compare consecutive array entries.

Quote:
Originally Posted by マルコ View Post
If your value is in between the last and the current value tested (taken from the tree nodes), you just have to subtract the the tested numbers from the input number, use the absolute number, and then use the number with the smaller result. If the results are equal, your program has to choose one of both. You then just output it.
The prime numbers are sorted, if you use my algo.
マルコ is offline  
Reply


Similar Threads Similar Threads
Help me! How to find Quest Array?
10/09/2012 - PW Hacks, Bots, Cheats, Exploits - 0 Replies
In forum have a bot which can do quest of charater. But doesn't show the structure of array quest. Anyone can show me about that !? , please ! Thanks 4 reading!
Trying to find array of bytes from address in WinHex
02/14/2010 - Dekaron - 4 Replies
Hey guys so today I started playing with WinHex.. not really modifying anything because I've never used WinHex before.. but im wondering is there an easy way to maybe find an AoB from an address in WinHex? Like if I have an updated offset then I search for it and I can find the array.. but lets say I dont have the updated offset and I need an AoB from the address.. how do I find it if I have the old offset and how do I know how long the AoB is? Im trying to teach myself but I dont wanna mess...
how to find array of bytes from an existing adress?
01/25/2010 - Dekaron - 2 Replies
hi! I have a question; how to find array of bytes from an existing adress? its a simple question I hope someone can tell me :)
How to find Array of Bytes?
10/03/2009 - Dekaron - 1 Replies
What do i need to do to find the array of bytes for a hack? Winhex? CSV? Origanal code search? (if that what do is search it under?)
How to find an array of bytes?
09/28/2009 - Dekaron - 7 Replies
Well i wanna learn how to hack in CE n thinking how could u guys find an "array of bytes"? which later on ables u to come up with new address for specific hack. I did do a searching but too many links make my brain dizzy :p



All times are GMT +1. The time now is 12:34.


Powered by vBulletin®
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2025 elitepvpers All Rights Reserved.