Professional Documents
Culture Documents
Set-I
Q. No. 1.1 Write a programme to input the temperature in celcius and convert into
farenheight.
Use formula:
* This is a program to convert temperature from celcius to farenheight
write(*,*)'Input temperature in celcius'
read(*,*)c
f=9./5*c+32
write(*,*)'The equivalent temperature in Farenheight is',f
end
1
Wednesday, September 24, 2008 Fortran for bce-I/II
Q. No. 1.2. Wrie a programme to calculate the area of triangle when three sides are
given.
We Have a, b, c are theree sides of triangle then:
a<b+c
b<c+a
c<a+b
S = (a + b + c) / 2
Area ( A ) = sqrt ( s ( s - a ) ( s - b ) ( s - c ) )
* This is a programme to calculate area of Tiangle using three sides
1 write(*,*)'Enter first side of triangle ie. a'
read(*,*)a
write(*,*)'Enter second side of triangle ie. b'
read(*,*)b
write(*,*)'Enter third side of triangle ie. c'
read(*,*)c
x=b+c
y=c+a
z=a+b
s=0.5*(a+b+c)
If(x.gt.a.and.y.gt.b.and.z.gt.c) then
area=sqrt(s*(s-a)*(s-b)*(s-c))
write(*,*)'The area of triangle is:',area
else
write(*,*)'......................'
write(*,*)'An error has been occured'
write(*,*)'These values of a,b,c doesnot form triangle'
write(*,*)'Plz check the sides and try again'
write(*,*)
write(*,*)'Again'
goto 1
endif
end
Q. No. 1.3.Write a programme to solve simultaneous equations of two unknowns of the
form:
a1x+b1y=c1
2
Wednesday, September 24, 2008 Fortran for bce-I/II
a2x+b2y=c2
3
Wednesday, September 24, 2008 Fortran for bce-I/II
Set-II
Q. No. 2.1 Wrie a programme to find maturity value (V)
*program to find the maturity value (v)
write(*,*)’enter the values of p,r and y’
read(*,*) p,r,y
v=p*(1+r/100)**y
write(*,*) ‘the value of v is ‘,v
stop
end
Q. No. 2.2 Wrie a programme to input the two sides of a triangle and the angle (in
degree) invcluded by them and calculate the third side.
Use formula:
Remaining Third Side C = Sqrt (a2 + b2- 2ab*Cos X)
* This is a programme to calculate third side of triangle by inputing two
* sides and angle between them
write(*,*)'The first side of triangle is '
read(*,*)a
write(*,*)'The second side of triangle is '
read(*,*)b
write(*,*)'The angle in degree betn 1st side and 2nd side is '
read(*,*)x
c=sqrt(a**2+b**2-2*a*b*cos(3.1415*x/180))
write(*,*)'The Third of triangle is c=',c
end
Q. No. 2.3.Wrie a programme tocalculate the length of parabola when height (h) and base
length (2b) is given:
Use Formula:
L = Sqrt [4h2 + b2] + b2/2h * Ln [(2h + sqrt[4h2 + b2) / b]
* This is a programme to calculate the length of parabola height and base
* length is given
real l
4
Wednesday, September 24, 2008 Fortran for bce-I/II
Set-III
Q. No. 3.1. Wrie a programme to solve a quadrantic equation using arithmatic IF
Evaluation of Discreminant:
Quadratic Equation: ax2 + bx + c = 0
Discreminant d2 = b2 - 4ac
* This is a programme to solve quadratic equation
write(*,*)'Enter the coefficient of second degree of x ie. a'
read(*,*)a
write(*,*)'Enter the coefficient of first degree of x ie. b'
read(*,*)b
write(*,*)'Enter the constant ie. c'
read(*,*)c
d=b*b-4*a*c
If(d-0) 1,2,3
2 x=b**2/2./a
write(*,*)'The values of x coincide & equal to x=',x,x
goto 100
3 x1=(-b+sqrt(d))/2./a
x2=(-b-sqrt(d))/2./a
write(*,*)'The values are real and distinct and are x=',x1,x2
goto 100
1 x1=-b/2./a
5
Wednesday, September 24, 2008 Fortran for bce-I/II
x2=sqrt(abs(d))/2./a
x3=-x2
write(*,*)'The values of x are immmaginary'
write(*,*)'The first value is',x1,'+',x2,'i'
write(*,*)'The second value is',x1,'-',x2,'i'
100 stop
end
Q. No. 3.2. Wrie a programme to generate a multiplication table of a given number.
* This is a programme to generate the multiplication table
integer a,c
write(*,*)'Enter the number whose multiplication table is needed'
read(*,*)a
write(*,*)'Enter the no. upoto which table is to be calutlated'
read(*,*)j
do 10 i=1,j,1
c=a*i
write(*,1)a,i,c
1 format(1x,i4' x'i3' ='i5)
10 continue
End
Q. No. 3.3. Wrie a programme to find the factorial of a given number.
* This is a programme to calculate the factorial of a given number
write(*,*)'Enter the number'
read(*,*)n
j=1
do 10 i=1,n,1
j=i*j
10 continue
write(*,*)n,'!=',j
end
Q. No. 3.4. Write a programme to input the year and display wheather it is leap year or
not.
* This is a programme to check fo leap year
6
Wednesday, September 24, 2008 Fortran for bce-I/II
integer year
write(*,*)'Input the year'
read(*,*)year
If(mod(year,400).eq.0) goto 1
If(mod(year,100).eq.0) goto 2
If(mod(year,4).eq.0) goto 1
write(*,*)'This is not leap year',year
goto 3
1 write(*,*)'This is a leap year',year
goto 3
2 write(*,*)'This is a leap year',year
3 stop
end
Set-IV
Q. No. 4.1. Wrie a programme to Check wheather a given number is prime or not.
* This is a programme to check wheather given number is prime or not
write(*,*)'Enter the number'
read(*,*)n
do 10 i=2,n/2
if(mod(n,i).eq.0) goto 1
10 continue
write(*,*)'It is a prime number'
goto 2
1 write(*,*)'It is not a prime number'
2 end
Q. No. 4.2. Wrie a programme to compute the reverse of a given integer number.
7
Wednesday, September 24, 2008 Fortran for bce-I/II
read(*,*)n
k=n
m=0
10 m=m*10+mod(k,10)
k=k/10
If(k.gt.0) goto 10
end
Q. No. 4.3. Wrie a programme to chek wheather the given number is perfect number or
not.
* This is a program to check wheather given number is perfect or not
Write(*,*)'Enter the number that u wanna to check for a perfect'
write(*,*)'number'
read(*,*)n
nsum=0
do 10 i=1,n/2,1
10 if(mod(n,i).eq.0) nsum=nsum+i
if(nsum.ne.n) goto 1
write(*,*)n,' is a perfect number'
goto 2
1 write(*,*)n,' is not perfect number'
2 stop
End
Q. No. 4.4. Wrie a programme to check wheather given number is Armsturng Number or
not.
8
Wednesday, September 24, 2008 Fortran for bce-I/II
read(*,*)n
k=n
m=0
33 m=m+1
k=k/10
if(k.gt.0) goto 33
k=n
j=0
100 j=(mod(k,10))**m +j
k=k/10
if (m.eq.1)then
stop
endif
11 if(j.eq.n) then
else
endif
end
9
Wednesday, September 24, 2008 Fortran for bce-I/II
Integer a,b
read(*,*)n
kount=1
b=10
write(*,5)n
1 m=0
a=b
2 m=m+1
a=a/10
if(a.gt.0) goto 2
j=0
a=b
3 j=(mod(a,10))**m+j
a=a/10
if(a.gt.0) goto 3
a=b
if(j.eq.a) then
write(*,*)a
10
Wednesday, September 24, 2008 Fortran for bce-I/II
kount=kount+1
endif
b=b+1
if (kount.le.n) goto 1
end
Q. No.4.4.2. Wrie a programme to generate all Armstrung Nos. within specified range.
integer a,b
read(*,*)a
read(*,*)b
if(b.lt.153) goto 44
if (a.le.9) a=10
do 50 i=a,b
k=i
m=0
33 m=m+1
k=k/10
if(k.gt.0) goto 33
sum=0
11
Wednesday, September 24, 2008 Fortran for bce-I/II
k=i
j=(mod(k,10))**m
sum=sum+j
k=k/10
goto 100
60 if (sum.eq.i) write(*,*)i
50 continue
goto 45
45 end
Set-V
Q. No. 5.1. Write a programme to calculate the mothly electricity bill amount on the
basis of following criteria:
Minimum Charge (Upto 20 Unite) = Rs. 80.00
21 to 250 units = Rs. 7.30 per unit.
250 unit or above = Rs. 10.5 per unit.
* This is a programme to calculate mothly bill of electricity
Integer R
write(*,*)'Input the meter reading in unit'
read(*,*)r
If(r.le.20)goto 1
If(r.gt.20.and.t.le.250)goto 2
If(r.gt.250)goto 3
1 b=80
12
Wednesday, September 24, 2008 Fortran for bce-I/II
13
Wednesday, September 24, 2008 Fortran for bce-I/II
term=term*x/(i-1)
1 sum=sum+term
write(*,*)'The value of e^',x,' is =',sum
end
Q. No. 5.3. Wrie a programme to find sum upto N terms of series:
Π = 4* (1-1/3+1/5-1/7+ …………………
<!--[if !supportLineBreakNewLine]-->
<!--[endif]-->
*To find the value of PI
Write(*,*) 'enter no. od terms n'
Read(*,*) n
Term=1
Sum=0
sign=-1
Do 5 i=1,n
Sum=sum+term
Term=sign/(2*i+1)
sign=-1*sign
5 continue
Write(*,*) 'the value of PI is :',sum*4
End
Set-VI
Q. No. 6.1. Wrie a programme to compute Mean, Variance and Standard Deviation from
N data inputs.
Mean = ∑x/N
Variance = (N(∑x2) - (∑x)2)/N(N-1)
SD = Sqrt (Variance)
* This is a programme to calculate the mean, vaiance, and SD
write(*,*)'Input the number of data ie. N'
read(*,*)n
sumx=0
14
Wednesday, September 24, 2008 Fortran for bce-I/II
sumxsq=0
i=1
2 if(i.gt.n)goto 1
write(*,*)'Entr the values of x'
read(*,*)x
sumx=sumx+x
sumxsq=sumxsq+x**2
i=i+1
goto 2
1 xmean=(sumx)/n
var=(n*(sumxsq)-(sumx)**2)/(n*(n-1))
SD=sqrt(var)
write(*,*)'The mean value =',xmean
write(*,*)'The variance =',var
write(*,*)'The Standard Deviation =',sd
end
Q. No. 6.2. Wrie a programme to generate all prime numbers within a given range.
* This is a progrmme to generate all prime numbers within range
integer a,b
write(*,*)'Enter the lower range'
read(*,*)a
write(*,*)'Enter the upper range'
read(*,*)b
if(a.gt.b) then
k=a
a=b
b=k
end if
if(a.le.1) a=2
if(b.le.1) b=50
write(*,*)'The prime numbers within range are'
do 5 i=a,b
do 6 j=2,i/2
15
Wednesday, September 24, 2008 Fortran for bce-I/II
6 if( mod(i,j).eq.0)goto 5
write(*,*)i
5 continue
End
Q. No. 6.2.1. Wrie a programme to generate first n prime numbers.
* This is a pogramme to generate first n prime numbers
integer count
write(*,*)'Enter the number hou many u wanna to see'
read(*,*)n
write(*,*)'The first',n,' prime numbers are'
count=1
m=2
22 If(count.gt.n)goto 100
do 1 i=2,m/2
if(mod(m,i).eq.0)goto 8
1 continue
write(*,*)m
count=count+1
8 m=m+1
goto 22
100 stop
End
Q. No. 6.3. Wrie a programme to compute natural logarithm table of values from 1.0 ,
1.1,1.2- - - - - - - - -to 9.8,9.9 in the following format
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9
1 - - - - - - - - - - - - - - - - -- --
2 -- -- -- -- -- -- -- -- -- --
3 -- -- -- -- -- -- -- -- -- --
4 -- -- -- --- -- -- -- -- -- --
5 -- -- -- -- -- -- -- -- -- --
6 -- -- -- -- -- -- -- -- -- --
7 -- -- -- -- -- -- -- -- -- --
8 -- -- -- -- -- -- -- -- -- --
16
Wednesday, September 24, 2008 Fortran for bce-I/II
9 -- -- -- -- -- -- -- -- -- --
* program to display log table
write(*,*) 'log table is:'
write(*,1) (a/10,a=0,9)
do 10 i=1,9
10 write(*,2) i,(log(i+a/10),a=0,9)
2 format(1x,i2,10(2x,f5.3))
1 format(/,/,1x,10(5x,f2.1))
end
Q. No. 7.1. Wrie a programme to compute the inner-product of 2 arrays with same numer
of elements.
real a(100),b(100)
read(*,*)n
17
Wednesday, September 24, 2008 Fortran for bce-I/II
do 1 i=1,n
1 read(*,*) a(i)
read(*,*) (b(i),i=1,n)
sum=0
do 2 i=1,n
sum=sum+a(i)*b(i)
2 continue
end
Q. No. 7.2. Wrie a programme to read an array of numbers with N elements and sort the
elemnts in decending order.
real a(100),b(100)
read(*,*)n
read(*,*)(a(i),i=1,n)
do 10 i=1,n
do 20 j=i+1,n
if(a(i).le.a(j)) then
18
Wednesday, September 24, 2008 Fortran for bce-I/II
temp=a(i)
a(i)=a(j)
a(j)=temp
endif
20 continue
write(*,*)a(i)
10 continue
end
Dimension x(100),y(100)
read(*,*)n
read(*,*) (x(i),i=1,n)
read(*,*) (y(i),i=1,n)
xsum=0
ysum=0
xysum=0
19
Wednesday, September 24, 2008 Fortran for bce-I/II
xsq=0
ysq=0
do 1 i=1,n
xsum=xsum+x(i)
1 ysum=ysum+y(i)
xmean=xsum/n
ymean=ysum/n
do 2 i=1,n
xdiff=x(i)-xmean
ydiff=y(i)-ymean
xysum=xysum+xdiff*ydiff
xsq=xsq+xdiff**2
2 ysq=ysq+ydiff**2
r=xysum/sqrt(xsq*ysq)
end
Q. No. 8.1. Wrie a programme to compute D=AB+CT,where A,B,C and D are all
matrices of valid order and CT is the transpose of C.
20
Wednesday, September 24, 2008 Fortran for bce-I/II
goto 200
100 write(*,*)'Such order of matrix can not be multiplied'
write(*,*)'Again'
200 write(*,*)'Enter the order of matrix A'
read(*,*)m,n
write(*,*)'Enter the order of matrix B'
read(*,*)p,q
write(*,*)'Enter the order of matrix C'
read(*,*)r,s
if (n.ne.p.or.m.ne.s.or.q.ne.r) goto 100
write(*,*)'Enter the elements of matrix A:'
read(*,*) (( A(i,j),j=1,n),i=1,m)
write(*,*)'Enter the elements of matrix B:'
read(*,*) ((B(i,j),j=1,p),i=1,q)
write(*,*)'Enter the elements of matrix B:'
read(*,*) ((C(i,j),j=1,r),i=1,s)
write(*,*)'the value of AB+CT is:'
do 3 i=1,m
do 3 j=1,q
D(i,j)=0
do 3 K=1,n
3 D(i,j)=d(i,j)+a(i,k)*b(k,j)
do 4 i=1,s
do 4 j=1,r
4 C(i,j)=C(j,i)
do 5 i=1,m
do 5 j=1,q
5 D(i,j)=D(i,j)+C(i,j)
do 6 i=1,m
6 write(*,*)(D(I,j),j=1,q)
end
Q. NO. 8.2. Wrie a programme to check or matrix wheather it is symmetric or not.
*to check or symmetric matrix
21
Wednesday, September 24, 2008 Fortran for bce-I/II
real A(10,10)
2 write(*,*)'enter the order of matrix A'
read(*,*)m,n
write(*,*)'enter the elements'
read(*,*)((A(i,j),j=1,m),j=i,n)
if (m.ne.n) goto 2
do 1 i=1,m
do 1 j=1,n
if(A(i,j).ne.a(j,i)) then
write(*,*)'the matrix is not symmetric'
end if
stop
1 continue
write(*,*)'the matrix is symmetric'
stop
end
# a data file defined as old status in the programme should exist in the defined
location .
# a data file defined as new satus in the programme shouldnot exist in the defined
location.
Q-9.1 Wrie a programme to calculate the standard deviation of data stores in a data file.
open(1,file='data.txt',status='old')
n=0
sumx=0
sumxsq=0
22
Wednesday, September 24, 2008 Fortran for bce-I/II
1 read(1,*,end=100)x
n=n+1
sumx=sumx+x
sumxsq=sumxsq+x**2
goto 1
100 var=(N*sumxsq-sumx**2)/((n-1)*n)
sd=sqrt(var)
endfile 1
end
Q. No. 9.2. Wrie a programme to read the dimensions and elements of two matrices from
a data file and multiply them and store the result in another data file.
23
Wednesday, September 24, 2008 Fortran for bce-I/II
c(i,j)=0
do 1 k=1,na
c(i,j)=c(i,j)+a(i,k)*b(k,j)
1 continue
write(*,*)
write(*,*)'See the answer in 102.txt'
write(*,*)
write(2,*)'The resultant matrix A x B ='
write(*,*)
do 2 i=1,ma
2 write(2,*) (c(i,j),j=1,nb)
endfile 1
endfile 2
goto 99
11 write(*,*) 'Insufficient data in data file'
99 stop
End
Q. No. 9.3. Wrie a programme to read the marks of n students in 5 subjcts an do the
following:
i> Compute total marks, percentage, minimum and maimum marks obtained by each
students.
ii> Compute average, minimum and maximum marks obtained in each subject.
--------------------------------------------------------------------------------
real marks(10,5),rper(10),rtot(10),rmax(10),rmin(10)
real ctot(5),cavg(5),cmax(5),cmin(5)
24
Wednesday, September 24, 2008 Fortran for bce-I/II
read(*,*)n
if (n.gt.10) goto 10
do 20 i=1,n
write(*,*)'students #',i
20 read(*,*) (marks(i,j),j=1,5)
do 30 i=1,n
rtot(i)=0
rmin(i)=marks(i,1)
rmax(i)=marks(i,1)
do 40 j=1,5
rtot(i)=rtot(i)+marks(i,j)
if (marks(i,j).lt.rmin(i)) rmin(i)=marks(i,j)
if (marks(i,j).gt.rmax(i)) rmax(i)=marks(i,j)
40 continue
rper(i)=rtot(i)/5
30 continue
do 50 j=1,5
ctot(j)=0
cmax(j)=marks(1,j)
25
Wednesday, September 24, 2008 Fortran for bce-I/II
cmin(j)=marks(1,j)
do 60 i=1,n
ctot(j)=ctot(j)+marks(i,j)
if (marks(i,j).gt.cmax(j)) cmax(j)=marks(i,j)
if (marks(i,j).lt.cmin(j)) cmin(j)=marks(i,j)
60 continue
cavg(j)=ctot(j)/n
50 continue
Write(*,1)'RN','Math','Engg','Sci','Nep','His','Tot','Per',
$'Min','Max'
do 80 i=1,n
80 write(*,2)i,(marks(i,j),j=1,5),rtot(i),rper(i),rmin(i),rmax(i)
write(*,*)
write(*,3)'avg',(cavg(j),j=1,5)
write(*,3)'min',(cmin(j),j=1,5)
write(*,3)'max',(cmax(j),j=1,5)
1 format(////////////////////,2x,a3,9(2x,a6))
2 format(2x,i3,9(2x,f6.2))
3 format(2x,a3,5(2x,f6.2))
end
26
Wednesday, September 24, 2008 Fortran for bce-I/II
Q-10.1 Wrie a programme to find the weighted mean for n number of values stored in a
array an weight stored in another array using a function subprogram.
function sum(x,n)
real x(100),sum
sum=0
do 10 i=1,n
10 sum=sum+x(i)
end
* Main Program
write(*,*)'Enter Size'
read(*,*)n
do 10 i=1,n
read(*,*) x(i),w(i)
10 y(i)=x(i)*w(i)
rmean=sum(y,n)/sum(w,n)
write(*,1)'Mean is ',rmean
27
Wednesday, September 24, 2008 Fortran for bce-I/II
1 format (1x,a7,3x,f10.2)
end
Q-10.2 Wrie function subprogramme to pass arry as arguments and hence display their
mean.
function arsum(A,n)
real A(n)
sum=0
do 101 i=1,n
101 sum=sum+A(i)
arsum=sum
end
*main programme
real x(10)
write(*,*)'no. of elements'
read(*,*)m
write(*,*)'enter elements'
read(*,*)(x(i),i=1,m)
xmean=arsum(x,m)/m
write(*,*)xmean
end
Q-10.3 Wrie a subroutine programme to read in main programme the value of radius and
height of a cylinder and compue base area, curve surface area total area, display the result
in main progrmme.
28
Wednesday, September 24, 2008 Fortran for bce-I/II
*subroutine programme
subroutine cycalc(r,h)
real pi,ba,ca,voll,r,h
pi=22.0/7
ba=pi*r*r
ca=2*pi*r*h
ta=2*ba+ca
vol1=ba*h
write(*,*)'base area',ba
write(*,*)'curve area=',ca
write(*,*)'total area=',ta
return
end
* main programme
real r1,h1
read(*,*)r1,h1
call cycalc(r1,h1)
read(*,*)i
29
Wednesday, September 24, 2008 Fortran for bce-I/II
end
F = (A + B) * (C-D')
where A and B are of same order (say m x n) C and D are of same order n x p and p x n
respectiveley (say)
subroutine input(m,n,mm,nn,a)
integer p
real a(mm,nn)
do 10 i=1,m
10 read(*,*)(a(i,j),j=1,n)
end
subroutine matmul(m,n,p,mm,nn,a,b,c)
integer p
real a(mm,nn),b(mm,nn),c(mm,nn)
do 30 i=1,m
30
Wednesday, September 24, 2008 Fortran for bce-I/II
do 30 j=1,p
c(i,j)=0
do 30 k=1,n
c(i,j)=c(i,j)+a(i,k)*b(k,j)
30 continue
end
subroutine add(m,n,mm,nn,a,b,c)
real a(mm,nn),b(mm,nn),c(mm,nn)
do 40 i=1,m
do 40 j=1,n
c(i,j)=a(i,j)+b(i,j)
40 continue
end
subroutine subs(n,p,mm,nn,a,b,c)
integer p
real a(mm,nn),b(mm,nn),c(mm,nn)
do 40 i=1,n
do 40 j=1,p
c(i,j)=a(i,j)-b(i,j)
40 continue
end
subroutine tran(p,n,mm,nn,a,b)
31
Wednesday, September 24, 2008 Fortran for bce-I/II
integer p
real a(mm,nn),b(mm,nn)
do 50 i=1,p
do 50 j=1,n
b(j,i)=a(i,j)
50 continue
end
subroutine output(m,p,mm,nn,c)
integer p
real c(mm,nn)
do 60 i=1,m
60 write(*,*)(c(i,j),j=1,p)
end
c Main Program........................
integer p
real a(10,10),b(10,10),c(10,10),d(10,10),e(10,10),f(10,10),
$ g(10,10), h(10,10)
read(*,*) m,n
call input(m,n,10,10,a)
32
Wednesday, September 24, 2008 Fortran for bce-I/II
call input(m,n,10,10,b)
read(*,*) n1, p
if(n1.ne.n) then
goto 5
endif
call input(n,p,10,10,c)
read(*,*) P2, N2
IF(n2.ne.n.or.p2.ne.p) then
goto 6
endif
call input(p,n,10,10,d)
call add(m,n,10,10,a,b,e)
call tran(p,n,10,10,d,g)
call subs(n,p,10,10,c,g,h)
call matmul(m,n,p,10,10,e,h,f)
33
Wednesday, September 24, 2008 Fortran for bce-I/II
call output(m,p,10,10,f)
end
34