Version finale
This commit is contained in:
27
Exemples/cat.c
Normal file
27
Exemples/cat.c
Normal file
@ -0,0 +1,27 @@
|
||||
#ifdef MCC
|
||||
#define FILE char
|
||||
// pipeau: un FILE est quelque chose de plus complique, normalement...
|
||||
#define EOF (-1)
|
||||
// ca, par contre, c'est la vraie valeur de EOF.
|
||||
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
int i, c;
|
||||
|
||||
for (i=1; i<argc; i++)
|
||||
{
|
||||
FILE *f;
|
||||
|
||||
f = fopen (argv[i], "r");
|
||||
while ((c = fgetc (f))!=EOF)
|
||||
fputc (c, stdout);
|
||||
fclose (f);
|
||||
}
|
||||
fflush (stdout);
|
||||
exit (0);
|
||||
}
|
42
Exemples/fact.c
Normal file
42
Exemples/fact.c
Normal file
@ -0,0 +1,42 @@
|
||||
#ifndef MCC
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
int fact (int n)
|
||||
{
|
||||
int res;
|
||||
|
||||
res = 1;
|
||||
while (n!=0)
|
||||
{
|
||||
res = res * n;
|
||||
n--;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
if (argc!=2)
|
||||
{
|
||||
fprintf (stderr, "Usage: ./fact <n>\ncalcule et affiche la factorielle de <n>.\n");
|
||||
fflush (stderr);
|
||||
exit (10); /* non mais! */
|
||||
}
|
||||
{
|
||||
int n, res;
|
||||
|
||||
n = atoi (argv[1]); /* conversion chaine -> entier. */
|
||||
if (n<0)
|
||||
{
|
||||
fprintf (stderr, "Ah non, quand meme, un nombre positif ou nul, s'il-vous-plait...\n");
|
||||
fflush (stderr);
|
||||
exit (10);
|
||||
}
|
||||
res = fact (n);
|
||||
printf ("La factorielle de %d vaut %d (en tout cas, modulo 2^32...).\n",
|
||||
n, res);
|
||||
}
|
||||
return 0;
|
||||
}
|
BIN
Exemples/ordre
Executable file
BIN
Exemples/ordre
Executable file
Binary file not shown.
13
Exemples/ordre.c
Normal file
13
Exemples/ordre.c
Normal file
@ -0,0 +1,13 @@
|
||||
#ifndef MCC
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
int i, j;
|
||||
|
||||
j = (i=3) + (i=4);
|
||||
printf ("Valeur de j=%d (normalement 7), valeur de i=%d.\n", j, i);
|
||||
fflush (stdout);
|
||||
return 0;
|
||||
}
|
102
Exemples/sieve.c
Normal file
102
Exemples/sieve.c
Normal file
@ -0,0 +1,102 @@
|
||||
#ifdef MCC
|
||||
#define NULL 0
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
if (argc!=2)
|
||||
{
|
||||
fprintf (stderr, "Usage: ./sieve <n>\ncalcule et affiche les nombres premiers inferieurs a <n>.\n");
|
||||
fflush (stderr);
|
||||
exit (10); /* non mais! */
|
||||
}
|
||||
{
|
||||
int n;
|
||||
int *bits;
|
||||
|
||||
n = atoi (argv[1]); // conversion chaine -> entier.
|
||||
if (n<2)
|
||||
{
|
||||
fprintf (stderr, "Ah non, quand meme, un nombre >=2, s'il-vous-plait...\n");
|
||||
fflush (stderr);
|
||||
exit (10);
|
||||
}
|
||||
bits = malloc (8*n); // allouer de la place pour n entiers (booleens).
|
||||
// Ca prend 32 fois trop de place. Mais C-- n'a pas les operations &, |,
|
||||
// qui nous permettraient de manipuler des bits individuellement...
|
||||
if (bits==NULL)
|
||||
{
|
||||
fprintf (stderr, "%d est trop gros, je n'ai pas assez de place memoire...\n");
|
||||
fflush (stderr);
|
||||
exit (10);
|
||||
}
|
||||
zero_sieve (bits, n);
|
||||
bits[0] = bits[1] = 1;
|
||||
fill_sieve (bits, n);
|
||||
print_sieve (bits, n);
|
||||
free (bits); // et on libere la place memoire allouee pour bits[].
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int zero_sieve (int *bits, int n)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i=0; i<n; i++)
|
||||
bits[i] = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int fill_sieve (int *bits, int n)
|
||||
{
|
||||
int last_prime;
|
||||
|
||||
for (last_prime = 2; last_prime<n; )
|
||||
{
|
||||
cross_out_prime (bits, n, last_prime);
|
||||
while (++last_prime<n && bits[last_prime]);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int cross_out_prime (int *bits, int n, int prime)
|
||||
{
|
||||
int delta;
|
||||
|
||||
for (delta = prime; (prime = prime + delta) < n; )
|
||||
bits[prime] = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int print_sieve (int *bits, int n)
|
||||
{
|
||||
char *delim;
|
||||
int i;
|
||||
int k;
|
||||
char *buf;
|
||||
|
||||
printf ("Les nombres premiers inferieurs a %d sont:\n", n);
|
||||
delim = " ";
|
||||
k = 0;
|
||||
for (i=0; i<n; i++)
|
||||
{
|
||||
if (bits[i]==0)
|
||||
{
|
||||
printf ("%s%8d", delim, i);
|
||||
if (++k>=4)
|
||||
{
|
||||
printf ("\n"); // retour à la ligne.
|
||||
k = 0;
|
||||
delim = " ";
|
||||
}
|
||||
else
|
||||
printf (" "); // espace.
|
||||
}
|
||||
}
|
||||
fflush (stdout); // on vide le tampon de stdout, utilise par printf().
|
||||
return 0;
|
||||
}
|
7
Exemples/test.c
Normal file
7
Exemples/test.c
Normal file
@ -0,0 +1,7 @@
|
||||
int global1;
|
||||
|
||||
int main() {
|
||||
global1 = 42;
|
||||
printf("%d\n", global1);
|
||||
return 0;
|
||||
}
|
1422
Exemples/unitest0.c
Normal file
1422
Exemples/unitest0.c
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user