1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| #include <stdio.h>
#include <stdlib.h>
int main (void)
{
int n;
int i;
int j;
int tab[50];
int max = 0;
int pos = 0;
char s[BUFSIZ];
printf ("saisir un entier n <= 50 :\n");
fgets (s, BUFSIZ, stdin);
n = (int)strtol (s, NULL, 10);
for (i = 0; i < n; i++)
{
printf ("element %d :\n", i);
fgets (s, BUFSIZ, stdin);
tab[i] = (int)strtol (s, NULL, 10);
}
for (i = 0; i < n; i++)
{
printf ("tab[%d] = %d\n", i, tab[i]);
}
for (i = 0; i < n; i++)
{
if (tab[i] > max)
{
max = tab[i];
pos = i;
}
}
printf ("la valeur maximale est %d elle occupe la position %d\n", tab[pos], pos);
printf ("\nPress [Enter] to continue...\n");
getchar ();
return EXIT_SUCCESS;
} |
Partager