Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // primez.cpp : Defines the entry point for the console application.
- //
- //#include "stdafx.h"
- #include <iostream>
- //#include <fstream>
- #include <cmath>
- #include <time.h>
- #include <stdio.h>
- using namespace std;
- class Primez {
- public:
- int start;
- int finish;
- clock_t time;
- double timetaken;
- int counter;
- //ofstream myfile;
- Primez(int start_arg, int finish_arg) {
- start = start_arg;
- finish = finish_arg;
- time = clock();
- counter = 0;
- //myfile.open("primez.csv");
- for (int i = start; i <= finish; i++) {
- bool isaprime = isprime(i);
- if (isaprime == true) {
- //myfile << i;
- //myfile << "\n";
- printf("%d is a prime number\n",i);
- counter++;
- }
- }
- //myfile.close();
- time = clock() - time;
- timetaken = ((double)time) / CLOCKS_PER_SEC; //In seconds
- printf(" There is %d Prime numbers between %d and %d\nThe process took %f seconds\n", counter, start, finish, timetaken);
- }
- bool isprime(int num) {
- bool isaprime = true;
- for (int i = 2; i < sqrt(num) + 1; i++) {
- if (num % i == 0) {
- isaprime = false;
- break;
- }
- else if (num == 0) {
- isaprime = false;
- break;
- }
- }
- return isaprime;
- }
- };
- int main() {
- Primez a = Primez(1, 10000000);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement