Expand|Select|Wrap|Line Numbers
- #include <iostream>
- #include <cmath>
- using namespace std;
- //To include project_gcd, Jon McMillan, 1/28/2012.
- long gcd(long,long); // this is the prototype of the procedure gcd
- int main() {
- long a,b; // a and b declared as long
- long c,k; // c and k declared as long
- cout << "Programming project gcd" << endl;
- cout << "by Jon McMillan"<< endl;
- a = 24;
- b = 60;
- /* Find the gcd by algorithm 1.2, the simple for loop */
- cout << "Alg 1.2: The GCD between " << a << " and " << b << " is " << gcd(a,b) << endl;
- return c;
- }
- //This is the procedure that calculates the greatest common divisor
- //input: integer a, b
- //return: the gcd of a and b or error messages
- long gcd(long a,long b) {
- //check for negatives.
- #if(a < 0) a = - a;
- #if(b < 0) b = - b;
- //check for 0’s
- #if( (a= = 0) && (b == 0));
- cout << “Both numbers are 0, No GCD!”<< endl;
- return 0;
- }
- #if( (a= = 0) && (b != 0)) return b;
- #if( (a!= 0) && (b == 0)) return a;
- //actually finding the gcd
- for( k = 1) (k <=a) (k++);
- #if( ( a % k == 0) && (b % k == 0) ); {
- cout << "In gcd: found a common divisor " << k << endl;
- c = k;
- return 0;
- }
1>c:\users\owner\documents\visual studio 2008\projects\project_gcd1\project_gcd1\main.cc(22 ) : warning C4067: unexpected tokens following preprocessor directive - expected a newline
1>c:\users\owner\documents\visual studio 2008\projects\project_gcd1\project_gcd1\main.cc(22 ) : warning C4067: unexpected tokens following preprocessor directive - expected a newline
1>c:\users\owner\documents\visual studio 2008\projects\project_gcd1\project_gcd1\main.cc(40 ) : fatal error C1004: unexpected end-of-file found
I am very unfamiliar with this programming so please help and use simple explanation.
Thank You