Created
November 4, 2015 03:13
-
-
Save frzleaf/e35a22d6e3519855dad5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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