[Top 100] Fortran Programming Language Quiz

[Top 100] Fortran Programming Language Quiz: we will cover Fortran mcqs.

Fortran Programming Language Quiz

1. What does the “IMPLICIT NONE” statement do in Fortran?

a) Declares all variables as integers by default.

b) Forces explicit declaration of all variables.

c) Enables implicit type conversion for variables.

d) Specifies default values for uninitialized variables.

Answer: b) Forces explicit declaration of all variables.

2: Which of the following is the correct way to write a comment in Fortran?

a) // This is a comment

b) /* This is a comment */

c) ! This is a comment

d) # This is a comment

Answer: c) ! This is a comment

3: Which of the following is the correct way to initialize an array in Fortran?

a) array = {1, 2, 3}

b) array = [1, 2, 3]

c) array = (1, 2, 3)

d) array = (/1, 2, 3/)

Answer: d) array = (/1, 2, 3/)

4: What is the correct syntax for a DO loop in Fortran?

a) FOR i = 1 TO 10

b) DO i = 1, 10

c) LOOP i = 1, 10

d) WHILE i = 1 TO 10

Answer: b) DO i = 1, 10

5: In Fortran, which function is used to read input from the user?

a) read

b) input

c) get

d) scan

Answer: a) read

6: Which of the following is the correct way to write a conditional statement in Fortran?

a) IF condition THEN

b) IF (condition) THEN

c) IF-THEN condition

d) IF (condition) EXECUTE

Answer: b) IF (condition) THEN

7: What is the correct way to define a subroutine in Fortran?

a) FUNCTION subroutine_name()

b) SUB program_name()

c) SUBROUTINE subroutine_name()

d) PROCEDURE subroutine_name()

Answer: c) SUBROUTINE subroutine_name()

8: Which Fortran keyword is used to exit a loop prematurely?

a) BREAK

b) CONTINUE

c) EXIT

d) RETURN

Answer: c) EXIT

9: Which statement is used to allocate dynamic memory in Fortran?

a) ALLOCATE

b) RESERVE

c) MEMORY

d) NEW

Answer: a) ALLOCATE

10: What is the correct way to open a file for reading in Fortran?

a) OPEN file_name, READ

b) OPEN file_name, INPUT

c) OPEN(file_name, READ)

d) OPEN(file_name, INPUT)

Answer: c) OPEN(file_name, READ)

11. Which of the following is the correct way to declare a character string variable in Fortran?

a) string x

b) var x as string

c) character x

d) declare x as character

Answer: c) character x

12: What is the correct way to write a formatted output statement in Fortran?

a) PRINT “Hello, World!”

b) WRITE “Hello, World!”

c) DISPLAY “Hello, World!”

d) WRITE(,) “Hello, World!”

Answer: d) WRITE(,) “Hello, World!”

13: Which function is used to obtain the length of a character string in Fortran?

a) LENGTH

b) LEN

c) SIZE

d) STRLEN

Answer: b) LEN

14: What is the correct way to convert a string to uppercase in Fortran?

a) UPPERCASE(string)

b) STRINGUP(string)

c) CONVERT(string, UPPERCASE)

d) TRANSFER(string, UPPERCASE)

Answer: a) UPPERCASE(string)

15: Which of the following is the correct way to define a module in Fortran?

a) MODULE module_name

b) DEFINE module_name

c) MODULE_NAME

d) DECLARE module_name

Answer: a) MODULE module_name

16: How do you access a module’s variable or subroutine in a program unit in Fortran?

a) By using the USE statement

b) By importing the module’s file

c) By declaring the module as public

d) By using the INCLUDE statement

Answer: a) By using the USE statement

17: What is the correct way to call a subroutine in Fortran?

a) subroutine_name()

b) CALL subroutine_name()

c) execute subroutine_name()

d) run subroutine_name()

Answer: b) CALL subroutine_name()

18: Which function is used to obtain the current date and time in Fortran?

a) DATE

b) TIME

c) NOW

d) CLOCK

Answer: c) NOW

