Advertisement
lineoff

Fonctions

Apr 1st, 2016
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.53 KB | None | 0 0
  1. //
  2. //  main.c
  3. //  Fonctions
  4. //
  5. //  Created by Abdelaali on 01/04/2016.
  6. //  Copyright © 2016 Abdelaali. All rights reserved.
  7. //
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <string.h>
  12.  
  13. typedef struct point {
  14.     int x,y;
  15. }point;
  16.  
  17. //fct bonjour
  18. void Bonjour();
  19. //fct bonjour n fois
  20. void BonjourN(int);
  21.  
  22. //fct calculatrice
  23. void Calculatrice(char ,int ,int);
  24.  
  25. //fct point translation
  26. point pointTranslation(point);
  27.  
  28. //fct factorielle
  29. int factorielle(int);
  30.  
  31. //fct sommeTab
  32. int sommeTab(int tab[],int taille);
  33.  
  34. //fct exposant 1
  35. int exposant(int,int);
  36. //fct exposant 2
  37. void exposant2(int*,int);
  38.  
  39. //fct triangle
  40. void triangle(int);
  41.  
  42.  
  43. int main(int argc, const char * argv[]) {
  44.     int x = 2;
  45.     Bonjour();
  46.     BonjourN(5);
  47.     Calculatrice('/', 1, 0);
  48.     printf("%d! = %d\n",6,factorielle(6));
  49.     printf("exp1[%d] = %d\n",x,exposant(x, x));
  50.     exposant2(&x, x);
  51.     printf("exp2[%d] =%d\n",2,x);
  52.     triangle(5);
  53.    
  54.     return 0;
  55. }
  56. void Bonjour(){
  57.     printf("Bonjour\n");
  58. }
  59. void BonjourN(int n){
  60.     int i =0;
  61.     while(i<n){
  62.         Bonjour();
  63.         i++;
  64.     }
  65. }
  66. void Calculatrice(char op,int op1,int op2){
  67.     switch (op) {
  68.         case '+':
  69.             printf("%d + %d = %d",op1,op2,op1 + op2);
  70.             break;
  71.         case '-':
  72.             printf("%d - %d = %d",op1,op2,op1 - op2);
  73.             break;
  74.         case '*':
  75.             printf("%d * %d = %d",op1,op2,op1 * op2);
  76.             break;
  77.         case '/':
  78.             if(op2 != 0)
  79.                 printf("%d / %d = %f",op1,op2,(float) op1 / op2);
  80.             else
  81.                 printf("la division par 0 est impossible.");
  82.             break;
  83.     }
  84.     printf("\n");
  85. }
  86. point pointTranslation(point X){
  87.     X.x += 2;
  88.     X.y += 3;
  89.     return X;
  90. }
  91. int factorielle(int n){
  92.     if(n == 0 || n == 1)
  93.         return 1;
  94.     return n * factorielle(n-1);
  95. }
  96. int sommeTab(int t[],int T){
  97.     int i,s = 0;
  98.     for(i=0;i<T;i++)
  99.         s += t[i];
  100.     return s;
  101. }
  102. int exposant(int x,int n){
  103.     int i,s;
  104.     s = x;
  105.     for(i=0;i<n-1;i++)
  106.         s *= s;
  107.     return s;
  108. }
  109. void exposant2(int* x,int n){
  110.     int i = 0;
  111.    
  112.     for (i=0; i<n-1; i++) {
  113.         (*x) *= (*x);
  114.     }
  115. }
  116. void triangle(int L){
  117.     int mat[L][L];
  118.     int i,j;
  119.    
  120.     for(i=0;i<L;i++)
  121.         for (j=0; j<=i; j++) {
  122.             mat[i][j] = factorielle(i) / (factorielle(j) * factorielle(i -  j));
  123.         }
  124.     for(i=0;i<L;i++){
  125.         for (j=0; j<=i; j++) {
  126.             printf("%2d",mat[i][j]);
  127.         }
  128.         printf("\n");
  129.     }
  130.  
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement