Sei sulla pagina 1di 26

SARAT

FORTRAN @ CIVIL I/II

1. Compute the value of log (1 + x) from Log (1 + x) = 1 x + x2/2 x3/3 + x4/4 write(*,*)'Enter value of x for log(1+x)' read(*,*)x term=-x sum=1-x do 1 i=2,4 term=-term*x*(i-1)/i sum=sum+term 1 continue write(*,2)sum 2 format(1x,'log(1+x)=',f10.2) stop end 2. Change the Fahrenheit temperature to centigrade starting from 0 to 100 in interval of 5 degree. C = 5/9 * (F 32). Use IF statement. c Fahrenheit to centigrade f=0 2 c=(5/9.)*(f-32) write(*,1)f,c 1 format(1x,f7.2,'F ','=',f7.2,'C') f=f+5 if(f.le.100)goto 2 stop end

3. Find the sum of series 53 + 103 + 153 + 203 + 253 + 303 . c sum of series n=0 sum=0 2 n=n+5 if(n.le.30)then term=n**3 sum=sum+term goto2 else goto1 endif 1 write(*,*)'The sum of series 5**3+10**3+15**3......+30**3 is' write(*,*)sum stop end
Page 1 Created on September 05,2006 00:00 am 8/6/2013

120

SARAT

FORTRAN @ CIVIL I/II

4. Compute stress (S) from slenderness ratio (R) from S = 18000 0.485R2 If R 110 S= 18000 If R > 110 2 1 + R /18000 c Slenderness Ratio(R) write(*,*)'Enter value of R for slenderness ratio' read(*,*)r if(r.gt.110)then s=18000/(1+(r*r)/18000) else s=18000-0.485*r*r endif write(*,1)s 1 format(1x,'The value of S is',f11.2) stop end

5. Compute the deflection of beam for Y = 5x 150x3 If 0 x <10 Y = 10x3 + 5x2 + 6x + 2 If 10 x <100 c Deflection of beam write(*,*)'Enter value of x' read(*,*)x if(x.ge.100)then write(*,*)'The function is not valid for this value' else if(x.lt.0)then write(*,*)'The function is not valid for this value' else if(x.lt.10)then y=5*x+150*x**3 else y=10*x**3+5*x**2+6*x+2 endif write(*,1)y format(1x,'Y =',f10.2) endif endif stop end

120

Page 2 Created on September 05,2006 00:00 am

8/6/2013

SARAT

FORTRAN @ CIVIL I/II

6. Write a program to find maximum value from three random values. c Maximum value write(*,*)'Enter 1th number' read(*,*)n max=n do 1 i=2,3 write(*,2)i format(1x,'Enter ',i2,'th number') read(*,*)n if(n-max.gt.0)then max=n else endif continue write(*,*)'The maximum value entered is' write(*,*)max stop end

7. Write a program to find minimum value from three random values. c Minimum value write(*,*)'Enter 1th number' read(*,*)n min=n do 1 i=2,3 write(*,2)i format(1x,'Enter ',i2,'th number') read(*,*)n if(min-n.gt.0)then min=n else endif continue write(*,*)'The minimum value entered is' write(*,*)min stop end

120

Page 3 Created on September 05,2006 00:00 am

8/6/2013

SARAT

FORTRAN @ CIVIL I/II

8. You have 100 numbers of data in Centigrade. Write a program to change these into Fahrenheit scale using DO statement. C = 5/9 * (F 32) c 100 Fahrenheit to centigrade do 1 i=1,100 write(*,2)i format(1x,'Enter ',i4,'th value') read(*,*)c f=9*c/5.+32 write(*,3)c,f format(1x,f7.2,'C ','=',f7.2,'F') continue stop end

3 1

9. Write a program to arrange the random data in ascending order. c Ascending order integer c dimension a(100),b(100) write(*,*)'Enter number of terms' read(*,*)n do 1 i=1,n,1 write(*,2)i 2 format(1x,'Enter ',i3,'th term') read(*,*)a(i) 1 continue do 3 i=1,n-1 do 3 j=i+1,n if(a(i).gt.a(j))then t=a(i) a(i)=a(j) a(j)=t endif 3 continue write(*,*)'The terms in ascending order is :' write(*,4)(a(i),i=1,n) 4 format(1x,100f7.2) stop end

120

Page 4 Created on September 05,2006 00:00 am

8/6/2013

SARAT

FORTRAN @ CIVIL I/II

10. Write a program to arrange the random data in descending order. c Descending order integer c dimension a(100),b(100) write(*,*)'Enter number of terms' read(*,*)n do 1 i=1,n,1 write(*,2)i 2 format(1x,'Enter ',i3,'th term') read(*,*)a(i) 1 continue do 3 i=1,n-1 do 3 j=i+1,n if(a(i).lt.a(j))then t=a(i) a(i)=a(j) a(j)=t endif 3 continue write(*,*)'The terms in descending order is :' write(*,4)(a(i),i=1,n) 4 format(1x,100f7.2) stop end 11. Write a program to read series of data in array and find average value of these data. c Average Array dimension a(100) write(*,*)'Enter number of terms' read(*,*)n write(*,*)'Enter the terms' do 1 i=1,n write(*,3)i 3 format(1x,'Enter ',i3,'th term') read(*,*)a(i) 1 continue sum=0 do 2 i=1,n,1 sum=sum+a(i) 2 continue avg=sum/n write(*,*)'The average value is' write(*,*)avg stop end

120

Page 5 Created on September 05,2006 00:00 am

8/6/2013

SARAT

FORTRAN @ CIVIL I/II

12. Write a program to check the prime number. c Check prime number write(*,*)'Enter the number' read(*,*)n l=1 l=l+1 if(l.gt.n/2)then write(*,*)'The number is prime' else if((n-n/l*l).eq.0)then write(*,*)'The number is not prime' else goto1 endif endif stop end

120

Page 6 Created on September 05,2006 00:00 am

8/6/2013

SARAT

FORTRAN @ CIVIL I/II

13. You have three matrices [A] , [B] , [C]. Write a program to add [A] and [B] with transpose of [C]. c Add+Transpose dimension a(10,10),b(10,10),c(10,10),d(10,10),e(10,10) write(*,*)'For the addition of matrixes' write(*,*)'Enter the order for 1st matrix as r,c' read(*,*)m,n write(*,*)'Enter the order for 2nd matrix as r,c' read(*,*)o,p write(*,*)'Enter the order for 3rd matrix as r,c' read(*,*)k,l if(m.eq.o)then if(o.eq.l)then if(n.eq.p)then if(p.eq.k)goto11 else endif else endif else endif write(*,*)'The matrix addition is not defined' stop 11 write(*,*)'Enter the values of the terms of 1st matrix' do 1 i=1,m,1 write(*,2)i format(1x,'Enter terms in',i2,'th row') read(*,*)(a(i,j),j=1,n) continue write(*,*)'Enter the values of the terms of 2nd matrix' do 3 i=1,m,1 write(*,4)i format(1x,'Enter terms in',i2,'th row') read(*,*)(b(i,j),j=1,n) 2 continue

2 1

120

Page 7 Created on September 05,2006 00:00 am

8/6/2013

SARAT

FORTRAN @ CIVIL I/II

write(*,*)'Enter the values of the terms of 3rd matrix' do 12 i=1,k write(*,20)i 20 format(1x,,'Enter terms in ',i2,'th row') read(*,*)(c(i,j),j=1,l) 12 continue do 13 i=1,l do 14 j=1,k d(i,j)=c(j,i) 14 continue 13 continue do 5 i=1,m,1 do 5 j=1,n,1 e(i,j)=a(i,j)+b(i,j)+d(i,j) continue write(*,*)'The first matrix is follows' do 6 i=1,m write(*,*)(a(i,j),j=1,n) continue write(*,*)'The second matrix is follows' do 7 i=1,m write(*,*)(b(i,j),j=1,n) continue write(*,*)'The third matrix is follows' do 8 i=1,k write(*,*)(c(i,j),j=1,l) continue

write(*,*)'The transpose of third matrix is follows' do 15 i=1,l write(*,*)(d(i,j),j=1,k) 15 continue write(*,*)'The sum matrix is follows' do 10 i=1,m write(*,*)(e(i,j),j=1,n) 10 continue stop end

