1 / 15

Fundamental data types List-directed input/output Week 3

Fundamental data types List-directed input/output Week 3. Fundamental types of numbers. Integers Whole numbers (positive/negative/zero) Examples: 1952 3456787890123 0 -2334567 Typical range on a 32-bit computer -2 x 10 9 to +2 x 10 9. Fundamental types of numbers. Reals

Download Presentation

Fundamental data types List-directed input/output Week 3

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Fundamental data types List-directed input/output Week 3

  2. Fundamental types of numbers • Integers • Whole numbers (positive/negative/zero) • Examples: 1952 3456787890123 0 -2334567 • Typical range on a 32-bit computer -2 x 109 to +2 x 109

  3. Fundamental types of numbers • Reals +/-xxx.yyyyy xxxinteger part yyyyy fractional part • A better representation: • Sign: +/- • Mantissa: a fraction between 0.1 and 1.0 • Exponent: x 10e -0.923456 x 10-6 or -0.923456e-6

  4. real and integer variables • Variable declaration: type :: name type :: name1, name2, … • integer :: a, b, c • real :: x, y, z

  5. Arithmetic expressions • A combination of variables, constants, operators, parentheses… (4*Pi*Radius* *2 + 1.2098)/2.3

  6. Assignment name= expression replace the content of the variablename with the result of the expression

  7. List-directed input and output • read *, var_1, var_2, … • only variables! • print *, item_1, item_2, … • variables, constants, expressions, … • Value separators: • Comma (,) • Space • Slash (/) • End-of-line

  8. List-directed input and output • Two consecutive commas: • a null value is read • the value of the variable is not set to zero, simply its value is not changed! • If the terminating character is a slash then no more dataitems are read; processing of the input statement is ended • Example

  9. Character data • A B C D E F G H I J K L M N O P Q R S T U W X Y Za b c d e f g h i j k l m n o p q r s t u w x y z0 1 2 3 4 5 6 7 8 9lj = + - * / ( ) , . ' : ! " % & ; < > ? $ • Declaration: character (len=length) :: name1, name2, … character (len=6) :: a, b, c character (len=10*3):: a character (len=10) :: b • Assignmenta = "What a lovely afternoon!" a will have the value of "What a lovely afternoon!ljljljljljlj"b = ab will have the value of "What a lov"

  10. Character data • Concatenation: • Operator // • Example: character (len=10) a, b, c a = "James" b = "Bond" c = trim(a)//"ž"//trim(b) c will have the value of "James Bond"

  11. Named constants • type, parameter :: name1=constant_expression1, … real, parameter :: pi=3.1415926, pi_by_2 = pi/2.0 integer, parameter :: max_lines = 200

  12. Example ! Name : Dursun Zafer Seker ! Tel : +90 (212) 285 3755 (office) ! Address : ITU, Faculty of Civil Engg. 80626 Maslak, Istanbul ! Purpose : Converts Celsius to Fahrenheit ! Date : March 14, 2001 ! Comments:..... ! program Cel_Fah real :: CEL, FAH print *, "Please Enter Celsius Temperature" read *, CEL FAH = 9.0*CEL/5.0+32.0 print*,"Celsius = ",CEL," Fahrenheit = ", FAH end program Cel_Fah

  13. Example ! Name : Dursun Zafer Seker ! Address : ITU, Faculty of Civil Engg. 80626 Maslak, Istanbul !! Date : March 14, 2001 ! Comments:..... ! program Sin_Cos_Tan real :: angle,S,C,T,RAD real, parameter :: PI = 3.1415926 print *, "Please Enter Value of Angle in degrees" read *, angle RAD = angle/(180.0/PI) S = sin(RAD) C = cos(RAD) T = tan(RAD) print*,"angle = ",angle," Sinx = ",S," Cosx = ",C," Tanx = ",T end program Sin_Cos_Tan

  14. Example program list_directed_input_example!integersinteger::int_1, int_2, int_3real::real_1, real_2, real_3!initial valuesint_1=-1int_2=-2int_3=-3real_1=-1.0real_2=-2.0real_3=-3.0!read dataread*, int_1, real_1, int_2, real_2,int_3, real_3!print new valuesprint*, int_1, real_1, int_2, real_2,int_3, real_3end program list_directed_input_example

  15. Example !this program is calculates area of a rectangle program area_calculation use rec real::a,b,al print *, "enter two edges of the rectangle" read *, a,b al=area (a,b) print *, "a=",a print*,"b=",b print *, "area_of_rectangle=",al endprogram area_calculation

More Related