Question 1: write a program to convert temperature Celsius to Fahrenheit.
Answer:
program temp_conversion
implicit none
real :: celcius,fahrenheit
print*,"value of celcius"
read*,celcius
fahrenheit=1.8*celcius+32.0
print*,"fahrenheit=",fahrenheit
end program
Question 2: Find the perimeter and the area of a rectangle.
Answer:
program
implicit none
integer ::p,q,area,perimeter
print*,"value of p"
read*,p
print*,"value of q"
read*,q
area=p*q
perimeter =2*(p+q)
print*,"Area=",area,"perimeter=",perimeter
end program
Question 3:Find the sides and area of a triangle.
Answer:
program side_area_triangle
implicit none
real ::a,b,c,theta,rad_theta,area
print*,"type the value of side a"
read*,a
print*,"type the value of side b”
read*,b
print*,”type the value of theta”
read*,theta
rad_theta=theta*pi/180
print*,”first side=”,a,”second side=”,b,”included angle=”,rad_theta
c=sqrt(a**2+b**2-2.0*a*b*cos( rad_theta))
area=a*b*sin(rad_theta)/2.0
print*,"third side=",c,"Area =",area
end program
Question 4: Determine the largest number from three given value.
Answer:
program picking_largest
implicit none
integer::a,b,c
print*,"Type value of a"
read*,a
print*,"Type value of b"
read*,b
print*,"Type value of c"
read*,c
if(a>b)then
if(a>c)then
print*,"largest=",a
else
print*,"largest=",c
end if
else
if(b>c)then
print*,"largest=",b
else
print*,"largest=",c
end if
end if
end program
Question 5: The income tax rates are given by following rules:
(i) No tax is charged on net tax income ≤ 35000
(ii) 20% is charged on income above 35000 but below 60000
(iii) 30% is charged on income above 60000 but below 120000
(iv) 40% is charged on income above 120000
Answer:
program main
implicit none
real income,tax
print*,"type your income"
read*,income
if(income<=35000)then
tax=0
else if (income<=60000)then
tax=anint(income-35000)*0.2
else if (income<=120000)then
tax=5000+anint(income-60000)*0.3
else
tax=23000+anint(income-120000)*0.4
end if
print*,"Tax to be paid=",tax
end program
Question 6:Find the sum of the digits of a number.
Answer:
program summing_digits
implicit none
integer num,digit,sum
print*,"type of number"
read*,num
sum=0
do while(num/=0)
digit=mod(num,10)
sum=sum+digit
num=num/10
end do
print*,"sum of digit =",sum
end program
Question 7: Write a program in fortran to find the leap year
Answer:
program leap_year
implicit none
integer year
print*,"Enter the Year"
read*,year
if(mod(year,400)==0)then
print*,"this is leap year"
else if(mod(year,100)==0)then
print*,"this is not leap year"
else if(mod(year,4)==0)then
print*,"this is leap year"
else
print*,"this is not leap year"
end if
end program
Question 8: write a fortran programming for determine the amount of interest and total
amount in a bank.
Answer:
program bank
implicit none
integer amount,deposit,rate,time,interest
print*,"Enter the deposit amount"
read*,deposit
print*,"Enter the time"
read*,time
print*,"Enter the rate interest"
read*,rate
interest=(deposit*rate*time)/100
amount=deposit+interest
print*,"total amount=",amount
end program
Question 8: Find the roots of the quadratic equation by fortran progamming
Answer:
program main
implicit none
real a,b,c,discriminant,root1,root2
print*,"Enter the coefficients"
read*,a,b,c
if(a==0.0)then
print*,"The value can't be 0"
else
discriminant=b**2-4.0*a*c
if(discriminant>0.0)then
root1=-b+sqrt(discriminant)/(2.0*a)
root2=-b-sqrt(discriminant)/(2.0*a)
print*,"Roots are real and distinct"
print*,"root1=",root1,"root2=",root2
else if(discriminant==0.0)then
root1=-b/(2.0*a)
print*,"Roots are real and equal"
print*,"root=",root1
else
print*,"roots are complex"
print*,"root1=",-b/(2.0*a),"+",sqrt(-discriminant)/(2.0*a)
print*,"root1=",-b/(2.0*a),"-",sqrt(-discriminant)/(2.0*a)
end if
end if
end
Question 9: Whether a number is prime or not determine by fortran programming
Answer:
program prime_number
implicit none
integer num,i
logical is_prime
print*,"Enter a number"
read*,num
i=1
if(num<=1)then
print*,num,"is not prime"
else
is_prime=.true.
do i=i+1,sqrt(real(num))
if(mod(num,i)==0)then
is_prime=.false.
exit
end if
end do
if(is_prime)then
print*,num,"is prime"
else
print*,num,"is not prime"
end if
end if
end program
Question 10: find the sum of the series: 1+2+3+……….
Answer:
program sum_series
implicit none
integer::i,n,sum
sum=0
print*,"Enter a number"
read*,n
do i=1,n
sum=sum+i
end do
print*,"summation=",sum
end program
Question 11: find the sum of the series: 7+14+21+……………
program summation
implicit none
integer i,n,sum,a
sum=0
a=7
print*,"Enter a number"
read*,n
do i=1,n
sum=sum+a
a=a+7
end do
print*,"summation=",sum
end program
2 n
x x
Question 12: find the sum of the series:1+ x + +…+
2! n!
Answer:
program main
implicit none
integer n,i
real x, term, fact, sum
print*,”Enter yhe value of n”
read*,n
sum=1
term=1
fact=1
do i=1,n
term=term*i
sum=sum+term/fact
end do
end program
1 1 1
Question 13: find the sum of the series:1+ + + …+
2 5 2n+ 1
Answer:
program main
implicit none
integer n,i
real sum
print*,”Enter an odd number”
read*,n
if(mod(n,2)==0)then
print*,”n must be an odd integer”
stop
end if
sum=0
do i=1,n,2
sum=sum+1/real(i)
end do
print*,”the sum is=”,sum
end program