Created
January 29, 2014 09:40
-
-
Save Yago/039904d7aff42c2566ab to your computer and use it in GitHub Desktop.
C - Opérations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Op?rations simples possibles /////////////////////////////////////////////////// | |
/* | |
+ addition | |
- soustraction | |
* multiplication | |
/ division | |
% modulo => Reste dans un division entre entier relatif (ex : 8/3=2 reste 0.66666) | |
*/ | |
// Exemple | |
int main(int argc, char *argv[]) | |
{ | |
int resultat = 0, nombre1 = 0, nombre2 = 0; | |
// On demande les nombres 1 et 2 ? l'utilisateur : | |
printf("Entrez le nombre 1 : "); | |
scanf("%d", &nombre1); | |
printf("Entrez le nombre 2 : "); | |
scanf("%d", &nombre2); | |
// On fait le calcul : | |
resultat = nombre1 + nombre2; | |
// Et on affiche l'addition ? l'?cran : | |
printf ("%d + %d = %d\n", nombre1, nombre2, resultat); | |
return 0; | |
} | |
// Op?rations plus complexes ////////////////////////////////////////////////// | |
#include <math.h> // Inclure le bilbioth?que math.h | |
fabs(nombre); // Retourne la valeur absolue (-27 -> 27) | |
ceil(nombre); // renvoie le premier nombre entier apr?s le nombre d?cimal qu'on lui donne (25.458 -> 26) | |
floor(nombre); // renvoie le premier nombre entier avant le nombre d?cimal qu'on lui donne (25.458 -> 25) | |
pow(nombre, puissance); // permet de calculer la puissance d'un nombre | |
sqrt(nombre); // calcule la racine carr?e d'un nombre | |
sin(nombre); | |
cos(nombre); | |
tan(nombre); | |
asin(nombre); | |
acos(nombre); | |
atan(nombre); | |
exp(nombre); // calcule l'exponentielle d'un nombre. Elle renvoie un double | |
log(nombre); // calcule le logarithme n?p?rien d'un nombre (que l'on note aussi ? ln ? | |
log10(nombre); // calcule le logarithme base 10 d'un nombre |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment