Вы находитесь на странице: 1из 8

ASSIGNMENT OF FORTRAN PROGRAMMING

SUBMITTED TO: DR. UGUR GUVEN SUBMITTED BY: ARCHANA NAITHANI R340308007

DEPARTMENT OF AEROSPACE ENGINEERING

UNIVERSITY OF PETROLEUM AND ENERGY STUDIES DEHRADUN

Ques 1) Write a program to separately calculate sum of successive even integers from 2 to 200
and the sum of successive odd integers from 1 to 199 and print them separately. Allow user to enter the highest and the lowest limit, but print the result for the values given above. Ans) PROGRAM SUM ! Naming the program as SUM IMPLICIT NONE ! Declaring the program as NON-IMPLICIT INTEGER A,C,I,B,S,G ! Declaring the variables as integer PRINT*," ENTER THE LOWEST LIMIT AS 1" ! Ask the user to enter the lowest value READ*,A ! Take the lowest value as input in variable A PRINT*,"ENTER THE HIGHEST LIMIT AS 200"! Ask the user to enter the highest value READ*,B ! Take the highest value as input in variable B DO I=A,B ! Run the loop from lowest to highest value C=MOD(I,2) ! Store the value of remainder of I divided by 2 in C IF (C==0)THEN ! Apply condition for even and odd. S=S+I ! If even then store the value in S adding the previous value stored ELSE ! Else if not even. G=G+I ! If it is odd store the value in G adding the previous value stored. END IF ! End the IF condition END DO ! End the DO loop. PRINT*,"SUM OF EVEN INTEGERS IS",S ! Print the sum of even numbers. PRINT*," SUM OF ODD INTEGERS IS",G ! Print the sum of odd numbers END PROGRAM SUM ! End the program SUM

The program appears as the following screen in developer studio.

When executed the following output appears. ENTER THE LOWEST LIMIT AS 1 1 ENTER THE HIGHEST LIMIT AS 200 200 SUM OF EVEN INTEGERS IS 10100 SUM OF ODD INTEGERS IS 10000

Ques 2) Write a program to calculate the Reynolds number and the Prandtl number based upon the inputted value. Let the program determine whether the flow is subsonic or supersonic by analyzing the speed value. Print the result of the flow. Ask the user whether he or she wants to run the program again? Ans) PROGRAM REPR ! Naming the program IMPLICIT NONE ! Declaring the program as non implicit REAL,PARAMETER::S=330 ! Declaring a constant s with the value of 330 as velocity. REAL DENSITY,VEL,DIA,VIS,C,K,RE,PR,M ! Declaring the variables as realtype. CHARACTER A*5 ! Declaring a variable A as character type. 90 PRINT*,"ENTER DENSITY,VELOCITY,DIAMETER,VISCOSITY,SPECIFIC HEAT CAPACITY AND THERMAL CONDUCTIVITY" ! asking the user to input the values READ*,DENSITY,VEL,DIA,VIS,C,K ! Taking the values of different variables as input. RE=(DENSITY*VEL*DIA)/VIS ! Applying the formula for reynolds number. PR=(C*VIS)/K ! Applying the formula for prandtl number. PRINT*,"THE REYNOLDS NUMBER IS",RE,"AND PRANDTL NUMBER IS",PR

! Printing the value of reynold and Prandtl number. M=VEL/S ! Calulating the value of Mach number and storing it in variable M. IF(M<1)THEN ! Applying IF condition. PRINT*," THE FLOW IS SUBSONIC" ! If mach number is less than one then print subsonic flow. ELSE IF(M==1)THEN PRINT*,"THE FLOW IS TRANSONIC ! If mach number is equal to 1 then print flow is transonic. ELSE IF(M>1)THEN PRINT*,"THE FLOW IS SUPERSONIC" ! If mach number is greater than 1 then print supersonic flow. ELSE IF(M>5)THEN PRINT*,"THE FLOW IS HYPERSONIC" ! If mach number is greater than 5 then print hypersonic flow. ELSE ! Else condition. PRINT*,"SOMETHING IS WRONG!!" END IF ! End the if condition. PRINT*,"DO YOU WANT TO CONTINUE?" ! Ask the user if he/she wants to continue? READ*,A ! Read the value in character A. IF(A=="YES".OR.A=="yes")THEN ! If the reader says yes GOTO 90 ! Move to the printing statement. ELSE GOTO 99 ! If the user denies then end the program. END IF ! End the if condition. 99 END PROGRAM REPR ! End the program.

