diff options
author | siddhu8990 | 2017-04-19 14:57:49 +0530 |
---|---|---|
committer | siddhu8990 | 2017-04-19 14:57:49 +0530 |
commit | 1fd0dce8d72c4d5869ce5ff4025ac09af603bc0f (patch) | |
tree | 34e52b33707a829c1d8484428c96d3f1f6ce2b3a /src/c/elementaryFunctions/discrete_mathematics | |
parent | 9e506f48291533cba7b4c555b0d2e98f234bfbe3 (diff) | |
download | Scilab2C_fossee_old-1fd0dce8d72c4d5869ce5ff4025ac09af603bc0f.tar.gz Scilab2C_fossee_old-1fd0dce8d72c4d5869ce5ff4025ac09af603bc0f.tar.bz2 Scilab2C_fossee_old-1fd0dce8d72c4d5869ce5ff4025ac09af603bc0f.zip |
Merged Shamik's work
Diffstat (limited to 'src/c/elementaryFunctions/discrete_mathematics')
8 files changed, 181 insertions, 0 deletions
diff --git a/src/c/elementaryFunctions/discrete_mathematics/factor/dfactors.c b/src/c/elementaryFunctions/discrete_mathematics/factor/dfactors.c new file mode 100644 index 0000000..210670b --- /dev/null +++ b/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/src/c/elementaryFunctions/discrete_mathematics/factor/sfactors.c b/src/c/elementaryFunctions/discrete_mathematics/factor/sfactors.c new file mode 100644 index 0000000..9a37140 --- /dev/null +++ b/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/src/c/elementaryFunctions/discrete_mathematics/factorial/dfactoriala.c b/src/c/elementaryFunctions/discrete_mathematics/factorial/dfactoriala.c new file mode 100644 index 0000000..de06aaa --- /dev/null +++ b/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/src/c/elementaryFunctions/discrete_mathematics/factorial/dfactorials.c b/src/c/elementaryFunctions/discrete_mathematics/factorial/dfactorials.c new file mode 100644 index 0000000..28c787e --- /dev/null +++ b/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/src/c/elementaryFunctions/discrete_mathematics/factorial/sfactoriala.c b/src/c/elementaryFunctions/discrete_mathematics/factorial/sfactoriala.c new file mode 100644 index 0000000..e7d820b --- /dev/null +++ b/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/src/c/elementaryFunctions/discrete_mathematics/factorial/sfactorials.c b/src/c/elementaryFunctions/discrete_mathematics/factorial/sfactorials.c new file mode 100644 index 0000000..b660702 --- /dev/null +++ b/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/src/c/elementaryFunctions/discrete_mathematics/primes/dprimess.c b/src/c/elementaryFunctions/discrete_mathematics/primes/dprimess.c new file mode 100644 index 0000000..5ecb92e --- /dev/null +++ b/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/src/c/elementaryFunctions/discrete_mathematics/primes/sprimess.c b/src/c/elementaryFunctions/discrete_mathematics/primes/sprimess.c new file mode 100644 index 0000000..14aa236 --- /dev/null +++ b/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++; + } + } +} |