•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 374,572 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,817 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser:
This program takes a parameter, which is how many prime numbers you need. However if you want to make a program which checks whether a number is prime or not you can delete everything in the main function and put this line instead:
cout << isPrime (argv [1]) ? "It's a prime." : "It's not a prime."
Hope you find this useful, if it works correct
.
cout << isPrime (argv [1]) ? "It's a prime." : "It's not a prime."
Hope you find this useful, if it works correct
. Last edited : Jan 5th, 2008.
#include <iostream> #include <stdlib.h> using namespace std; bool isPrime (float number) { if (number == 1.0f) { return true; } for (float i=2.0f; i<number; i+=1.0f) { if (((number/i) - (int)(number/i)) == 0) return false; } return true; } int main (int argc, char** argv) { cout << "Hello its me the prime number god!, I will give you " << argv [1] << " Prime Numbers like you requested.\n"; int nums =0; while (nums != atoi (argv [1])){ static int i =0; if (isPrime (i)){ cout << "The number : " << nums << " is : " << i << endl; i++; nums++; }else i++; } }
Comments (Newest First)
cscgal | The Queen of DaniWeb | Jan 5th, 2008
•
•
•
•
Moved
darkscript | Newbie Poster | Jan 2nd, 2008
Post Comment
•
•
•
•
DaniWeb Marketplace (Sponsored Links)