Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > C/C++
You last visited: Today at 03:28

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

Advertisement



[c++] array with prime numbers

Discussion on [c++] array with prime numbers within the C/C++ forum part of the Coders Den category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Apr 2012
Posts: 370
Received Thanks: 20
[c++] array with prime numbers

Hi, i'd need some help with a function...
well, i need to write a function with an array parameter and an int parameter.

that array has to be filled with first 10 prime numbers that are exact or higher than the int parameter...
and then i need an average value of those 10 prime numbers...

The problem is im not really sure how i should do the part to fill the array with prime numbers that are higher than that int?? So any code samples that does that would be really nice... (the average part shouldnt do much problems i think, so i only need for that array fill...)

Code:
int avgprimearray (int higharray[], int somenumber){

}
Hikarim is offline  
Old 11/25/2012, 15:59   #2

 
snow's Avatar
 
elite*gold: 724
Join Date: Mar 2011
Posts: 10,480
Received Thanks: 3,319
For the prime numbers array:
Do some for- / while-loop and check every number above your passed "somenumber" if it's a prime number. If it's a prime number, add it to the array.

This is how it could look (not sure if there are any syntax errors)

PHP Code:
for (int i somenumber500i++) {

 if (
primenumber) { // insert your prime number check here
  
  
*higharray++ = i;
 }

If you want to do this for the first 10 prime numbers, take a look at a while-loop where you count up an integer every time you've found a prime number.

To get the average:

int average = 0;
int counter = 0;
while (*higharray++ != null) {

average+= *higharray;
++counter;
}

average = (int)(average / counter);

-> just add every prime number you've found and divide it by the total amount of found prime numbers. If there are only 10 prime numbers, you don't need the counter variable, just divide by 10.
snow is offline  
Old 11/25/2012, 16:44   #3
 
elite*gold: 0
Join Date: Apr 2012
Posts: 370
Received Thanks: 20
Solved it alrdy, but thanks anyway
Hikarim is offline  
Reply


Similar Threads Similar Threads
New Numbers !
11/08/2011 - CO2 Weapon, Armor, Effects & Interface edits - 11 Replies
Well today i got bored & made these numbers. Finally new numbers? Am i right ? :) http://i38.tinypic.com/33lj82e.png It took me a while resizing them. But i think it was worth it. I have no idea where these numbers are located but i figured i do em anyway. Uh , i don't really know how to make them appear in game but ill take screenies of em their not gunna be in game though. http://i38.tinypic.com/1zl417d.png I tired to remove the white space spacing them apart so they would be closer but i...
best numbers
07/25/2011 - DarkOrbit - 1 Replies
what is the best radius for circling a bk for the circle tool, the increase and decrease things dnt work, i am a goli with all 15 speed gens, but i use battle side with no speed only prom on bk's?
What does all the numbers in itemtype.dat mean?
05/09/2010 - CO2 Private Server - 1 Replies
???^^^???
charname numbers or guild numbers will take block?
02/21/2010 - Silkroad Online - 6 Replies
charname numbers or guild numbers will take block? some friends said that to me is it right?



All times are GMT +2. The time now is 03:28.


Powered by vBulletin®
Copyright ©2000 - 2024, 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 ©2024 elitepvpers All Rights Reserved.