« C » : différence entre les versions
De bricosoft
m Nettoyage : gabarit 2012 (widgets Twitter/Google/DISQUS morts et fichiers fantômes) |
m Remplacement des balises <source> obsolètes par <syntaxhighlight> (bot) |
||
| Ligne 3 : | Ligne 3 : | ||
=Codes sources en vrac= | =Codes sources en vrac= | ||
==Produit de deux matrices== | ==Produit de deux matrices== | ||
< | <syntaxhighlight lang="c"> | ||
#include <stdio.h> | #include <stdio.h> | ||
| Ligne 47 : | Ligne 47 : | ||
printf("\n"); | printf("\n"); | ||
} | } | ||
</ | </syntaxhighlight> | ||
==Liens== | ==Liens== | ||
Dernière version du 8 novembre 2026 à 17:46
Le C est un langage de programmation impératif.
Codes sources en vrac
Produit de deux matrices
#include <stdio.h>
#define N 10
void produit(float a[N][N], float b[N][N], float c[N][N], int nla, int nca, int nlb, int ncb) {
int i, j, k;
for (i = 0; i < ncb ; i++)
for (j = 0; j < nla ; j++) {
c[j][i] = 0;
for (k = 0; k < nca; k++)
c[j][i] = a[j][k] * b[k][i] + c[j][i];
}
}
void affiche_matrice(float d[N][N], int nld, int ncd);
int main (void)
{
float a[N][N] = { { 1 , 2 , 0, 4 } , { 3 , 1 , 2, 1 } };
float b[N][N] = { { 1, 2, 1 }, { 3, 0, 2 }, { 1, 2, 0 }, { 1, 4, 1 } };
float c[N][N];
produit( a, b, c, 2, 4, 4, 3 );
affiche_matrice(a, 2, 4);
affiche_matrice(b, 4, 3);
affiche_matrice(c, 2, 3);
}
void affiche_matrice(float d[N][N], int nld, int ncd) {
int i, j;
for ( i=0; i<nld; i++) {
printf ("|");
for (j=0; j<ncd; j++)
printf (" %.0lf |", d[i][j]);
printf("\n");
}
printf("\n");
}
Liens
|url=http://www.bricosoft.com/C }}