19: Which Fortran statement is used to deallocate dynamic memory?

A) DEALLOCATE

b) RELEASE

c) FREE

d) REMOVE

Answer: a) DEALLOCATE

20: What is the correct way to include a Fortran source file in another Fortran program?

a) INCLUDE “file.f90”

b) IMPORT “file.f90”

c) USE “file.f90”

d) ADD “file.f90”

Answer: a) INCLUDE “file.f90”

21. What is the correct syntax to define a one-dimensional array with 5 elements in Fortran?

a) array(5)

b) array[5]

c) array(1:5)

d) array[1:5]

Answer: c) array(1:5)

22: Which of the following is the correct way to write a logical OR operation in Fortran?

a) A || B

b) A OR B

c) A .OR. B

d) A && B

Answer: c) A .OR. B

23: What is the correct way to round a floating-point number to the nearest integer in Fortran?

a) ROUND(number)

b) INTEGER(number)

c) FLOOR(number)

d) NINT(number)

Answer: d) NINT(number)

24: In Fortran, which of the following is used to specify the precision and format of a floating-point number in formatted output?

a) %d

b) %f

c) %e

d) %g

Answer: b) %f

25: Which Fortran statement is used to specify the termination condition for a DO loop?

a) CONTINUE

b) STOP

c) END DO

d) EXIT DO

Answer: c) END DO

26: What is the correct way to write an inline comment in Fortran?

a) // This is a comment

b) /* This is a comment */

c) ! This is a comment

d) # This is a comment

Answer: c) ! This is a comment

27: Which of the following is the correct way to write an exponentiation operation in Fortran?

a) x ** y

b) x ^ y

c) x ^^ y

d) EXP(x, y)

Answer: a) x ** y

28: In Fortran, which function is used to convert a string to a numeric value?

a) NUMVAL

b) VAL

c) STR2NUM

d) CONVERT

Answer: b) VAL

29: What is the correct way to declare a constant in Fortran?

a) constant x

b) const x

c) parameter x

d) var x as constant

Answer: c) parameter x

30: Which Fortran statement is used to specify an alternative block of code when a condition is not met?

a) ELSE

b) OTHERWISE

c) OTHERWISE IF

d) ELSE IF

Answer: a) ELSE

31: Which of the following is the correct syntax for a subroutine in Fortran?

a) FUNCTION subroutine_name()

b) SUBROUTINE subroutine_name()

c) PROCEDURE subroutine_name()

d) ROUTINE subroutine_name()

Answer: b) SUBROUTINE subroutine_name()

32: What is the correct Fortran statement to read a character string from the user?

a) READ(,) string

b) READ(,'(A)’) string

c) READ(,'(F10.2)’) string

d) READ(*,'(I)’) string

Answer: b) READ(*,'(A)’) string

33: Which of the following is the correct Fortran statement to write a character string to the screen?

a) PRINT , string

b) WRITE(,*) string

c) PRINT , ‘string’

d) WRITE(,'(A)’) string

Answer: d) WRITE(*,'(A)’) string

34: What is the correct syntax to define a two-dimensional array with 3 rows and 4 columns in Fortran?

a) array(3, 4)

b) array(4, 3)

c) array(1:3, 1:4)

d) array(1:4, 1:3)

Answer: c) array(1:3, 1:4)

35: In Fortran, which of the following is used to declare a variable to be an integer?

a) INT

b) INTEGER

c) REAL

d) CHARACTER

Answer: b) INTEGER

36: What is the correct way to write a DO loop that iterates over the elements of an array in Fortran?

a) DO i = 1 TO N

b) DO i = 1, N

c) DO i FROM 1 TO N

d) DO i FROM 1, N

Answer: b) DO i = 1, N

37: Which Fortran statement is used to stop the program execution and return control to the operating system?

a) RETURN

b) STOP

c) EXIT

d) QUIT

Answer: b) STOP

38: In Fortran, which function is used to convert a numeric value to a string?

a) STR

b) NUM2STR

c) CONVERT

d) CHAR

Answer: a) STR

