typedef struct pNd{ unsigned int N; // Dimension double* Coords;} pNd;typedef pNd* PointNd;
#include <stdarg.h>PointNd Point(double N, ...){ PointNd P = (PointNd) malloc(sizeof(pNd)); P->Coords = (double*) malloc((int)N * sizeof(double)); double coo; va_list args; va_start(args, N); for (int i = 0 ; i < N ; ++i) { coo = va_arg(args, double); P->Coords[i] = coo; } va_end(args); return P;}
#include <stdio.h>#include <stdlib.h>#include <stdarg.h>typedef struct pNd{ unsigned int N; // Dimension double* Coords;} pNd;typedef pNd* PointNd;PointNd Point(double N, ...){ int i = 0 ; PointNd P = (PointNd) malloc(sizeof(pNd)); // TODO : Tells I've Added this line P->N = N ; P->Coords = (double*) malloc((int)N * sizeof(double)); double coo; va_list args; va_start(args, N); // TODO : Tells I've changed ++i to i++ for (i = 0 ; i < N ; i++) { coo = va_arg(args, double); P->Coords[i] = coo; } va_end(args); return P;}/** * Print a point to screen * * \param pnd Point to print * */void printPoint(PointNd pnd){ int i = 0 ; printf("Dimension : %ld\n\n", pnd->N) ; for (i = 0 ; i < pnd->N ; ++i) { printf("Coordinate number %ld : %f\n", (i + 1), pnd->Coords[i]) ; }}int main(void){ PointNd pnd = NULL, pnd2 = NULL ; // Allocates two points. pnd = Point(4, 1.0, 2.0, 3.0, 4.0) ; if (pnd == NULL) printf("ERROR : pnd == NULL") ; pnd2 = Point(2, 3.89, 4.78) ; if (pnd2 == NULL) printf("ERROR : pnd2 == NULL") ; // Prints to screen. printf("pnd :\n===\n\n") ; printPoint(pnd) ; printf("\n\n") ; printf("pnd2 :\n====\n\n") ; printPoint(pnd2) ; return EXIT_SUCCESS;}
Effectivement je ne connaissais pas cette appelation de fonction non plus, j'avais plutôt tendance à passer des tableaux pour ce genre de problème ^^
fib(n) if n < 2 : return n else : return fib(n-1) + fib(n-2)
fib2(n) if n < 2 : return n else : return fib2_a(1, 0, n - 1)fib2_a(n1, n2, i) if i < 0 : return n1 else return fib2_a(n1 + n2, n1, i - 1)
for (unsigned int i = 0 ; i < 100 ; ++i){ printf("%llu\n", Fibonacci(i));}
, c'est parfois difficile de savoir quoi utiliser pour être le plus efficace.
Exemple (très) naïf pour comprendre le concept:for (i=0;i<100;i++){ tab[ i]=tab[i ]*une_fonction(une_constante)}
Quant aux arbres, ... J'aime pas, mdr. Je sais que c'est puissant, mais j'ai eu une mauvaise expérience en cours ^^'
J'espère que ça s'applique à des problèmes plus subtils que ça, parce que sinon, lol !
Un peu comme pour le système de cartes à protéines pour biologistes dont tu m'avais parlé un fois, avec le supercalculateur, la MS surface, le quadri écran et Matlab. Ils ont déjà assez à faire avec la bio et autres sans qu'on ait besoin de leur imposer des connaissances en info, les pauvres ^^
QuoteQuant aux arbres, ... J'aime pas, mdr. Je sais que c'est puissant, mais j'ai eu une mauvaise expérience en cours ^^'Euh je te conseille de te replonger dedans alors, parce que les arbres c'est quand même surpuissant.
Donc oui, y'a la même notion d'avoir une "couche d'abstraction" pour pas que l'utilisateur ait à réfléchir à tout ce qui se passe dans l'ordinateur, mais bon ça s'arrête là ^^