Difference between revisions of "F90: Tabela verdade do OU Exclusivo"

From AdonaiMedrado.Pro.Br
Jump to: navigation, search
(New page: <code lang="fortran"> PROGRAM aula LOGICAL :: l1, l2 l1=.TRUE. l2=.TRUE. WRITE (*,*) "T e T =", ExecutarOUExclusivo(l1,l2) WRITE (*,*) "T e F =", ExecutarOUExclusivo(l1,.NOT. l2) WRI...)
 
Line 1: Line 1:
 +
== Versão sem FUNCTION ==
 +
<code lang="fortran">
 +
PROGRAM aula
 +
!Formas de se escrever um OU El1clusivo:
 +
!(l1 .AND. .NOT. l2) .OR. (.NOT. l1 .AND. l2)
 +
!ou
 +
!(l1 .OR. l2) .AND. (.NOT. l1 .OR. .NOT. l2)
 +
!ou
 +
!(l1 .OR. l2) .AND. .NOT. (l1 .AND. l2)
 +
!ou
 +
!.NOT. ((l1 .OR. .NOT. l2) .AND. (.NOT. l1 .OR. l2))
 +
!Usarei aqui a primeira forma.
 +
LOGICAL :: l1, l2
 +
l1=.TRUE.
 +
l2=.TRUE.
 +
WRITE (*,*) "T e T =", (l1 .AND. .NOT. l2) .OR. (.NOT. l1 .AND. l2)
 +
WRITE (*,*) "T e F =", (l1 .AND. l2) .OR. (.NOT. l1 .AND. .NOT. l2)
 +
WRITE (*,*) "F e T =", (.NOT. l1 .AND. .NOT. l2) .OR. (l1 .AND. l2)
 +
WRITE (*,*) "F e F =", (.NOT. l1 .AND. l2) .OR. (l1 .AND. .NOT. l2)
 +
END PROGRAM aula</code>
 +
== Versão com FUNCTION ==
 
<code lang="fortran">
 
<code lang="fortran">
 
PROGRAM aula
 
PROGRAM aula

Revision as of 17:30, 2 October 2008

Versão sem FUNCTION

PROGRAM aula
	!Formas de se escrever um OU El1clusivo:
	!(l1 .AND. .NOT. l2) .OR. (.NOT. l1 .AND. l2)
	!ou
	!(l1 .OR. l2) .AND. (.NOT. l1 .OR. .NOT. l2)
	!ou
	!(l1 .OR. l2) .AND. .NOT. (l1 .AND. l2)
	!ou
	!.NOT. ((l1 .OR. .NOT. l2) .AND. (.NOT. l1 .OR. l2))
	!Usarei aqui a primeira forma.
	LOGICAL :: l1, l2
	l1=.TRUE.
	l2=.TRUE.
	WRITE (*,*) "T e T =", (l1 .AND. .NOT. l2) .OR. (.NOT. l1 .AND. l2)
	WRITE (*,*) "T e F =", (l1 .AND. l2) .OR. (.NOT. l1 .AND. .NOT. l2)
	WRITE (*,*) "F e T =", (.NOT. l1 .AND. .NOT. l2) .OR. (l1 .AND. l2)
	WRITE (*,*) "F e F =", (.NOT. l1 .AND. l2) .OR. (l1 .AND. .NOT. l2)
END PROGRAM aula

Versão com FUNCTION

PROGRAM aula
	LOGICAL :: l1, l2
	l1=.TRUE.
	l2=.TRUE.
	WRITE (*,*) "T e T =", ExecutarOUExclusivo(l1,l2)
	WRITE (*,*) "T e F =", ExecutarOUExclusivo(l1,.NOT. l2)
	WRITE (*,*) "F e T =", ExecutarOUExclusivo(.NOT. l1, l2)
	WRITE (*,*) "F e F =", ExecutarOUExclusivo(.NOT. l1,.NOT. l2)
CONTAINS
	LOGICAL FUNCTION ExecutarOUExclusivo(x,y)
		LOGICAL, INTENT(IN) :: x,y
		!Formas de se escrever um OU Exclusivo:
		!(x .AND. .NOT. y) .OR. (.NOT x .AND. y)
		!ou
		!(x .OR. y) .AND. (.NOT. x .OR. .NOT. y)
		!ou
		!(x .OR. y) .AND. .NOT. (x .AND. y)
		!ou
		!.NOT. ((x .OR. .NOT. y) .AND. (.NOT. x .OR. y))
		!Usarei aqui a primeira forma.
		ExecutarOUExclusivo = (x .AND. .NOT. y) .OR. (.NOT x .AND. y)
	END FUNCTION ExecutarOUExclusivo
END PROGRAM aula