120

Page 8 Created on September 05,2006 00:00 am

8/6/2013

SARAT

FORTRAN @ CIVIL I/II

14. Write a program to find NCR value using function sub program. c c nCr Functions function f(k) f=1 do 1 i=1,k f=f*i continue return end Main Program write(*,*)'Enter values of n & r for nCr' read(*,*)n,l m=f(n)/(f(l)*f(n-l)) write(*,2)n,l,m format(1x,'C(',i2,',',i2,') = ',i3) stop end

15. Write a program to find NCR value using subroutine. c Sub routine subroutine fact(n,a) j=1 do 1 i=1,n j=j*i a=j return end integer a,b,c,d,e,r write(*,*)'Enter n,r' read(*,*)n,r call fact(n,ab) call fact(r,ac) call fact((n-r),ad) e=ab/(ac*ad) write(*,2)n,r,e format(1x,'C (',i2,',',i2,') = ',i3) stop end

120

Page 9 Created on September 05,2006 00:00 am

8/6/2013

SARAT

FORTRAN @ CIVIL I/II

16. Write a program to solve quadratic equation. c Quadratic write(*,*)'enter values of a,b,c' read(*,*)a,b,c if(b**2-4*a*c)1,2,3 1 write(*,*)'real value of x doesnot exist' stop 2 x=-b/(2*a) write(*,*)'the value of x is' write(*,*)x stop 3 x1=(-b+sqrt(b**2-4*a*c))/(2*a) x2=(-b-sqrt(b**2-4*a*c))/(2*a) write(*,*)'the values of x are' write(*,*)x1,x2 stop end 17. Use Do statement to find sum of 1 + x + x2/4 + x3/9 + x4/16 c sum of series using do loop write (*,*)'Enter the value of x' read(*,*)x sum=1 do 1 i=1,4 sum=sum+x**i/i**2 1 continue write(*,*)'The sum of series is' write(*,*)sum stop end 18. Use IF statement to find sum of 1 + x + x2/4 + x3/9 + x4/16 + ........ c sum of series using if statement write(*,*)'Enter the value of x' read(*,*)x sum=1 i=1 1 sum=sum+x**i/i**2 i=i+1 if(i.gt.4)goto2 goto1 2 write(*,*)'The sum of series is' write(*,*)sum stop end

120

Page 10 Created on September 05,2006 00:00 am

8/6/2013

SARAT

FORTRAN @ CIVIL I/II

19. Find annual return using A P * i(1 + i)n/(1 + i)n - 1 where is interest rate , P is investment amount , n numbers of years. c c Annual Return Sub Programs function f(x,y) f=(1+x)**y return end Main Program write(*,*)'Enter the investment amount' read(*,*)a write(*,*)'Enter the interest rate' read(*,*)b write(*,*)'Enter the number of years' read(*,*)c t=a*b*f(b,c)/(f(b,c)-1) write(*,*)'The total annual return is' write(*,1)t format(1x,f7.2) stop end

20. Write program to find earth pressure by P = wh2/2 * 1-sin/1+sin. Use calculated P to find moment at distance h/3 for 10 sections of retaining wall. c Pressure write(*,*)'Enter the value of w' read(*,*)w write(*,*)'Enter the value of h' read(*,*)h write(*,*)'Enter the angle' read(*,*)a a=a*22/(7*180.) p=(w*h*h/2)*(1-sin(a))/(1+sin(a)) write(*,*)'The pressure is' write(*,*)p b=p*h/3 write(*,*)'The moment is' write(*,*)b stop end

120

Page 11 Created on September 05,2006 00:00 am

8/6/2013

SARAT

FORTRAN @ CIVIL I/II

21. Write a program to find volume of triangular cylinder from two sides and angle between them in cross section and length. C Volume of the cylinder write(*,*)'Enter the length of two adjacent sides' read(*,*)a,b write(*,*)'Enter angle between entered sides' read(*,*)c write(*,*)'Enter the height of the prism' read(*,*)d c=c*22/(7*180) e=0.5*a*b*sin(c) v=e*d write(*,1)e,v format(1x,'The area of the base is',f5.2,/,1x,'The volume of pris *m is',f6.2,/) stop end

