diff --git a/C/Euler_totient_Function.c b/C/Euler_totient_Function.c new file mode 100644 index 0000000..b6193ab --- /dev/null +++ b/C/Euler_totient_Function.c @@ -0,0 +1,29 @@ +//C program to calculate Euler's Totient Function +#include + +// Function to return gcd of a and b +int gcd(int a, int b) +{ + if (a == 0) + return b; + return gcd(b % a, a); +} + +// A simple method to evaluate Euler Totient Function +int phi(unsigned int n) +{ + unsigned int result = 1; + for (int i = 2; i < n; i++) + if (gcd(i, n) == 1) + result++; + return result; +} + +// Driver program to test above function +int main() +{ + int n; + for (n = 1; n <= 10; n++) + printf("phi(%d) = %d\n", n, phi(n)); + return 0; +} \ No newline at end of file