-
Notifications
You must be signed in to change notification settings - Fork 0
/
math.c~
91 lines (83 loc) · 1.63 KB
/
math.c~
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "math.h"
float min(float* tab,int size){
float r=tab[0];
int i;
for(i=1;i<size;i++){
if(tab[i]<r){
r=tab[i];
}
}
return r;
}
float max(float* tab,int size){
float r=tab[0];
int i;
for(i=1;i<size;i++){
if(tab[i]>r){
r=tab[i];
}
}
return r;
}
/*
donne la puissance de 10 majorant un entier 024 -> 3, nos paramettres depassent pas 1O¹⁰
algorithme provenant de:http://stackoverflow.com/questions/3068397/finding-the-length-of-an-integer-in-c
plus rapide qu'un log10 dans certaines situations.
*/
int size_entier(int x){
// this is either a fun exercise in optimization
if(x>=100000) {
if(x>=10000000) {
if(x>=1000000000) return 10;
if(x>=100000000) return 9;
return 8;
}
if(x>=1000000) return 7;
return 6;
} else {
if(x>=1000) {
if(x>=10000) return 5;
return 4;
} else {
if(x>=100) return 3;
if(x>=10) return 2;
return 1;
}
}
}
/*
remplie un tableau par l entier et renvoie la tailel du tableau
*/
int remplir_taille(int** tab,char* nb){
//int size=size_entier(a);
int size=strlen(nb);
(*tab)=malloc(size*sizeof(int));
int i;
for(i=0;i<size;i++){
(*tab)[i]=nb[i]-48;
}
return size;
/*int a=atoi(nb);
if(nb[0]=='0'){
(*tab)[0]=0;
int i;
int div=1;
for(i=1;i<size;i++){
printf("%d %dval %d\n",i,a/div,a/div%10);
(*tab)[i]=a/div%10;
div=div*10;
}
}
else{
int i;
int div=1;
for(i=0;i<size;i++){
(*tab)[i]=a/div%10;
div=div*10;
}
}*/
}