02.05.2014 Views

Patrick Corde & Anne Fouilloux

Patrick Corde & Anne Fouilloux

Patrick Corde & Anne Fouilloux

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Corrigés 234<br />

Corrigé de l’exercice 5<br />

1 program triabulle<br />

2 implicit none<br />

3 integer, parameter :: croissant=1, decroissant=2, n=10<br />

4 real, dimension(n) :: tab<br />

5 real :: temp<br />

6 logical :: tri_termine, expr1, expr2<br />

7 integer :: sens, i<br />

8<br />

9 ! Valorisation du vecteur<br />

10 data tab/0.76, 0.38, 0.42, 0.91, 0.25, &<br />

11 0.13, 0.52, 0.69, 0.76, 0.98/<br />

12 do sens=croissant, decroissant ! Sens du tri<br />

13 do ! Tri<br />

14 tri_termine = .true.<br />

15 do i=2,n<br />

16 expr1 = sens == croissant .and. tab(i-1) > tab(i)<br />

17 expr2 = sens == decroissant .and. tab(i-1) < tab(i)<br />

18 if (expr1 .or. expr2) then<br />

19 tri_termine = .false.<br />

20 temp = tab(i-1); tab(i-1) = tab(i); tab(i) = temp<br />

21 end if<br />

22 end do<br />

23 if (tri_termine) exit<br />

24 end do<br />

25 ! Impression du vecteur trié<br />

26 if (sens == croissant) print*, "Tri croissant "<br />

27 if (sens == decroissant) print*, "Tri décroissant "<br />

28 print*, tab<br />

29 end do<br />

30 end program triabulle<br />

INSTITUT DU DÉVELOPPEMENT<br />

ET DES RESSOURCES<br />

EN INFORMATIQUE SCIENTIFIQUE<br />

Cours langage Fortran – 27 janvier 2006<br />

<strong>Patrick</strong> <strong>Corde</strong> et <strong>Anne</strong> <strong>Fouilloux</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!