39: What is the correct Fortran statement to initialize all elements of an array to zero?

a) array = 0

b) array(1:N) = 0

c) array(1:N, 1:M) = 0

d) None of the above

Answer: b) array(1:N) = 0

40: In Fortran, which statement is used to test a condition and execute a block of code repeatedly as long as the condition is true?

a) IF

b) SELECT CASE

c) DO WHILE

d) DO UNTIL

Answer: c) DO WHILE

41: Which of the following is the correct way to define a derived data type in Fortran?

a) TYPE DerivedType

b) DEFINE DerivedType

c) STRUCT DerivedType

d) DECLARE DerivedType

Answer: a) TYPE DerivedType

42: What is the correct Fortran statement to write the value of a variable to a file?

a) PRINT , variable

b) WRITE(,*) variable

c) PRINT , ‘variable’

d) WRITE(unit,) variable

Answer: d) WRITE(unit,*) variable

43: Which of the following is used to concatenate two character strings in Fortran?

a) CONCAT(string1, string2)

b) MERGE(string1, string2)

c) string1 // string2

d) string1 + string2

Answer: c) string1 // string2

44: What is the correct syntax to define a named constant in Fortran?

a) constant_name = value

b) constant constant_name = value

c) parameter constant_name = value

d) define constant_name = value

Answer: c) parameter constant_name = value

45: In Fortran, which statement is used to transfer control to a specific label?

a) GO TO

b) TRANSFER

c) JUMP TO

d) GOTO

Answer: a) GO TO

46: What is the correct way to declare a logical variable in Fortran?

a) logical x

b) var x as logical

c) bool x

d) logical*1 x

Answer: a) logical x

47: Which of the following is the correct Fortran statement to open a file for writing?

a) OPEN file_name, WRITE

b) OPEN file_name, OUTPUT

c) OPEN(file_name, WRITE)

d) OPEN(file_name, OUTPUT)

Answer: c) OPEN(file_name, WRITE)

48: In Fortran, which function is used to find the maximum value in an array?

a) MAXVAL

b) MAXIMUM

c) MAX

d) MAXIMUM_VALUE

Answer: a) MAXVAL

49: What is the correct way to exit a program and return a specific status code in Fortran?

a) END PROGRAM status_code

b) STOP status_code

c) EXIT status_code

d) QUIT status_code

Answer: b) STOP status_code

50: In Fortran, which statement is used to specify the access mode of a file?

a) READ

b) WRITE

c) ACCESS

d) MODE

Answer: c) ACCESS

51: What is the correct way to check if two strings are equal in Fortran?

a) string1 == string2

b) string1 = string2

c) string1 .EQ. string2

d) string1 EQUALS string2

Answer: c) string1 .EQ. string2

52: Which of the following is the correct way to declare a 2D array with dimensions 3×4 in Fortran?

a) array(3, 4)

b) array(4, 3)

c) array(1:3, 1:4)

d) array(1:4, 1:3)

Answer: c) array(1:3, 1:4)

53: What is the correct Fortran statement to calculate the square root of a number?

a) SQRT(number)

b) ROOT(number)

c) number ** 0.5

d) None of the above

Answer: a) SQRT(number)

54: In Fortran, which of the following is used to specify the precision and format of a floating-point number in formatted input?

a) %d

b) %f

c) %e

d) %g

Answer: c) %e

55: What is the correct way to declare a real number variable in Fortran?

a) real x

b) var x as real

c) float x

d) declare x as real

Answer: a) real x

56: In Fortran, which statement is used to repeat a block of code a specific number of times?

a) IF

b) DO WHILE

c) DO UNTIL

d) DO

Answer: d) DO

57: What is the correct Fortran statement to read a real number from the user?

a) READ(,) number

b) READ(,'(A)’) number

c) READ(,'(F10.2)’) number

d) READ(*,'(I)’) number

Answer: a) READ(,) number

58: Which of the following is the correct Fortran statement to write a real number to the screen with two decimal places?

a) PRINT , number

b) WRITE(,*) number

c) PRINT , ‘number’

