# Assignment 2 Question 6

Posted by SkillS4eva
Announcements Last Post
SoC Curricula 09/30/2017 01:08PM
Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
School of Computing Short Learning Programmes 11/24/2014 08:37AM
Unisa contact information 07/28/2011 01:28PM
 Assignment 2 Question 6 May 17, 2006 02:08PM IP/Host: ---.gprs.vodacom.co.za Registered: 13 years ago Posts: 34 Rating: 0
I see no one has asked for help or had trouble with Assignment 2 Question 6. Has everyone else completed it no problem and am I just useless???
I can't make heads or tails of it [/img]
 Re: Assignment 2 Question 6 May 18, 2006 02:53AM IP/Host: ---.saix.net Registered: 13 years ago Posts: 407 Rating: 0
Have a look at section 6.14 in Cohoon and Davidson. The recursive function we needed to write is very similar.
 Re: Assignment 2 Question 6 May 18, 2006 02:14PM IP/Host: ---.gprs.vodacom.co.za Registered: 13 years ago Posts: 34 Rating: 0
* Scratches around for the text book * Dunno if i bought it though... it Was kinda expensive...

[/url]
 Re: Assignment 2 Question 6 May 18, 2006 04:06PM IP/Host: 196.211.24.--- Registered: 13 years ago Posts: 88 Rating: 0
Here is the code for the simplest of all the questions.

#include <iostream>
#include <string>
using namespace std;

int gcd(int m,int n) {
if ((m % n) = 0) //evaluates whether m can be divided by n without a remainder then n is the gcd
return n;
else
return gcd(n,(m % n)); //use the c++ bult in function to return the gcd for u if you read the section on recursive functions you will have known this

}

int main() {
int m, n;
cout << "Please enter two integers: " << endl;
cin >> m >> n;
cout << " Greatest common divisor for " << m << " / " << " n " <<
" is: " << gcd(m,n) << endl;
return 0;
}

Please no insult, but gcd you were thought in std 7 or 8 I think can't remember. Now just code it, it is simple.
 Re: Assignment 2 Question 6 May 19, 2006 10:01AM IP/Host: ---.saix.net Registered: 13 years ago Posts: 407 Rating: 0
You're probably gonna need to shell out for the textbook at some point. The study guide doesn't cover most of the material, it just tells you what to read in the textbook.

I had never touched C++ before starting COS111 & COS112 this year, and the textbook has been a lifesaver! That and the COS111 study guide.
 Re: Assignment 2 Question 6 May 19, 2006 01:26PM IP/Host: ---.gprs.vodacom.co.za Registered: 13 years ago Posts: 34 Rating: 0
Damn. I didnt purchase the text book. Is it possible to pass the end year exam with just the Study Guide from Unisa?

Thanks Guys
Sorry, only registered users may post in this forum.