SLIDE 84 Algorithmics and C basis
Introduction
For beginners . . . Definition of algorithm
Examples
The product of real numbers Maximum element of a vector
C basis
Variables, arrays Coding . . . Execution
A sorting algorithm
The algorithm The C code
A little more advanced . . .
Pointers Libraries
Implementation of the algorithm in C
#include <stdio.h> #include <stdlib.h> void matrixSort(int n,int m,double **a); int max(int n,int *x); main () { int i,j,n,m; double **a; printf("Sorting algorithm for matrices\n"); printf("dimensions of matrix (n,m)? "); scanf("%d%d",&n,&m); a = calloc(n,sizeof(double*)); for (i = 0; i < n; i++) a[i] = calloc(m,sizeof(double)); printf("insert matrix:\n"); for (i = 0; i < n; i++) for (j = 0; j < m; j++) scanf("%lf",&a[i][j]); matrixSort(n,m,a); printf("sorted matrix:\n"); for (i = 0; i < n; i++) { for (j = 0; j < m; j++) printf(" %lf ",a[i][j]); printf("\n"); }; free(a); };