i tried my best to make a function but i failed.can any one help me?

question is write a function that calculate the greatest common divisor of two number..
Show your attempt.
i dn't have my laptop with me yet.i live in hostel and i came home due to weekend..i hav to submit task tomorrw,,plz if you help me i wud b very thnkful to you
We're not going to write your homework for you.
Make an attempt and we'll help with any questions.
# include<iostream>
# include<conio.h>
using namespace std;
void sum(double& sum,int n){
float add=0;
cout<<"please enter the value of n"<<endl;
cin>>n;
for (int i=1;i<=n; i++){
add +=1.0/i;

}
}
void main(){
double k=0;
int j=0;
sum(k,j);
cout<<"sum is"<<endl;
getch();
this is the program that i want to build..actully i want to sum the series using function void sum(double& sum,int n),the series is 1/1+1/2+1/3...1/n where n is positiv integer
that calculate the greatest common divisor of two number
sum the series 1/1+1/2+1/3...1/n where n is positiv integer

These do not look like one and the same.
sorry i posted another code,this code is not the one i mentioned..can you please give me the hint that how to calculate the greatest comon divisor of two numbers?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
int gcd(int a, int b)
{
    if(a == 0) return b;
    if(b == 0) return a;
    if(a < b)
    {
        a += b;
        b = a - b;
        a -= b;
    }
    int c;
    c = a % b;
    while(c > 0)
    {
        a = b;
        b = c;
        c = a % b;
    }
    return b;
}


writing the code is not the hard core usually, you need to know how to think about an issue, and express it with programming language. and i did not see any difference as explaining it in natural language.
Last edited on
thanx brother.it helps me alot
dear it is only giving me greatest divisor,not the common divisor
question is write a function that calculate the greatest common divisor of two number..

oops, this is your question.
what do you mean by common divisor, but not the greatest common divisor?
there could be more then one common divisor between two files.
Topic archived. No new replies allowed.