Hi guys I am really frustrated because it feels like i have tried everything and I still cant get my darn assignment to run. The program is supposed to find the largest prime number between 2 and some finite value a user inputs. For example if i input 9 the program should return 7 as the answer. The answer can also include the inputted number and 2. I am bascially attempting this problem with two for loops. One that will decrement the inputted number when certain conditions are met. The second for loop checks divisors and verifies primality. I cant seem to get the two loops to work together. That is break at appropriate times. I am really frustrated because i have been at this for hours with little success. Plz any help is appreciated.
Code:#include <iostream> #include "stdafx.h" #using <mscorlib.dll> using namespace std; using namespace System; int _tmain() { int b,d; d=1; bool a = false; cout << "INPUT B: "; cin >>b; for (b; ( a ==false && b>2 ); b--){ for (int i=2; (i<=b-1 && d!=0); i++){ d = b %i; } if(d == 0) a = false; else a = true; cout<< b <<endl; } return 0; }



LinkBack URL
About LinkBacks


