Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Change the following two programs in Pascal form: PROGRAM #1 – Simple Fortran Co

ID: 3732888 • Letter: C

Question

Change the following two programs in Pascal form:

PROGRAM #1 – Simple Fortran Code

PROGRAM Simple

        REAL :: a, b, c, d

        character (LEN=3) :: r='si'       

        DO WHILE ( r .EQ. 'si')

        PRINT *, 'Enter variable A: '

        READ(*,*) a

        PRINT *, 'Enter variable B: '

        READ(*,*) b

        PRINT *, 'Enter variable C: '

        READ(*,*) c

        d = b*b - 4.0*a*c

        IF (d <0.0) THEN

        WRITE(*,*)'It is not real: ', d

        ELSE IF (d >= 0.0) THEN

        WRITE(*,*)'It is real: ', d

        END IF

        PRINT *, 'Do you wish to continue: '

        READ(*,*) r

        END DO

        PRINT *, 'Program finished '

        END PROGRAM Simple

---------------------------------------------------

PROGRAM #2 – Subroutine Fortran Code

Program Sub

        REAL :: a, b, c,d,r1,r2

        PRINT *, 'Enter variable A: '

        READ(*,*) a

        PRINT *, 'Enter variable B: '

        READ(*,*) b

        PRINT *, 'Enter variable C: '

        READ(*,*) c

        CALL Roots(a, b, c, d, r1, r2)

        CALL Print(r1, r2, d)

       

        END Program Sub

        SUBROUTINE Roots(a, b, c, d, r1, r2)

        d = b*b - 4.0*a*c

        IF (d <0.0) THEN

        WRITE(*,*)'Doesn’t contain real square root.'

        STOP

        ELSE IF (d >= 0.0) THEN

        d     = SQRT(d)

        r1 = (-b + d)/(2.0*a)

        r2= (-b - d)/(2.0*a)

        END IF

        RETURN

        END

        SUBROUTINE PRINT(r1, r2, d)

        IF (r1 == r2) THEN

        PRINT*,'The following square root is; ', root1

        ELSE IF (r1 /= r2) THEN

        PRINT*,'The square root is ', r1, ' y ', r2

        END IF

        PRINT*,'The discriminant is ', d

        RETURN

        END

Explanation / Answer

1)

BEGIN

procedure PRINT(var r1, r2, d);

procedure Roots(var a, b, c, d, r1, r2);

implementation

// PROGRAM Simple

REAL =a, b, c, d;

character (LEN:=3) :: r:='si' ;

while ( r .EQ. 'si')

write ('Enter variable A: ');

readln(F*, a);

write( 'Enter variable B: ');

readln(F*, b);

write('Enter variable C: ');

readln(F*, c);

d := b*b - 4.0*a*c;

if (d <0.0) then begin

writeln(F*,'It is not real: ', d);

end else if (d >= 0.0) then begin

writeln(F*,'It is real: ', d);

end;

end;

readln(F*, r);

end;

END

2

// PROGRAM #2 – Subroutine Fortran Code
// Program Sub
REAL :: a, b, c,d,r1,r2;
PRINT *, 'Enter variable A: ';
readln(F*, a);
PRINT *, 'Enter variable B: ';
readln(F*, b);
PRINT *, 'Enter variable C: ';
readln(F*, c);
Roots(a, b, c, d, r1, r2);
Print(r1, r2, d);


procedure Roots(var a, b, c, d, r1, r2);
begin
d := b*b - 4.0*a*c;
if (d <0.0) then begin
writeln(F*,'Doesn’t contain real square root.');
STOP;
end else if (d >= 0.0) then begin
d := SQRT(d);
r1 := (-b + d)/(2.0*a);
r2:= (-b - d)/(2.0*a);
end;

end;
procedure PRINT(var r1, r2, d);
begin
if (r1 == r2) then begin
PRINT*,'The following square root is; ', root1;
end else if (r1 <> r2) then begin
PRINT*,'The square root is ', r1, ' y ', r2;
end;
PRINT*,'The discriminant is ', d;

end;
end.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote