0% found this document useful (0 votes)
46 views

A Program To Calculate The Addition of Two Numbers

This document contains programs written in Fortran to perform various mathematical calculations and illustrate programming concepts. The programs include: addition, subtraction, multiplication and division of two numbers; calculating the area and perimeter of a rectangle; converting between Celsius and Fahrenheit temperatures; calculating a summing series; finding the sum of digits in a number; inputting data; finding the roots of a quadratic equation; determining the largest of three numbers; calculating income tax based on tax slabs and rates; calculating discounts using a case statement; reading and printing a matrix; and tabulating the Poisson distribution function for integer values of k from 0 to 15.

Uploaded by

mengelhu
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views

A Program To Calculate The Addition of Two Numbers

This document contains programs written in Fortran to perform various mathematical calculations and illustrate programming concepts. The programs include: addition, subtraction, multiplication and division of two numbers; calculating the area and perimeter of a rectangle; converting between Celsius and Fahrenheit temperatures; calculating a summing series; finding the sum of digits in a number; inputting data; finding the roots of a quadratic equation; determining the largest of three numbers; calculating income tax based on tax slabs and rates; calculating discounts using a case statement; reading and printing a matrix; and tabulating the Poisson distribution function for integer values of k from 0 to 15.

Uploaded by

mengelhu
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

PGM NO:

DATE :

ADDITION OF TWO NUMBERS


AIM:
A program to calculate the addition of two numbers.
PROGRAM:
PROGRAM ADDITION
IMPLICIT NONE
INTEGER::a,b,Sum
PRINT*, Type the value of a &b
READ*,a,b
Sum=a+b
PRINT*, Sum=,Sum
END PROGRAM ADDITION

PGM NO:
DATE :

SUBTRACTION OF TWO NUMBERS


AIM:
A program to calculate the subtraction of two numbers.
PROGRAM:
PROGRAM SUBTRACTION
IMPLICIT NONE
INTEGER::a,b,SUB
PRINT*, Type the value of a &b
READ*,a,b
SUB=a-b
PRINT*, SUB=,SUB
END PROGRAM SUBTRACTION

PGM NO:
DATE :

MULTIPLICATION OF TWO NUMBERS


AIM:
A program to calculate the multiplication of two numbers.
PROGRAM:
PROGRAM MULTIPLICATION
IMPLICIT NONE
INTEGER::a,b,MULT
PRINT*, Type the value of a &b
READ*,a,b
MULT=a*b
PRINT*, MULT =,MULT
END PROGRAM MULTIPLICATION

PGM NO:
DATE :

DIVISION OF TWO NUMBERS


AIM:
A program to calculate the division of two numbers.
PROGRAM:
PROGRAM DIVISION
IMPLICIT NONE
INTEGER::a,b,DIV
PRINT*, Type the value of a &b
READ*,a,b
DIV=a/b
PRINT*, DIV =,DIV
END PROGRAM DIVISION

PGM NO:
DATE :

PROGRAM TO FIND OUT AREA AND PERIMETER OF RECTANGLE

AIM:
A program to calculate the area and perimeter of rectangle.
PROGRAM:
PROGRAM AREA_PERIMETER
IMPLICIT NONE
INTEGER:: P,Q,AREA,PERIMETER
PRINT*, ENTER THE VALUE OF LENGTH AND BREADTH
READ*,P,Q
PRINT*, P=,P, Q=,Q
AREA=P*Q
PERIMETER= 2*(P+Q)
PRINT*, AREA =,AREA, PERIMETER=,PERIMETER
END PROGRAM AREA_PERIMETER

PGM NO:
DATE :

CONVERSION OF CELSIUS TO FAHRENHEIT


AIM:
A program to convert the Celsius into Fahrenheit.
PROGRAM:
PROGRAM temp_conversion
IMPLICIT NONE
REAL:: Fahrenheit, Celsius
PRINT*, Type the value of Celsius
READ*, Celsius
PRINT*, Celsius=,Celsius
Fahrenheit=1.8*Celsius+32.0
PRINT*, Fahrenheit=, Fahrenheit
END PROGRAM temp_conversion

PGM NO:
DATE :

PROGRAM TO CALCULATE SUMMING SERIES