When executed the program gives the following output. ENTER DENSITY, VELOCITY, DIAMETER, VISCOSITY, SPECIFIC HEAT CAPACITY AND THERMAL CONDUCTIVITY. 5 4562 78 45 14 56 THE REYNOLDS NUMBER IS 39537.330000 AND THE PRANDTL NUMBER IS 11.250000 THE FLOW IS SUPERSONIC DO YOU WANT TO CONTINUE? YES ENTER DENSITY, VELOCITY, DIAMETER, VISCOSITY, SPECIFIC HEAT CAPACITY AND THERMAL CONDUCTIVITY. 89 5620 78

45 74 86 THE REYNOLDS NUMBER IS 866978.700000 AND THE PRANDTL NUMBER IS 38.720930 THE FLOW IS SUPERSONIC DO YOU WANT TO CONTINUE? NO Press any key to continue_

Ques 3) Write a program that calculates the velocity of an airplane by reading the pressure difference from a Venturimeter. Ans) PROGRAM VENTURI ! Naming the program. IMPLICIT NONE ! Defining the program as non implicit. REAL V,P1,P2,DEN,A1,A2,S,C,D ! Declaring the variables as real. PRINT*,"ENTER PRESSURE AT INLET,PRESSURE AT VENTURI,DENSITY,AREA OF TUBE AND AREA OF VENTURI" ! Ask the user to input the values. READ*,P1,P2,DEN,A1,A2 ! Take the values of the parameters as defined. C=(A1/A2)**2 ! Formula caluclating ratios of area minus 1 stored in variable C V=(P1-P2) ! Calculating pressure difference. S=(2*V)/(DEN*(C-1)) ! Calculating the velocity square and storing it in variable S. D=(S**0.5) ! Calculating the velocity and storing it in variable D. PRINT*,"THE VELOCITY IS",S ! Print the velocity value. END PROGRAM VENTURI ! End the program Venturi.

When executed the programme gave the output as follows. ENTER PRESSURE AT INLET, PRESSURE AT VENTURI, DENSITY, AREA OF TUBE AND AREA OF VENTURI 12 15 1.3 21 23 THE VELOCITY IS 27.744750 Press any key to continue_

Ques 4) Write a program that determines the letter grade of the student as based upon his numerical grade. Use the following scale for determination. -90 to 100: A -70 to 89 : B -50 to 69 : C -40 to 49 : D - 0 to 39 : F Ans) PROGRAM GRADE ! Naming the program IMPLICIT NONE ! Declaring the program as non implicit. REAL X ! Declaring the variable X as real. CHARACTER A*5 ! Declaring the variable A as character. 90 PRINT*,"ENTER THE MARKS OF THE STUDENTS OUT OF 100" ! Ask the user to input the marks. READ*,X ! Take the input and store in variable X IF(X>=90.AND.X<=100)THEN ! Define the conditions. PRINT*," THE GRADE IS A" ! Print the grade. ELSE IF(X>=70.AND.X<=89)THEN ! Define the conditions. PRINT*," THE GRADE IS B" ! Print the grade. ELSE IF(X>=51.AND.X<=69)THEN ! Define the conditions. PRINT*," THE GRADE IS C" ! Print the grade. ELSE IF(X>=40.AND.X<=50)THEN ! Define the conditions. PRINT*," THE GRADE IS D" ! Print the grade. ELSE ! Else condition. PRINT*," THE GRADE IS F" ! Print the grade. END IF ! End the If condition. PRINT*,"DO YOU WANT GRADE FOR ANOTHER STUDENT? IF YOU DO ENTER YES OR yes." ! Ask the user if he wants to continue. READ*,A ! Take the user input and store in A. IF(A=="YES".OR.A=="yes")THEN GOTO 90 ! If the user says yes then move to print command. ELSE GOTO 99 ! If he says no then end the program. END IF ! End the if condition. 99 END PROGRAM GRADE ! End the program Grade. When executed the program gave following result. ENTER THE MARKS OF THE STUDENTS OUT OF 100 23 THE GRADE IS F DO YOU WANT GRADE FOR ANOTHER STUDENT? IF YOU DO ENTER YES OR yes. yes ENTER THE MARKS OF THE STUDENTS OUT OF 100 96 THE GRADE IS A DO YOU WANT GRADE FOR ANOTHER STUDENT? IF YOU DO ENTER YES OR yes.

NO Press any key to continue_

Output:

Вам также может понравиться