22. Write a program to read square matrix and to calculate sum of any row of the matrix. c Sum of any row Dimension a(10,10),b(100) write(*,*)'Enter the order of square matrix' read(*,*)k write(*,*)'Enter the terms of the matrix' do 1 i=1,k,1 write(*,4)i 4 format(1x,'Enter terms of ',i2,'th row') read(*,*)(a(i,j),j=1,k) 1 continue write(*,*)'Enter the row to calculate the sum' read(*,*)i sum=0 do 3 j=1,k,1 sum=sum+a(i,j) 3 continue write(*,*)'The sum of elements of given row is :' write(*,5)sum 5 format(1x,f5.2) stop end

120

Page 12 Created on September 05,2006 00:00 am

8/6/2013

SARAT

FORTRAN @ CIVIL I/II

23. Write a program to read square matrix and to calculate sum of any column of the matrix. c Sum of any column Dimension a(10,10),b(100) write(*,*)'Enter the order of square matrix' read(*,*)k write(*,*)'Enter the terms of the matrix' do 1 i=1,k,1 write(*,4)i 4 format(1x,'Enter terms of ',i2,'th row') read(*,*)(a(i,j),j=1,k) 1 continue write(*,*)'Enter the column to calculate the sum' read(*,*)j sum=0 do 3 i=1,k,1 sum=sum+a(i,j) 3 continue write(*,*)'The sum of elements of given column is :' write(*,5)sum 5 format(1x,f5.2) stop end

120

Page 13 Created on September 05,2006 00:00 am

8/6/2013

SARAT

FORTRAN @ CIVIL I/II

24. Write a program to read square matrix and to calculate sum of each row of the matrix. c Sum of each row Dimension a(10,10),b(100) write(*,*)'Enter the order of square matrix' read(*,*)k write(*,*)'Enter the terms of the matrix' do 1 i=1,k,1 write(*,4)i 4 format(1x,'Enter terms of ',i2,'th row') read(*,*)(a(i,j),j=1,k) 1 continue do 2 i=1,k,1 sum=0 do 3 j=1,k,1 sum=sum+a(i,j) continue write(*,6)i format('The sum of elements of',i2,'th row is :') write(*,5)sum format(1x,f5.2) continue stop end

3 6 5 2

120

Page 14 Created on September 05,2006 00:00 am

8/6/2013

SARAT

FORTRAN @ CIVIL I/II

25. Write a program to read square matrix and to calculate sum of each column of the matrix. c Sum of each column Dimension a(10,10),b(100) write(*,*)'Enter the order of square matrix' read(*,*)k write(*,*)'Enter the terms of the matrix' do 1 i=1,k,1 write(*,4)i 4 format(1x,'Enter terms of ',i2,'th row') read(*,*)(a(i,j),j=1,k) 1 continue do 2 j=1,k,1 sum=0 do 3 i=1,k,1 sum=sum+a(i,j) continue write(*,6)j format('The sum of elements of',i2,'th column is :') write(*,5)sum format(1x,f5.2) continue stop end

3 6 5 2

120

Page 15 Created on September 05,2006 00:00 am

8/6/2013

SARAT

FORTRAN @ CIVIL I/II

26. Write a program to read square matrix and to calculate sum of all elements of the matrix. c Sum of all elements Dimension a(10,10),b(100) write(*,*)'Enter the order of square matrix' read(*,*)k write(*,*)'Enter the terms of the matrix' do 1 i=1,k,1 write(*,4)i 4 format(1x,'Enter terms of ',i2,'th row') read(*,*)(a(i,j),j=1,k) 1 continue sum=0 do 2 j=1,k,1 do 3 i=1,k,1 sum=sum+a(i,j) 3 continue 2 continue write(*,*)'The sum of all elements of matrix is' write(*,5)sum 5 format(1x,f5.2) stop end

120

Page 16 Created on September 05,2006 00:00 am

8/6/2013

SARAT

FORTRAN @ CIVIL I/II