AIM:
A program to calculate the following series.
Sum=1- x2/2! + x4/4! - x6/6! + x8/8! - x10/10!
PROGRAM:
!PROGRAM TO SUM SERIES
PROGRAM SUM_SERIES
IMPLICIT NONE
REAL::x,x2,x3,x4,x6,x8,x10,sum
PRINT*, Type value of x
READ*,x
PRINT*, x=,x
X2=x*x
X4=x2*x2/24.0
X6=x4*x2/30.0
X8=x6*x2/56.0
X10=x8*x2/90.0
Sum=1.0-.5*x2+x4-x6+x8-x10
PRINT*, Value of x=,x, sum=,sum
END PROGRAM SUM_SERIES

PGM NO:
DATE :

SUMMING DIGITS OF A NUMBER


AIM:
A program to find the summing digits of a number.
PROGRAM:
PROGRAM sum_digits_mod
IMPLICIT NONE
INTEGER:: digit_1,digit_2,digit_3,digit_4,&digit_5,sum,n,number
PRINT*, Type a five digit number
READ*,number
PRINT*, Number=,number
n=IABS(number)
!THE MODE FUNCTION RETURNS LAST SIGNIFICANT
!DIGIT OF n
digit_1=MOD(n,10)
n=n/10
digit_2=MOD(n,10)
n=n/10
digit_3=MOD(n,10)
n=n/10
digit_4=MOD(n,10)
n=n/10
digit_5=n
sum=digit_1+digit_2+digit_4+digit_5
PRINT*, sum of digit =,sum
END PROGRAM sum_digit_mod

PGM NO:
DATE :

ILLUSTRATION OF INPUT DATA


AIM:
A program to illustrate how to input data.
PROGRAM:
PROGRAM input
IMPLICIT NONE
INTEGER::i,j
REAL::a,b,c,d
PRINT*,Type 5.847E-3,-.52589,53.25,342,583
READ*,a,b,c,i,j
PRINT*,a=,a,b=,b,c=,c
PRINT*,i=,I,j=,j
PRINT*,Type 2.5, ,9.8
READ*,a,b,c
PRINT*,Type 4*5.5
READ*,a,b,c,d
PRINT*,a=,a,b=,b,c=,d=,d
PRINT*,Type 25,3.5,9.8
READ*,a,i,b
PRINT*,a=,a,b=,b,i=,i
END PROGRAM input

PGM NO:
DATE :

ROOTS OF A QUDRATIC EQUATION


AIM:
A program to find the roots of a quadratic equation
PROGRAM:
!ROOTS OF A QUDRATIC EQUATION
!FINDING SOLUTION OF A QUADRATIC EQUATION
PROGRAM QUADRATIC
IMPLICIT NONE
REAL,PARAMETER::epsilon=0,5e-7
REAL::a,b,c,discr,xim1,xim2,xreal1,xreal2,sqrt_discr
Print*, Type values of a,b,c
READ*,a,b,c
PRINT*, a=,a, b=,b, c=,c
Discr=b*b-4*a*c
If(discr<0) then
Discr= -discr
Xim1=0.5*sqrt(discr)/a
Xim2= -xim1
Xreal1= -b*0.5/a
PRINT*, complex conjugate root
PRINT*, real part=,xreal1
PRINT*, Imaginary part=,xim1,xim2
Else if(abs(discr) < epsilon) then
Xreal1= -b*0.5/a
PRIINT*, Repeated roots
PRINT*, real roots= ,xreal1
Else
Sqrt_discr= sqrt(discr)
Xreal1= (-b+sqrt_discr)*0.5/a
Xreal2= (-b-sqrt_discr)*0.5/a
PRINT*, real roots
PRINT*, root 1=,xreal1, root 2=,xreal2
Endif
End program quadratic

PGM NO:
DATE :

PICKING THE LARGEST OF THREE NUMBERS


AIM:
A program to find largest of three numbers
PROGRAM:
!PICKING THE LARGEST OF THREE NUMBERRS
PROGRAM FIND_LARGEST
IMPLICIT NONE
INEGER::A,B,C,BIG
PRINT*, Type values of a, b, c
READ*,a,b,c
PRIINT*, a=,a, b=,b, c=,c
Big=a
If(b>big) big=b
If(c>big) big=c
PRINT*, Largest number=,big
END PROGRAM FIND_LARGEST

PGM NO:
DATE :

CALCULATION OF INCOME TAX


AIM:
A program to calculate the income tax.
The income tax rates are given by the following rules:
i.
ii.
iii.
iv.

No tax is chargeable on net taxable income <= 35,000


20% is charged on income above 35,000 but below 60,000
30% is charged on income above 60,000 but below 1,20,000
On income above 1,20,000 the rate is 40%

PROGRAM:
PROGRAM TAX_CALCULATION
IMPLICIT NONE
INTEGER::INCOME,SLAB_1,SLAB_2,SLAB_3,R_TAX
REAL::rate_1,rate_2,rate_3,tax
!read slabs and rates
PRINT*,Type values of slab 1, slab 2 and slab 3
READ*,slab_1,slab_2,slab_3
PRINT*,slab_1=,slab_1,slab_2,slab_2,slab_3,slab_3
PRINT*,Type value of rate 1,rate 2 and rate 3
READ*,rate_1,rate_2,rate_3
PRINT*,Rate_1=rate_1,rate_2=,rate_2,rate_3,rate_3
PRINT*, Type income
READ*,income !INCOME IS NET TAXABLE INCOME
PRINT*,net income=,income
If(income < slab_1) then
Tax=0
Else if(income < slab_2) then
Tax=(income-slab_1)*rate_1
Else if(income < slab_3) then
Tax=(income-slab_2)*rate_2+(slab_2-slab_1)*rate_1
Else
Tax=(income-slab_3)*rate_3+(slab_3-slab_2)*rate_2+(slab_2-slab_1)*rate_1
Endif
!CALCULATE TAX TO NEAREST RUPEE - ROUNDED TAX
R_tax=anint(tax)
PRINT*,net taxable income=,income
PPRINT*,Tax to be paid=,r_tax
END PROGRAM TAX_CALCULATION

PGM NO:
DATE :

DISCOUNT CALCULATION USING CASE


AIM:
A program to calculate discount using case
PROGRAM:
!DISCOUNT CALCULATION USING CASE
!DISCOUNT CALCULATION EXAPLE WITH SELECT CASE
PROGRAM DISCOUNT_2
IMPLICIT NONE
INTEGER::serial_no,code
REAL::amount,discount,net_amount
PRINT*,ser. Code Discount Net amount
DO
READ*,serial_no,code,amount
IF(serial_no==0)exit
Discount=0.0
SELECT CASE(code)
CASE(1)
IF(amount>=5000.0)Discount=0.1
Case(2)
If(amount>=2000.0)discount=0.1
Case(3)
If(amount>=1000.0)discount=0.1
Case default
PRINT*,error in code,serial_no,Code=,code
END select
Net_amount=amount*(1.0-discount)
Print*,serial_no,code,discount,net_amount
End do
Print*,end of processing
End program discount_2

PGM NO:
DATE :

READING AND PRINTING A MATRIX


AIM:
A program to read and print a matrix
PROGRAM:
!READING AND PRINTING A MATRIX
PROGRAM MAT_READ
IMPLICIT NONE
INTEGER, DIMENSION(2,3)::matrix
INTEGER::I,j
PRINT*,Type elements of matrix columnwise
READ*,((matrix(I,j),i=1,2),j=1,3)
Print*,(matrix(1,j)j=1,3)
Print*,(matrix(2,j),j=1,3)
End program

PGM NO:
DATE :

TABULATION OF POISSION FUNCTION


AIM:
A program to tabulate the Poisson function.
It is required to tabulate the values of the function shown below for integer values
of k from 0 to 15.
P(k) = e-a ak/k!
PROGRAM:
!TABULATION OF POISSION FUNCTION
!POISSION FUNCTION TABULATION
PROGRAM POISSION
IMPLICIT NONE
INTEGER::k
REAL::a,pois
PRINT*,Type value of a
READ*,a
PRINT*,a=,a
Pois=exp(-a)
K=0
PRINT*,k poission(k)
PRINT*,k,,pois
Do k=1,15
Pois=pois*a/real(k)
PRINT*,k, ,pois
End do
END PROGRAM poission

You might also like