Skip to content
MPGHThe Dark Arts
/
RegisterLog in
Forum
Community
What's NewLatest posts across the boardTrendingHottest threads right nowSubscribedThreads you follow
Discussion
GeneralIntroductionsEntertainmentDebate FortFlaming & Rage
Board
News & AnnouncementsMPGH TimesSuggestions & HelpGiveaways
More Sections
Art & Graphic DesignProgrammingHackingCryptocurrency
Hacks & Cheats
Games
ValorantCS2 / CS:GOCall of Duty / WarzoneFortniteApex LegendsEscape From Tarkov
+14 moreLeague of LegendsGTA VMinecraftRustROTMGBattlefieldTroveBattleOnCombat ArmsCrossFireBlackshotRuneScapeDayZDead by Daylight
Resources
Game Hacking TutorialsReverse EngineeringGeneral Game HackingAnti-CheatConsole Game Hacking
Tools
Game Hacking ToolsTrainers & CheatsHack/Release NewsNew
Submit a release →Share your cheat, tool, or config with the community.
AINEW
AI Tools
General & DiscussionPrompt EngineeringLLM JailbreaksHotAI Agents & AutomationLocal / Open Models
AI × Gaming
AI Aimbots & VisionML Anti-CheatGame Bots & Automation
Create
AI Coding / Vibe CodingAI Art & MediaAI Voice & TTS
The AI frontier →Where game hacking meets modern machine learning. Jump in.
Marketplace
Buy & Sell
SellingBuyingTradingUser Services
Trust & Safety
Middleman LoungeMarketplace TalkVouch Copy Profiles
Money
Cryptocurrency TalkCurrency ExchangeWork & Job Offers
Start selling →List accounts, services, and goods. Use the middleman to trade safe.
MPGH The Dark Arts

A community for offensive security research, reverse engineering, and AI.

Community

ForumMarketplaceSearch

Account

RegisterLog in

Legal

Privacy PolicyForum RulesHelp & FAQ
© 2026 MPGH · All rights reserved.Built by the community, for the community. For educational purposes onlyContent is shared for security research and education — we don't condone illegal use. You're responsible for complying with applicable laws. Use at your own risk.
Home › Forum › Programming › C++/C Programming › Prime numbers

Prime numbers

Posts 1–15 of 19 · Page 1 of 2
LA
lalakijilp
Prime numbers
as a test for chapter 2 the task was to make a program that can find the prime numbers between 1 and 100. i tried it and i failed. tried again and succeeded.

i googled if 1 is a prime nr but it isn't.

but under no circumstance i can let it show the nr 1 (yeah i know it is not a prime number but i still want it to be possible).

can someone check if the code is alright or can be shortened?
or to make it possible to make the 1 show up.

#include <iostream>
using namespace std;

int main ()
{
int prime, checker, residu;
bool addprime;
residu = prime%checker;

for (prime = 1;prime <=100; prime++)
{

for (checker = 1; checker <prime; checker++)
{
residu = prime%checker;
if (residu ==0)addprime = false;
if (checker ==1)addprime = true;

}

if (addprime == true) cout << prime<< endl;

}

system ("pause");

return 0;

}
#1 · 17y ago
why06
why06
Quote Originally Posted by lalakijilp View Post
as a test for chapter 2 the task was to make a program that can find the prime numbers between 1 and 100. i tried it and i failed. tried again and succeeded.

i googled if 1 is a prime nr but it isn't.

but under no circumstance i can let it show the nr 1 (yeah i know it is not a prime number but i still want it to be possible).

can someone check if the code is alright or can be shortened?
or to make it possible to make the 1 show up.
Close, but not quite. You just need to make a compound if statement

if(residu == 0 && checker != 1)


Place that in ur code.... so that the loop will look like this:
Code:
addprime = true;
for (checker = 1; checker <prime; checker++)
{
residu = prime%checker;
if(residu == 0 && checker != 1)addprime = false;
}
also because this handles both checks you don't need the second if statement so I took the liberty of removing it :P
#2 · 17y ago
LA
lalakijilp
ty didnt think of it to do it that way.