27. Write a program to read square matrix and to calculate sum of all elements except diagonal elements of matrix. c Sum of all elements excluding diagonal elements Dimension a(10,10),b(100) write(*,*)'Enter the order of square matrix' read(*,*)k write(*,*)'Enter the terms of the matrix' do 1 i=1,k,1 write(*,4)i 4 format(1x,'Enter terms of ',i2,'th row') read(*,*)(a(i,j),j=1,k) 1 continue sum=0 do 2 j=1,k,1 do 3 i=1,k,1 if(i.eq.j)goto3 sum=sum+a(i,j) 3 continue 2 continue write(*,*)'The sum of all elements excluding diagonal elements of *matrix is' write(*,5)sum 5 format(1x,f5.2) stop end

120

Page 17 Created on September 05,2006 00:00 am

8/6/2013

SARAT

FORTRAN @ CIVIL I/II

28. Write a program to read square matrix and to calculate sum of any row of the matrix. c Sum of any row Dimension a(10,10),b(100) write(*,*)'Enter the order of square matrix' read(*,*)k write(*,*)'Enter the terms of the matrix' do 1 i=1,k,1 write(*,4)i 4 format(1x,'Enter terms of ',i2,'th row') read(*,*)(a(i,j),j=1,k) 1 continue write(*,*)'Enter the row to calculate the sum' read(*,*)i sum=0 do 3 j=1,k,1 sum=sum+a(i,j) 3 continue write(*,*)'The sum of elements of given row is :' write(*,5)sum 5 format(1x,f5.2) stop end

120

Page 18 Created on September 05,2006 00:00 am

8/6/2013

SARAT

FORTRAN @ CIVIL I/II

29. Write a program to read square matrix and to count the negative elements within the matrix find their sum. c Negative elements Dimension a(10,10),b(100) integer c,d write(*,*)'Enter the order of square matrix' read(*,*)k write(*,*)'Enter the terms of the matrix' do 1 i=1,k,1 write(*,4)i format(1x,'Enter terms of ',i2,'th row') read(*,*)(a(i,j),j=1,k) continue m=0 do 2 i=1,k,1 do 3 j=1,k,1 if(a(i,j).lt.0)then m=m+1 b(m)=a(i,j) else endif continue continue write(*,*)'The number of negative elements is:' write(*,*)m write(*,*)'The negative elements of the matrix are as follows:' write(*,6)(b(i),i=1,m) format(1x,100f6.2) sum=0 do 7 i=1,m sum=sum+b(i) continue write(*,*)'The sum of negative elements is;' write(*,6)sum stop end

4 1

3 2

120

Page 19 Created on September 05,2006 00:00 am

8/6/2013

SARAT

FORTRAN @ CIVIL I/II

30. Write a program to read square matrix and to count non-negative elements within the matrix. c Non-negative elements Dimension a(10,10),b(100) integer c,d write(*,*)'Enter the order of square matrix' read(*,*)k write(*,*)'Enter the terms of the matrix' do 1 i=1,k,1 write(*,4)i format(1x,'Enter terms of ',i2,'th row') read(*,*)(a(i,j),j=1,k) continue m=0 do 2 i=1,k,1 do 3 j=1,k,1 if(a(i,j).gt.0)then m=m+1 else endif continue continue write(*,*)'The number of non-negative elements of the matrix:' write(*,*)m stop end

4 1

3 2

120

Page 20 Created on September 05,2006 00:00 am

8/6/2013

SARAT

FORTRAN @ CIVIL I/II

31. Write a program to read square matrix and to display only non-negative elements with the matrix. c Non-negative Dimension a(10,10),b(100) integer c,d write(*,*)'Enter the order of square matrix' read(*,*)k write(*,*)'Enter the terms of the matrix' do 1 i=1,k,1 write(*,4)i 4 format(1x,'Enter terms of ',i2,'th row') read(*,*)(a(i,j),j=1,k) 1 continue m=0 do 2 i=1,k,1 do 3 j=1,k,1 if(a(i,j).gt.0)then m=m+1 b(m)=a(i,j) else endif 3 continue 2 continue write(*,*)'The non-negative elements of the matrix are as follows: *' write(*,6)(b(i),i=1,m) 6 format(1x,100f6.2) stop end

120

Page 21 Created on September 05,2006 00:00 am

8/6/2013

SARAT

FORTRAN @ CIVIL I/II

