Problem # 1
This is the first problem for project Euler problems. The first problem asks you to return the amount of numbers between 0 and 1000 which are divisible by 3 or 5.
/* * challenge1.cpp * * This is challenge 1 solution for project Euler, * * Copyright 2012 Bill Heaster <TheCreator@ApexLogic.net> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. * * */ #include <iostream> using namespace std; int main(int argc, char **argv) { int cnt, res; int i = 0; int myArray[1000]; int cpy; for(cnt = 0; cnt <1000; cnt++) { cpy = cnt; if(cpy %3 ==0 || cpy %5 == 0) { //its divisable, add it to array myArray[i]= cnt; i++; } } cout<<"There are "<<i<<" numbers divisable by 3 or 5 that lie between 0 and 1000"<<endl; return 0; }