d) WRITE(,'(F10.2)’) number

Answer: d) WRITE(*,'(F10.2)’) number

59: In Fortran, which function is used to find the minimum value in an array?

a) MINVAL

b) MINIMUM

c) MIN

d) MINIMUM_VALUE

Answer: a) MINVAL

60: What is the correct Fortran statement to close a file?

a) CLOSE file_name

b) CLOSEFILE file_name

c) CLOSE(file_name)

d) None of the above

Answer: c) CLOSE(file_name)

61: What is the correct way to declare an array with an unknown size in Fortran?

a) DIMENSION array(*)

b) DIMENSION array(size)

c) DIMENSION array[]

d) DIMENSION array(:)

Answer: a) DIMENSION array(*)

62: Which of the following is the correct way to access the first element of an array named “arr” in Fortran?

a) arr[0]

b) arr(1)

c) arr(0)

d) arr[1]

Answer: b) arr(1)

63: What is the correct Fortran statement to round a floating-point number down to the nearest integer?

a) FLOOR(number)

b) INT(number)

c) CEILING(number)

d) NINT(number)

Answer: a) FLOOR(number)

64: In Fortran, which statement is used to exit the current iteration of a DO loop and continue with the next iteration?

a) BREAK

b) CONTINUE

c) EXIT

d) SKIP

Answer: b) CONTINUE

65: What is the correct way to define an array with 10 elements, where each element is initialized to 0, in Fortran?

a) INTEGER :: array(10) = 0

b) INTEGER, DIMENSION(10) :: array = 0

c) INTEGER :: array(10)

array = 0

d) INTEGER :: array(10)

array(:) = 0

Answer: b) INTEGER, DIMENSION(10) :: array = 0

66: Which of the following is the correct way to compare if two real numbers are approximately equal in Fortran?

a) real1 == real2

b) real1 = real2

c) real1 .EQV. real2

d) ABS(real1 – real2) < epsilon

Answer: d) ABS(real1 – real2) < epsilon

(Note: ‘epsilon’ refers to a small value used as a tolerance for comparison.)

67: What is the correct way to obtain the current value of the system clock in Fortran?

a) SYSTEM_CLOCK(clock)

b) GET_TIME(clock)

c) CLOCK(clock)

d) TIME(clock)

Answer: a) SYSTEM_CLOCK(clock)

68: In Fortran, which statement is used to pause the execution of a program for a specified amount of time?

a) WAIT

b) PAUSE

c) SLEEP

d) STOP

Answer: c) SLEEP

69: What is the correct Fortran statement to convert an integer to a character string?

a) INT_TO_STR(integer)

b) STR(integer)

c) CHAR(integer)

d) STRING(integer)

Answer: c) CHAR(integer)

70: In Fortran, which statement is used to define a block of code that is executed only if a specific condition is true?

a) IF

b) CASE

c) SELECT

d) WHERE

Answer: a) IF

71: What is the correct way to declare a character array with a length of 20 in Fortran?

a) CHARACTER(20) :: array

b) CHARACTER20 :: array

c) CHARACTER :: array(20)

d) CHARACTER :: array20

Answer: b) CHARACTER*20 :: array

72: In Fortran, which statement is used to specify the precision and format of a real number in formatted output?

a) %d

b) %f

c) %e

d) %g

Answer: b) %f

73: What is the correct way to read an entire line of text from a file in Fortran?

a) READ(,) line

b) READ(,'(A)’) line

c) READ(,'(A80)’) line

d) READ(*,'(F10.2)’) line

Answer: c) READ(*,'(A80)’) line

(Note: A80 specifies that the input should be read as a character string of length 80.)

74: Which of the following is used to find the size of an array in Fortran?

a) SIZE(array)

b) LENGTH(array)

c) DIM(array)

d) SHAPE(array)

Answer: a) SIZE(array)

75: What is the correct way to initialize a character string variable with the value “Hello” in Fortran?

a) string = “Hello”

b) string = ‘Hello’

c) string = “Hello”‘

d) string = ‘Hello’

Answer: d) string = ‘Hello’

76: In Fortran, which statement is used to convert a character string to uppercase?

a) UPPER(string)

b) UCASE(string)

c) CONVERT(string)

d) TRANSFER(string)

Answer: b) UCASE(string)

77: What is the correct Fortran statement to open a file for reading and writing?

a) OPEN(file_name, READ, WRITE)

b) OPEN(file_name, INPUT, OUTPUT)

c) OPEN(file_name, READWRITE)

d) OPEN(file_name, INOUT)

Answer: c) OPEN(file_name, READWRITE)

78: In Fortran, which function is used to find the index of the maximum value in an array?

a) MAXLOC

b) MAXINDEX

c) MAXIMUM_INDEX

d) MAXVAL_INDEX

Answer: a) MAXLOC

79: What is the correct way to declare a double precision variable in Fortran?

a) double x

b) var x as double

c) real*8 x

d) double precision x

Answer: c) real*8 x

80: In Fortran, which statement is used to specify the number of digits after the decimal point in formatted output?

a) DECIMALS

b) PRECISION

c) DIGITS

d) None of the above

Answer: b) PRECISION

81: What is the correct way to declare and initialize a 1D integer array with the values 1, 2, 3, and 4 in Fortran?

a) INTEGER :: array(1:4) = [1, 2, 3, 4]

b) INTEGER, DIMENSION(4) :: array = [1, 2, 3, 4]

c) INTEGER :: array(4)

array = [1, 2, 3, 4]

d) INTEGER :: array(4) = [1, 2, 3, 4]

Answer: d) INTEGER :: array(4) = [1, 2, 3, 4]

82: In Fortran, which statement is used to check if a file exists?

a) EXISTS(file)

b) FILE_EXIST(file)

c) FILE_EXISTS(file)

d) FILENAME_EXIST(file)

Answer: b) FILE_EXIST(file)

83: What is the correct way to declare a subroutine in Fortran?

a) SUBROUTINE subroutine_name()

b) SUB subroutine_name()

c) SUBROUTINE subroutine_name

d) DECLARE subroutine_name

Answer: c) SUBROUTINE subroutine_name

84: In Fortran, which statement is used to allocate dynamic memory?

a) ALLOCATE

b) NEW

c) MEMORY

d) DYNAMIC

Answer: a) ALLOCATE

85: What is the correct way to pass an array to a subroutine in Fortran?

a) Pass the array by reference using the “CALL” statement.

b) Pass the array by value using the “VALUE” attribute.

c) Pass the array by reference using the “INTENT(IN)” attribute.

d) Pass the array by value using the “INTENT(OUT)” attribute.

Answer: c) Pass the array by reference using the “INTENT(IN)” attribute.

86: In Fortran, which statement is used to convert a character string to a numeric value?

a) NUMERIC(string, value)

b) VAL(string, value)

c) CONVERT(string, value)

d) TRANSFORM(string, value)

Answer: b) VAL(string, value)

87: What is the correct way to declare a module in Fortran?

a) MODULE module_name

b) DECLARE module_name

c) DEFINE module_name

d) MODULE

Answer: a) MODULE module_name

88: In Fortran, which statement is used to generate a random number?

a) RANDOM

b) RAND

c) RND

d) RANDOM_NUMBER

Answer: d) RANDOM_NUMBER

89: What is the correct Fortran statement to delete a file?

a) DELETE file_name

b) REMOVE file_name

c) ERASE file_name

d) None of the above

Answer: b) REMOVE file_name

90: In Fortran, which statement is used to obtain the command-line arguments passed to a program?

a) ARGUMENT_COUNT

b) COMMAND_ARGUMENT_COUNT

c) GET_COMMAND_ARGUMENT

d) GET_ARGUMENT

Answer: c) GET_COMMAND_ARGUMENT

Related Queries:

intel oneapi 2021 for fortran | blas fortran | fortran programming language | lapack fortran | intel fortran | python for fortran programmers | fortran developer | intel fortran compiler

For More Programming Quiz Click Here

Leave a Comment

error: Content is protected !!