32. Write a program to read square matrix and to display only negative elements with in the matrix. c Negative Dimension a(10,10),b(100) integer c,d write(*,*)'Enter the order of square matrix' read(*,*)k write(*,*)'Enter the terms of the matrix' do 1 i=1,k,1 write(*,4)i format(1x,'Enter terms of ',i2,'th row') read(*,*)(a(i,j),j=1,k) continue m=0 do 2 i=1,k,1 do 3 j=1,k,1 if(a(i,j).lt.0)then m=m+1 b(m)=a(i,j) else endif continue continue write(*,*)'The negative elements of the matrix are as follows:' write(*,6)(b(i),i=1,m) format(1x,100f6.2) stop end

4 1

3 2

120

Page 22 Created on September 05,2006 00:00 am

8/6/2013

SARAT

FORTRAN @ CIVIL I/II

33. Write a program to read square matrix and to check whether the matrix is symmetric or not. c Symmetric Matrix Dimension a(10,10) write(*,*)'Enter the order of square matrix' read(*,*)k write(*,*)'Enter the terms of the matrix' do 1 i=1,k,1 write(*,4)i format(1x,'Enter terms of ',i2,'th row') read(*,*)(a(i,j),j=1,k) continue n=0 do 2 i=1,k,1 do 3 j=1,k,1 if(a(i,j).eq.a(j,i))then else n=n+1 endif continue continue if(n.eq.0)then write(*,*)'The given matrix is symmetric' else write(*,*)'The given matrix is not symmetric' endif stop end

4 1

3 2

120

Page 23 Created on September 05,2006 00:00 am

8/6/2013

SARAT

FORTRAN @ CIVIL I/II

34. Write a program to read square matrix and to check whether the matrix is skew symmetric or not. c Skew-Symmetric Matrix Dimension a(10,10) write(*,*)'Enter the order of square matrix' read(*,*)k write(*,*)'Enter the terms of the matrix' do 1 i=1,k,1 write(*,4)i format(1x,'Enter terms of ',i2,'th row') read(*,*)(a(i,j),j=1,k) continue n=0 do 2 i=1,k,1 do 3 j=1,k,1 if(i.eq.j)then if(a(i,j).eq.0)goto3 n=n+1 goto3 endif if(a(i,j).eq.-a(j,i))then else n=n+1 endif continue continue if(n.eq.0)then write(*,*)'The given matrix is skew symmetric.' else write(*,*)'The given matrix is not skew symmetric.' endif stop end

4 1

3 2

120

Page 24 Created on September 05,2006 00:00 am

8/6/2013

SARAT

FORTRAN @ CIVIL I/II

35. Write a program to read square matrix and to replace all the diagonal elements by 1 and display changed matrix. c Replace by one Dimension a(10,10) write(*,*)'Enter the order of square matrix' read(*,*)k write(*,*)'Enter the terms of the matrix' do 1 i=1,k,1 write(*,4)i format(1x,'Enter terms of ',i2,'th row') read(*,*)(a(i,j),j=1,k) continue do 2 i=1,k,1 do 3 j=1,k,1 if(i.eq.j)then a(i,j)=1 else endif continue continue write(*,*)'The resulting matrix is' do 5 i=1,k,1 write(*,*)(a(i,j),j=1,k) continue stop end

4 1

3 2

120

Page 25 Created on September 05,2006 00:00 am

8/6/2013

SARAT

FORTRAN @ CIVIL I/II

36. Write a program to read square matrix and to replace all non-diagonal elements by 0 and display changed matrix. c Replace by zero Dimension a(10,10) write(*,*)'Enter the order of square matrix' read(*,*)k write(*,*)'Enter the terms of the matrix' do 1 i=1,k,1 write(*,4)i format(1x,'Enter terms of ',i2,'th row') read(*,*)(a(i,j),j=1,k) continue do 2 i=1,k,1 do 3 j=1,k,1 if(i.eq.j)then else a(i,j)=0 endif continue continue write(*,*)'The resulting matrix is' do 5 i=1,k,1 write(*,*)(a(i,j),j=1,k) continue stop end

4 1

3 2

120

Page 26 Created on September 05,2006 00:00 am

8/6/2013

Potrebbero piacerti anche