Skip to content

Instantly share code, notes, and snippets.

@denisdemaisbr
Created November 27, 2024 06:31
Show Gist options
  • Save denisdemaisbr/83da2052f24a7c30427d392498fd45d9 to your computer and use it in GitHub Desktop.
Save denisdemaisbr/83da2052f24a7c30427d392498fd45d9 to your computer and use it in GitHub Desktop.
modular multiplication in c
/*
gcc --ffast-math -std=c99 -o modmul modmul.c -lm
./modmul
(2 x 3) mod 6 = 0
*/
#include <stdio.h>
int modular_multiplication(int a, int b, int m) {
return (a * b) % m;
}
int main(void) {
int a = 2, b = 3, m = 6;
int result = modular_multiplication(a, b, m);
printf("(%d x %d) mod %d = %d\n", a, b, m, result);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment