# Formula Data Matematik

Document Sample

```					Fundamental data types

List-directed input/output
write a program that calculates µ value from
following equation: µ = (ma * mb) / (ma + mb)
write a program to input a number x and print the
values of x-1, x+2 and x2 +x-2.
Write a program that reads k value from keyboard
and t=4 as a coefficient, calculate and print l and m
values with the following equations.

l=2*k+8,
m=t+k
program example5
real::t,k,l,m
!integer::e
t=4
print*,"please enter a number for k"
l=2*k+8
m=t+k
print*,l
print*,m
end program example5
Write a program at home to read a Celsius
temperature and convert it to Fahrenheit using
the formula,
F=(9C/5)+32
Write a program to calculate the weight and volume of a
cylinder by using following data r=70 cm, h=280 cm,
d=0.00789, g=9.81
Find the errors in this program. Indicate them with
small circles and correct mistakes.

program 123bas
# This program prints numbers
real,:: one, two, _three
one =: 1.0
two = 2.0
three = 3
# Now the printing section
print **,one, two, _three
end program 123bas
What will be printed by the following program?
program question5
real :: a, b, c, x, y, z
integer :: k
! Let’s make some assignments:
a = 1.5
b = 3.0
c = 4.5
! Simple arithmetic:
x = b/c + 1.5
y = c/b/c
z = c/a
k = b/c + c
! Now let’s print:
print *, x, y, z, k
end program question5
   What will be printed by the following program?

Program ornek1
real::a,b,p,q,r
integer::x,y,z
a=2.5
b=4.0
p=a+b
x=a+b
q=a*b
y=a*b
r=p/q
z=x/y
print*,p,q,r
print*,x,y,z
end program ornek1
   When visitors come to dinner at his home in
Copenhagen, Mr Schmidt always makes them
Danish Apple Cake. For four people this requires
the following ingredients:

675 g of apples
75 g of butter
150 g of sugar
150 ml of cream

Write a program which inputs the number of
people coming to dinner, and then prints the
amount of each ingredient required.
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
Fundamental 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
real and integer variables

   Variable declaration:
type :: name

type :: name1, name2, …
   integer :: a, b, c
   real :: x, y, z
Arithmetic expressions

   A combination of variables, constants,
operators, parentheses…

Assignment

name = expression

replace the content of the variable name
with the result of the expression
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
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
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 Z
a   b   c   d   e   f   g   h   i   j k l m n o p q r s t u w x y z
0   1   2   3   4   5   6   7   8   9
ǉ   =   +   -   *   /   (   )   ,   . ' : ! " % & ; < > ? \$

   Declaration:
character (len=length) :: name1, name2, …
character (len=6) :: a, b, c
character (len=10*3):: a
character (len=10) :: b

   Assignment
a = "What a lovely afternoon!"
a will have the value of "What a lovely
afternoon!ǉǉǉǉǉǉ"
b = a
b will have the value of "What a lov"
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"
Please write a program for the given example in the previous
slide.
Write a program that read the first name, middle name and
last name of a person and print it as the following format.

Dursun Zafer Seker ----- Dursun Z. Seker
Write a program which prints the abbreviation of “POSTA
TELGRAF TELEFON”
Sayın ilgili,

50199045 nolu Ahmet Suna adli ogrencimiz

Ogrenci otomasyon merkezi

ayrı alarak yukarıdaki dilekceyi yazabilen bir
program yaziniz.
Write a program, which asks the user following
instructions, and print a program to specify the code
of a lesson by using format expressions.

Which department this lecture belongs to?
(ex: BILGISAYAR, INSAAT, MATEMATIK..)

What is the Lecture code? (ex: 106, 432, 313)

In which language this lecture is given. (ex:
ENGLISH, TURKISH)      Example: BIL106E
Named constants
   type, parameter :: name1=constant_expression1, …

real, parameter :: pi=3.1415926, pi_by_2 = pi/2.0
integer, parameter :: max_lines = 200
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 4, 2002
!
program Cel_Fah
real :: CEL, FAH
print *, "Please Enter Celsius Temperature"
FAH = 9.0*CEL/5.0+32.0
print*,"Celsius = ",CEL," Fahrenheit = ", FAH
end program Cel_Fah
Example
! Name : Dursun Zafer Seker
! Address : ITU, Faculty of Civil Engg. 80626 Maslak, Istanbul
!! Date : March 4, 2002
!
program Sin_Cos_Tan
real, parameter :: PI = 3.1415926
print *, "Please Enter Value of Angle in degrees"
print*,"angle = ",angle," Sinx = ",S," Cosx = ",C," Tanx = ",T
end program Sin_Cos_Tan
Example
program list_directed_input_example
!integers
integer::int_1, int_2, int_3
real::real_1, real_2, real_3
!initial values
int_1=-1
int_2=-2
int_3=-3
real_1=-1.0
real_2=-2.0
real_3=-3.0
read*, int_1, real_1, int_2, real_2,int_3, real_3
!print new values
print*, int_1, real_1, int_2, real_2,int_3, real_3
end program list_directed_input_example
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"
al=area (a,b)
print *, "a=",a
print*,"b=",b
print *, "area_of_rectangle=",al
endprogram area_calculation

```
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
 views: 172 posted: 4/20/2011 language: English pages: 30
Description: Formula Data Matematik document sample