the only thing now is you need to change prime to 2 in the first for loop because 1 isnt actually a prime nr.
#3 · 17y ago
Hell_Demon
Hell_Demon
err oops searched wikipedia and found this is something different
#4 · edited 17y ago · 17y ago
LA
lalakijilp
Quote Originally Posted by Hell_Demon View Post
err oops searched wikipedia and found this is something different
in nl zijn het priemgetallen heb je dat nog niet gehad dan? had ik in de 1ste al
#5 · 17y ago
Hell_Demon
Hell_Demon
Quote Originally Posted by lalakijilp View Post
in nl zijn het priemgetallen heb je dat nog niet gehad dan? had ik in de 1ste al
ik heb dat voor het laatst op de basisschool gehad 6 jaar geleden :P

mischien is dit interessant voor je: Sieve of Atkin - Wikipedia, the free encyclopedia
#6 · 17y ago
LA
lalakijilp
Quote Originally Posted by Hell_Demon View Post
ik heb dat voor het laatst op de basisschool gehad 6 jaar geleden :P

mischien is dit interessant voor je: Sieve of Atkin - Wikipedia, the free encyclopedia
wow dat is wel erg veel gedoe snap jij hier iets van?
#7 · 17y ago
why06
why06
Wow. omg they are speaking german o_O? Ummm confused.... it is german right?
#8 · 17y ago
LA
lalakijilp
Quote Originally Posted by why06 View Post
Wow. omg they are speaking german o_O? Ummm confused.... it is german right?
yeah in holland we speak german
#9 · 17y ago
B1ackAnge1
B1ackAnge1
Dutch.. (Nederlands) they're talking about prime numbers and how last time hell demon had that in 'basic school' was 6 years ago* and then he posted a link to an algorithm. Lala responded that it was very confusing with a lot of 'stuff' going on and was wondering if HD understood any of this.


*ya know.. i'm seriously starting to think I'm the old-fart around here...
#10 · 17y ago
ZE
zeco
Quote Originally Posted by B1ackAnge1 View Post
Dutch.. (Nederlands) they're talking about prime numbers and how last time hell demon had that in 'basic school' was 6 years ago* and then he posted a link to an algorithm. Lala responded that it was very confusing with a lot of 'stuff' going on and was wondering if HD understood any of this.


*ya know.. i'm seriously starting to think I'm the old-fart around here...
Is it just me or does my little flag thingy, not actually show up . Oh well, my guess of dutch was correct then =D.
#11 · 17y ago
B1ackAnge1
B1ackAnge1
Yeah no little flag thingie for you. Maybe you need to re-set it? I think I had to.
#12 · 17y ago
why06
why06
Quote Originally Posted by B1ackAnge1 View Post
Dutch.. (Nederlands) they're talking about prime numbers and how last time hell demon had that in 'basic school' was 6 years ago* and then he posted a link to an algorithm. Lala responded that it was very confusing with a lot of 'stuff' going on and was wondering if HD understood any of this.


*ya know.. i'm seriously starting to think I'm the old-fart around here...
Ummm... how do I put this... ur fart has taken a little longer to dissipate then most other farts o_O?
#13 · edited 17y ago · 17y ago
zhaoyun333
zhaoyun333
Code:
#include <iostream.h>
#include <math.h>

using namespace std;

int main(void){

int primelist[10000]={2,3};  //array to store all prime numbers
int pn=2;   //number of primes in array
int i;        //number to check if prime
int i2;      //index of prime list
bool prime;

for(i=5;i<10000;i+=2){
      for(i2=0,prime=true;primelist[i2]<=sqrt(i);i2++){
              if(i%primelist[i2]==0)prime=false;
      }
      if(prime){
              primelist[pn]=i;
              pn++;
      }
}

for(i=0;i<pn;i++)printf("%d\n",primelist[i]);

return 0;
}

My code running time is about (n/2)*(sqrt(n)) h while his code's running time is n squared
#14 · edited 17y ago · 17y ago
why06
why06
Quote Originally Posted by zhaoyun333 View Post

My code running time is about (n/2)*(sqrt(n)) h while his code's running time is n squared
I'm not sure what you mean by this, but it was a nice idea to only check the odd numbers.
#15 · 17y ago
Posts 1–15 of 19 · Page 1 of 2

Post a Reply

Similar Threads

  • i need short icq number pls and hack to wr..By BoneXDBreaker in WarRock - International Hacks
    1Last post 20y ago
  • Iverson's Comic Number 2By iverson954360 in General
    21Last post 17y ago
  • Iverson's Comic Number 3By iverson954360 in General
    11Last post 17y ago
  • 666 the devils number 666By Gourav2122 in General
    15Last post 19y ago
  • wow number 1By graythug in Debate Fort
    9Last post 19y ago

Tags for this Thread

#numbers#prime