Skip to content

Instantly share code, notes, and snippets.

@frzleaf
Created November 4, 2015 03:13
Show Gist options
  • Save frzleaf/e35a22d6e3519855dad5 to your computer and use it in GitHub Desktop.
Save frzleaf/e35a22d6e3519855dad5 to your computer and use it in GitHub Desktop.
/*
* Bai 4.14
* Le Quang Thanh - 11020287
*/
#include <iostream>
#include <stdlib.h>
#include <string>
int gcd(int a, int b){
if ( (a * b) == 0 )
return a + b;
return ( a == b)
? a
: a > b
? gcd ( a % b, b )
: gcd ( a , b % a);
}
void testgcd(){
std::cout << gcd(4,0) << std::endl;
std::cout << gcd(4,1)<< std::endl;
std::cout << gcd(0,0)<< std::endl;
std::cout << gcd(4,8)<< std::endl;
}
template<typename T>
void show_array(T **c, int t_row) {
for (int i = 0; i < t_row; ++i) {
for (int j = 0; j < t_row; ++j) {
std::cout << c[i][j] << " ";
}
std::cout << std::endl;
}
}
int main() {
int const N = 5;
bool **a;
a = new bool*[N];
for ( int i = 0 ; i < N ; ++i ){
a[i] = new bool[N];
for ( int j = 0 ; j < N ; ++j ){
a[i][j] = ( gcd(i,j) <= 1);
}
}
show_array(a,N);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment