summaryrefslogtreecommitdiff
path: root/2.3-1/src/c/elementaryFunctions/discrete_mathematics
diff options
context:
space:
mode:
Diffstat (limited to '2.3-1/src/c/elementaryFunctions/discrete_mathematics')
-rw-r--r--2.3-1/src/c/elementaryFunctions/discrete_mathematics/factor/dfactors.c31
-rw-r--r--2.3-1/src/c/elementaryFunctions/discrete_mathematics/factor/sfactors.c31
-rw-r--r--2.3-1/src/c/elementaryFunctions/discrete_mathematics/factorial/dfactoriala.c12
-rw-r--r--2.3-1/src/c/elementaryFunctions/discrete_mathematics/factorial/dfactorials.c24
-rw-r--r--2.3-1/src/c/elementaryFunctions/discrete_mathematics/factorial/sfactoriala.c12
-rw-r--r--2.3-1/src/c/elementaryFunctions/discrete_mathematics/factorial/sfactorials.c23
-rw-r--r--2.3-1/src/c/elementaryFunctions/discrete_mathematics/primes/dprimess.c24
-rw-r--r--2.3-1/src/c/elementaryFunctions/discrete_mathematics/primes/sprimess.c24
8 files changed, 181 insertions, 0 deletions
diff --git a/2.3-1/src/c/elementaryFunctions/discrete_mathematics/factor/dfactors.c b/2.3-1/src/c/elementaryFunctions/discrete_mathematics/factor/dfactors.c
new file mode 100644
index 00000000..210670bb
--- /dev/null
+++ b/2.3-1/src/c/elementaryFunctions/discrete_mathematics/factor/dfactors.c
@@ -0,0 +1,31 @@
+# include <stdio.h>
+# include <math.h>
+
+void dfactors(double in,double* out)
+{
+ int i=0,k=0;
+ int n=(int)in;
+ while (n%2 == 0)
+ {
+ //printf("%d ", 2);
+ out[k++]=2;
+ n = n/2;
+ }
+
+ for (i = 3; i <= sqrt(n); i = i+2)
+ {
+ while (n%i == 0)
+ {
+ out[k++]=i;
+ //printf("%d ", i);
+ n = n/i;
+ }
+ }
+
+ if (n > 2)
+ {
+ out[k++]=n;
+ //printf ("%d ", n);
+ }
+}
+
diff --git a/2.3-1/src/c/elementaryFunctions/discrete_mathematics/factor/sfactors.c b/2.3-1/src/c/elementaryFunctions/discrete_mathematics/factor/sfactors.c
new file mode 100644
index 00000000..9a37140e
--- /dev/null
+++ b/2.3-1/src/c/elementaryFunctions/discrete_mathematics/factor/sfactors.c
@@ -0,0 +1,31 @@
+# include <stdio.h>
+# include <math.h>
+
+void sfactors(float in,float* out)
+{
+ int i=0,k=0;
+ int n=(int)in;
+ while (n%2 == 0)
+ {
+ //printf("%d ", 2);
+ out[k++]=2;
+ n = n/2;
+ }
+
+ for (i = 3; i <= sqrt(n); i = i+2)
+ {
+ while (n%i == 0)
+ {
+ out[k++]=i;
+ //printf("%d ", i);
+ n = n/i;
+ }
+ }
+
+ if (n > 2)
+ {
+ out[k++]=n;
+ //printf ("%d ", n);
+ }
+}
+
diff --git a/2.3-1/src/c/elementaryFunctions/discrete_mathematics/factorial/dfactoriala.c b/2.3-1/src/c/elementaryFunctions/discrete_mathematics/factorial/dfactoriala.c
new file mode 100644
index 00000000..de06aaa2
--- /dev/null
+++ b/2.3-1/src/c/elementaryFunctions/discrete_mathematics/factorial/dfactoriala.c
@@ -0,0 +1,12 @@
+#include "factorial.h"
+#include <math.h>
+
+void dfactoriala(double* in,int size,double* out)
+{
+ int i=0;
+ for (i=0;i<size;i++)
+ {
+ out[i] = dfactorials(in[i]);
+ }
+}
+
diff --git a/2.3-1/src/c/elementaryFunctions/discrete_mathematics/factorial/dfactorials.c b/2.3-1/src/c/elementaryFunctions/discrete_mathematics/factorial/dfactorials.c
new file mode 100644
index 00000000..28c787e9
--- /dev/null
+++ b/2.3-1/src/c/elementaryFunctions/discrete_mathematics/factorial/dfactorials.c
@@ -0,0 +1,24 @@
+#include <stdio.h>
+#include <math.h>
+#include "factorial.h"
+
+double dfactorials(double in)
+{
+ int i,n;
+ long long int fact=1;
+ n=(int)in;
+ if (n < 0)
+ printf("Error! Factorial of a negative number doesn't exist.");
+ else if (n>170)
+ printf("Inf");
+ else
+ {
+ for(i=1; i<=n; i++)
+ {
+ fact=fact*i;
+ //printf("\n %lld",fact);
+ }
+ }
+
+ return fact;
+}
diff --git a/2.3-1/src/c/elementaryFunctions/discrete_mathematics/factorial/sfactoriala.c b/2.3-1/src/c/elementaryFunctions/discrete_mathematics/factorial/sfactoriala.c
new file mode 100644
index 00000000..e7d820b2
--- /dev/null
+++ b/2.3-1/src/c/elementaryFunctions/discrete_mathematics/factorial/sfactoriala.c
@@ -0,0 +1,12 @@
+#include "factorial.h"
+#include <math.h>
+
+void sfactoriala(float* in,int size,float* out)
+{
+ int i=0;
+ for (i=0;i<size;i++)
+ {
+ out[i] = dfactorials(in[i]);
+ }
+}
+
diff --git a/2.3-1/src/c/elementaryFunctions/discrete_mathematics/factorial/sfactorials.c b/2.3-1/src/c/elementaryFunctions/discrete_mathematics/factorial/sfactorials.c
new file mode 100644
index 00000000..b660702d
--- /dev/null
+++ b/2.3-1/src/c/elementaryFunctions/discrete_mathematics/factorial/sfactorials.c
@@ -0,0 +1,23 @@
+#include <stdio.h>
+#include <math.h>
+#include "factorial.h"
+
+float sfactorials(float in)
+{
+ int i,n;
+ long long int fact=1;
+ n=(int)in;
+ if (n < 0)
+ printf("Error! Factorial of a negative number doesn't exist.");
+ else if(n>170)
+ printf("Inf");
+ else
+ {
+ for(i=1; i<=n; i++)
+ {
+ fact *= i;
+ }
+ }
+
+ return fact;
+}
diff --git a/2.3-1/src/c/elementaryFunctions/discrete_mathematics/primes/dprimess.c b/2.3-1/src/c/elementaryFunctions/discrete_mathematics/primes/dprimess.c
new file mode 100644
index 00000000..5ecb92e1
--- /dev/null
+++ b/2.3-1/src/c/elementaryFunctions/discrete_mathematics/primes/dprimess.c
@@ -0,0 +1,24 @@
+#include<stdio.h>
+#include "primes.h"
+void dprimess(double in, double* out)
+{
+ int i=0,j=0,k=0,n=0,counter=0;
+ n=(int)in;
+ for(i=2;i<=n;i++)
+ {
+ counter=0;
+ for(j=2;j<i;j++)
+ {
+ if(i%j==0)
+ {
+ counter=1;
+ break;
+ }
+ }
+ if(counter==0)
+ {
+ out[k++]=i;
+
+ }
+ }
+}
diff --git a/2.3-1/src/c/elementaryFunctions/discrete_mathematics/primes/sprimess.c b/2.3-1/src/c/elementaryFunctions/discrete_mathematics/primes/sprimess.c
new file mode 100644
index 00000000..14aa2365
--- /dev/null
+++ b/2.3-1/src/c/elementaryFunctions/discrete_mathematics/primes/sprimess.c
@@ -0,0 +1,24 @@
+#include<stdio.h>
+#include "primes.h"
+void sprimess(float in, float* out)
+{
+ int i=0,j=0,k=0,n=0,counter=0;
+ n=(int)in;
+ for(i=2;i<=n;i++)
+ {
+ counter=0;
+ for(j=2;j<i;j++)
+ {
+ if(i%j==0)
+ {
+ counter=1;
+ break;
+ }
+ }
+ if(counter==0)
+ {
+ out[k]=i;
+ k++;
+ }
+ }
+}