Title: Fundamental data types
1- Fundamental data types
- List-directed input/output
2Fundamental 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
3Fundamental types of numbers
- Reals
- /- xxx.yyyyy
- xxx integer 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
4real and integer variables
- Variable declaration
- type name
- type name1, name2,
- integer a, b, c
- real x, y, z
5Arithmetic expressions
- A combination of variables, constants, operators,
parentheses - (4PiRadius 2 1.2098)/2.3
6Assignment
- name expression
- replace the content of the variable name with the
result of the expression
7List-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
8List-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
9Character 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 9? - / ( ) , . ' ! "
lt gt ? - Declaration
- character (lenlength) name1, name2,
- character (len6) a, b, c
- character (len103) a
- character (len10) b
- Assignmenta "What a lovely afternoon!" a will
have the value of "What a lovely
afternoon!??????"b ab will have the value of
"What a lov"
10Character data
- Concatenation
- Operator //
- Example
- character (len10) a, b, c
- a "James"
- b "Bond"
- c trim(a)//"?"//trim(b)
- c will have the value of "James Bond"
11Named constants
- type, parameter name1constant_expression1,
- real, parameter pi3.1415926, pi_by_2 pi/2.0
- integer, parameter max_lines 200
12Example
! 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.0CEL/5.032.0 print,"Celsius ",CEL,"
Fahrenheit ", FAH end program Cel_Fah
13Example
! 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
14program list_directed_input_example!integersinte
gerint_1, int_2, int_3realreal_1, real_2,
real_3!initial valuesint_1-1int_2-2int_3-3
real_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
Example
15Example
!this program is calculates area of a
rectangle program area_calculation use
rec reala,b,al print , "enter two edges of the
rectangle" read , a,b alarea (a,b) print ,
"a",a print,"b",b print , "area_of_rectangle"
,al endprogram area_calculation
16Exercises
- Write a program for the following equations
- abc
- write a program to input a number x and print the
values of x-1, x2 and x2 x-2, - write a program which read a Fahrenheit
temperature and then convert it to Celcius, - write a program that calculates µ value from
following equation - µ (ma mb) / (ma mb)
-
17Example PROBLEM Prepare a computer program
which calculates the volume the
weight of a steel cylinder having the following
initial values radius r 70
cm height h 280 cm density
d 7.89 kg / dm3