Monday, October 22, 2018

Euclidean algorithm using C programming language


This is a code for Euclidean algorithm using C programming language.



Euclidean algorithm:-
Source code:-

#include <stdio.h>
int greatestCommonDivisor(int m, int n)
{
    int r;
    if((m == 0) || (n == 0))
        return 0;
    else if((m < 0) || (n < 0))
        return -1;

    do
    {
        r = m % n;
        if(r == 0)
            break;
        m = n;
        n = r;
    }
    while(1);

    return n;
}

int main(void)
{
    int num1 = 600, num2 = 120;
    int gcd = greatestCommonDivisor(num1, num2); 

    printf("The GCD of %d and %d is %d\n", num1, num2, gcd);

    getchar();
   return 0;
}


Output:-


Diffie–Hellman key exchange using C programming language

This is a code for  Diffie–Hellman key exchange  using C programming language. Diffie–Hellman key exchange :- Source code:- #in...