Member Avatar

Hey, guys. Find the sum of all the primes below 2000000. My code: *main.cpp* #include <iostream> #include <vector> #include <cmath> #include "Sieve.h" using namespace std; typedef unsigned long long int ulli; ulli Sum = 0; ulli Sum_of_Primes(vector<bool>, ulli&); ulli Sum_of_Primes(vector<bool> Primes, ulli& Sum) { for(ulli a = 2; a < Upper_Limit; a++) { if (Primes[a]) { Sum += a; } } return Sum; } int main() { Find_Primes_until_n(Primes); cout << Sum_of_Primes(Primes,Sum) << endl; return 0; } *Sieve.h* #ifndef SIEVE_H_INCLUDED #define SIEVE_H_INCLUDED using namespace std; #define Upper_Limit 2000000 vector<bool> Primes; void Find_Primes_until_n (vector<bool>&); void Find_Primes_until_n(vector<bool>& Primes) { Primes.resize(Upper_Limit); fill(Primes.begin(),Primes.begin() + Upper_Limit …

Member Avatar
+0 forum 4
Member Avatar

Hello, guys. I've wrote the following code #include <iostream> #include <string.h> #include <string> #include <locale> #include <stdio.h> #include <stdlib.h> #include <limits> #include <vector> #include <windows.h> using namespace std; string Numero_de_Matricula = ""; string Nome = ""; int Numero_de_Materias = 0; int Numero_de_Creditos = 0; vector<double> creditos (10); vector<double> Coeficientes(10); double Coeficiente_Total = 0; bool repetir = false; void ClearScreen(); void Perguntar_Matricula_e_Nome(string,string); void Perguntar_Materias_e_Creditos(); void Perguntar_Coeficientes(int); void Calcular_Media(vector<double>&,int); bool Repetir(bool); void ClearScreen() { HANDLE hStdOut; CONSOLE_SCREEN_BUFFER_INFO csbi; DWORD count; DWORD cellCount; COORD homeCoords = { 0, 0 }; hStdOut = GetStdHandle( STD_OUTPUT_HANDLE ); if (hStdOut == INVALID_HANDLE_VALUE) return; /* Get the …

Member Avatar
+0 forum 6

The End.