Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // main.c
- // Fonctions
- //
- // Created by Abdelaali on 01/04/2016.
- // Copyright © 2016 Abdelaali. All rights reserved.
- //
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- typedef struct point {
- int x,y;
- }point;
- //fct bonjour
- void Bonjour();
- //fct bonjour n fois
- void BonjourN(int);
- //fct calculatrice
- void Calculatrice(char ,int ,int);
- //fct point translation
- point pointTranslation(point);
- //fct factorielle
- int factorielle(int);
- //fct sommeTab
- int sommeTab(int tab[],int taille);
- //fct exposant 1
- int exposant(int,int);
- //fct exposant 2
- void exposant2(int*,int);
- //fct triangle
- void triangle(int);
- int main(int argc, const char * argv[]) {
- int x = 2;
- Bonjour();
- BonjourN(5);
- Calculatrice('/', 1, 0);
- printf("%d! = %d\n",6,factorielle(6));
- printf("exp1[%d] = %d\n",x,exposant(x, x));
- exposant2(&x, x);
- printf("exp2[%d] =%d\n",2,x);
- triangle(5);
- return 0;
- }
- void Bonjour(){
- printf("Bonjour\n");
- }
- void BonjourN(int n){
- int i =0;
- while(i<n){
- Bonjour();
- i++;
- }
- }
- void Calculatrice(char op,int op1,int op2){
- switch (op) {
- case '+':
- printf("%d + %d = %d",op1,op2,op1 + op2);
- break;
- case '-':
- printf("%d - %d = %d",op1,op2,op1 - op2);
- break;
- case '*':
- printf("%d * %d = %d",op1,op2,op1 * op2);
- break;
- case '/':
- if(op2 != 0)
- printf("%d / %d = %f",op1,op2,(float) op1 / op2);
- else
- printf("la division par 0 est impossible.");
- break;
- }
- printf("\n");
- }
- point pointTranslation(point X){
- X.x += 2;
- X.y += 3;
- return X;
- }
- int factorielle(int n){
- if(n == 0 || n == 1)
- return 1;
- return n * factorielle(n-1);
- }
- int sommeTab(int t[],int T){
- int i,s = 0;
- for(i=0;i<T;i++)
- s += t[i];
- return s;
- }
- int exposant(int x,int n){
- int i,s;
- s = x;
- for(i=0;i<n-1;i++)
- s *= s;
- return s;
- }
- void exposant2(int* x,int n){
- int i = 0;
- for (i=0; i<n-1; i++) {
- (*x) *= (*x);
- }
- }
- void triangle(int L){
- int mat[L][L];
- int i,j;
- for(i=0;i<L;i++)
- for (j=0; j<=i; j++) {
- mat[i][j] = factorielle(i) / (factorielle(j) * factorielle(i - j));
- }
- for(i=0;i<L;i++){
- for (j=0; j<=i; j++) {
- printf("%2d",mat[i][j]);
- }
- printf("\n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement