|
FORTAN PAST QUESTION(THEORY + PROGRAM) || IOE || C PROGRAMMING

FORTAN PAST QUESTION(THEORY + PROGRAM) || IOE || C PROGRAMMING

  CREDIT: JEN BATI SIR::::::::::::

Board Exam Theory Questions

  1. What do you mean by formatted and unformatted input/output statements in Fortran [4] [071] 
Formatted input / output statementsFormatted input/output statements are read(*,*) and write(*,*) in fortran. The read(*,*) statement is used for reading data from input devices in user desire format. The write(*,*) statement is used to write/display data to output devices in user desire format.

Syntax:
read(UNIT=unit_no,FMT=format_no) list_of_variables_separated_by_comma
write(UNIT=unit_no,FMT=formt_no) list_of_variables_separated_by_comma

Here, unit_no is an integer that represents input or output device. A computer may have multiple input and output devices such as keyboard, magnetic tape, card reader, monitor, printer etc. In this case, a unique number is given to each device. An asterisk (*) in read() function represents stdin i.e. the keyboard and in write() function it represents stdout i.e. monitor. So, we can either specify a particualr device number in UNIT field or * for default device.

The format_no refers to a label for a format statement. We can write an asterisk (*) to indicate default formatting.

Example of read and write with default unit and default format:
read(*,*),list_of_variables_separated_by_comma
write(*,*),list_of_variables_separated_by_comma

Here, comma at beginning of the variable-list is optional.

c Example of Formatted input/ouput
program addition
integer a,b,c
write(*,*)'Enter any two numbers'
read(*,*)a,b
c = a + b
write(*,*)'Required addition is ',c
end
Unformatted input / output statementsUnformatted input/output statements are read*, and print*, in fortran. When unformatted input/output statements are used, the computer itself decides the formats.

c Unformatted input/ouput
program addition
integer a,b,c
print*,'Enter any two numbers'
read*,a,b
c = a + b
print*,'Required addition is ',c
end






  1. Describe the formatted input and output statement in FORTRAN programming language with its syntax. [4] [067] [071] 

Formatted input and output statements
Formatted input/output statements are read(*,*) and write(*,*) in fortran. The read(*,*) statement is used for reading data from input devices in user desire format. The write(*,*) statement is used to write/display data to output devices in user desire format.

Syntax:
read(UNIT=unit_no,FMT=format_no) list_of_variables_separated_by_comma
write(UNIT=unit_no,FMT=formt_no) list_of_variables_separated_by_comma

Here, unit_no is an integer that represents input or output device. An asterisk (*) represents default device that is keyboard in read() and monitor in write() statements.

The format_no refers to a label for a format statement. We can write an asterisk (*) to indicate default formatting. However we can specify some particular input or output format, e.g. how may decimals in real numbers. For this we use FORMAT statement.

Syntax of FORMAT statement is: N FORMAT(f1,f2,f3,...fn) where
  • N is the statement number and must be for each format statement. It can be placed anywhere in the program.
  • f1,f2,f3,...fn are the format specifications and these must be seperated by commas and enclosed within parenthesis.

The most common format code letters are:
NameDescriptionGeneral Format
F FormatThe symbol F is used to denote the real data expressed in decimal form.Fw.d where w is field width and d is precision.
A FormatThe symbol A is used for character type data.Aw where w is the width which is optional.
I FormatThe symbol I is used to denote the integer data.Iw where w is the width of the integer data.
E FormatThe symbol E is used to denote a real data expressed in exponential form.Ew.d where w is the total field width including mantissa (i.e. base) and d is the decimal width (i.e. precision).
X FormatThe symbol X is used to skip some columns while printing data.nX where n is the number of columns to be skipped in case of reading data from keyboard.
T FormatThis format is used to give tab.Tn where n specifies the number of column form which the output will be started.

c Formatted input/ouput Example
program i/o example
real pi
write(*,*)'Enter the value for pi'
read(*,101)pi
write(*,102)'pi=',pi
101 Format(F8.6)
102 Format(A5,F6.4)
End

Output
Enter the value for pi
3.141592
pi=3.1416



  1. How computer programming language C is different from FORTRAN? [4] [067]
  2. What are the characteristics of FORTRAN programming? [3] [074]
  3. What are FORTRAN’s constants, variables and library functions? Explain. [4] [067]
  4. What is the structure of FORTRAN program? [5] [073] [068]
  5. Explain the FORTRAN structure. What are data types in FORTRAN. [2+2] [070]
  6. Compare arithmetic and logical if statement in FORTRAN. [7] [071]
  7. Differentiate between arithmetic and logical if statement. [2+2] [068]
  8. Compare arithmetic and logical if statements in FORTRAN with suitable example. [4] [070]
  9. Differentiate “Logical if” with “Arithmetic if” in FORTRAN with suitable example. [6] [069]
  10. Compare unconditional goto and computed goto in FORTRAN with syntax. [3] [073]
  11. Explain different types of goto statements in FORTRAN programming with suitable example. [4] [072]
  12. Compare “Computed goto” statement (FORTRAN) and “switch” (C language). [069]
  13. How are do-loops used in FORTRAN? Explain with example. Compare it with implied do-loop. [2] [069]
  14. Explain with suitable example to show how an Implied Do loop works in FORTRAN. [4] [072]
  15. Compare DO and implied DO statement in FORTRAN. [3] [072]
  16. What is the syntax of two dimensional arrays in FORTRAN? Explain with example. [4] [069]



PROGRAM:::::::::::::::::::::::::::::::::::::::::

BRANCHING STATEMENT

  • Logical if
  • WAP to read a number from user and determine whether it is positive or negative or zero.



  • WAP to read a number from user and determine whether it is even or odd.

  • WAP in FORTRAN to test whether the accept
    ed year is leap or not.[8] [068]

  • Back
  • Arithmetic if
  • WAP to read a number from user and determine whether it is positive or negative or zero using arithmetic if statement?


  • Write a FORTRAN program to display nature of roots of a quadratic equation. Calculate and display the roots, if they are real and equal. [8] [071]


  • Write a program in FORTRAN to solve quadratic equation and display roots in proper format. [8] [070]


  • Unconditional goto statement
  • WAP to find the HCF & LCM of two integer numbers just entered by user.


  • Computed goto statement
  • WAP to read gender code (i.e. 1 for male and 2 for female) from user and display corresponding gender using computed goto statement.


  • Write a program to read a day number and display whether it is Sunday, Monday, Tuesday, Wednesday, Thursday, Friday and Saturday using both concept. [069]


  • LOOPING STATEMENT

    • do-loop
    • WAP to print the number from 1 to 5.


    • WAP to print the number up to n.


    • Write a program in FORTRAN to calculate the value of π by evaluating the following formula for the first 25 terms. [5] [074]



  • Write a program to read n from user and display the sum of following series till nth terms: 1+(1+2)+(1+2+3)+(1+2+3+4)+.....n. [4] [074]

  • Back

  • Write a FORTRAN program to read n numbers and display largest number among them. [5] [073]



  • Write a FORTRAN program to read n numbers and display smallest number among them. [5]

# NOTE SAME AS ABOVE BUT CHANGE IN EQUALITY SIGN..


  • Write a program in FORTRAN to read an array containing N elements, sort this data in ascending order and display the result. [5] [069]

  • Back

  • Write a program in FORTRAN to take a position and a number and insert this number on this position inside an array containing n elements. [8] [067] (Updated)


2D ARRAY

  • Write a program in FORTRAN to read two matrices from user find their sum and display the sum. [8] [068]


  • Write a FORTRAN program to add and subtract two matrices and display the results in matrix form. [7] [072] 



  • Write a FORTRAN program to read m*n matrix, transpose it and display both the matrices. [8] [070] 






Post a Comment (0)
Previous Post Next Post