Skip to main content

Posts

Showing posts from July, 2019

Program in fortran to find the value of integration of the function [(1-x^2)^1/2]*cosx by Trapezoidal rule

!       Program in fortran to find the value of integration of the !       function [(1-x^2)^1/2]*cosx by Trapezoidal rule         write(*,*)'Enter the lower and upper limits respectively:'         read(*,*)a,b         Write(*,*)'Enter the number of sub intervals (n):'         read(*,*)n         sum=f(a)+f(b)         h=(b-a)/n         do i=1,n-1         sum=sum+2.0*f(a+i*h)         end do         sum=sum*h/2.0         write(*,11)sum 11    format(2x,'The value of the integration corrected upto six decimal places is',f16.6)  ...

Program to find the mean, median and mode of n numbers

C      Program to find the mean, median and mode of n numbers         dimension a(100)         sum=0.0         write(*,*)'Enter the no. of the data:'         read(*,*)n         write(*,*)'Now, enter the data:'         do i=1,n         read(*,*)a(i)         sum=sum+a(i)         end do         rmean=sum/n         do i=1,n-1         do j=i+1,n         if(a(i).gt.a(j))then         temp=a(i)         a(i)=a(j)        ...

Program to find the sum of the e^x series with an error < 10^5

C      Program to find the sum of the e^x series with an error < 10^5         write(*,*)'Enter the value of x:'         read(*,*)x         sum=0.0         term=1.0         i=1 10    sum=sum+term         term=x**i/fact(i)         k=k+1         i=i+1         if(abs(term).gt..00001)goto 10         write(*,20)sum,x  20   format(2x,'The sum of the series is:'f16.4,' for x=',f16.4)         end C      Program sub function         function fact(i)         fact=1.0 ...

Program to find the sum of the cube of the digits of a three digit number

C      Program to find the sum of the cube of the digits of a C      three digit number         write(*,*)'Enter a three digit number:'         read(*,*)n         m=n         r=mod(n,10)         n=n/10         i=mod(n,10)         n=n/10         write(*,*)'The digits of the number',m,'is',n,',',i,',',r         k=n**3+i**3+r**3         write(*,*)'The sum of the cube of these digits is',k         end

Program to find the square root of a real number

C      Program to find the square root of a real number         real::a         write(*,*)'Input the number:'         read(*,*)a         if (a.ge.0.0)then         c=sqrt(a)         write(*,10)c 10    Format(2x,'The square root of the number is',f16.4)         else         d=sqrt(-a)         write(*,20)d  20   Format(2x,'The square root of the number is i',f16.4)         end if         end

Program to test whether a year is leap year or not

C      Program to test whether a year is leap year or not         write(*,*)'Enter the year:'         read(*,*)l         if (mod(l,4).ne.0)goto 10         if (mod(l,100).ne.0)goto 20         if (mod(l,400).ne.0)goto 10 20    write(*,*)'The year is a leap year.'         stop 10    write(*,*)'The year is  not a leap year.'         stop         end

Program to find large number between two numbers

C      Program to find large number between two numbers         write(*,*)'Input the two numbers:'         read(*,*)a,b         large=a         if(large.lt.b)then         large=b         write(*,*)'The large number is',large         else         write(*,*)'The large number is',large         end if         end

Program to find the trace of a matrix

C     Program to find the trace of a matrix        integer::n        real::trace=0.0,a(10,10)        print*,'Enter the number of row and coloumns of square matrix:'        read(*,*)n        write(*,*)'Enter the matrix elements:'        do i=1,n        read(*,*)(a(i,j),j=1,n)        end do        write(*,*)'The matrix is :'        do i=1,n        write(*,*)(a(i,j),j=1,n)        end do        do i=1,n        trace=trace+a(i,i)        end do        write(*,*)'The trace of the entered matrix is',tra...

Program to find the value of integration using Simpson's 1/3 rule

!       Program to find the value of integration using Simpson's 1/3 rule        write(*,*)'Enter the values of lower and upper limit of integration  respectively:'         read(*,*)a,b         k=4         write(*,*)'Enter the number of even sub intervals:'         read(*,*)n         sum=f(a)+f(b)         h=(b-a)/n         do i=1,n-1         sum=sum+k*f(a+i*h)         k=6-k         end do         sum=sum*h/3.0         write(*,10)sum 10    format(2x,'The value of integration is',f16.3)  ...

Program to find the reverse of a given number

C      Program to find the reverse of a given number         write(*,*)'Enter an integer:'         read(*,*)n         m=n         rev=0         if (n.eq.0)then         write(*,*)'The reverse number is:',n         else         dowhile (n.ne.0)         r=mod(n,10)         rev=rev*10+r         n=n/10         end do         write(*,*)'The reverse of the given number is',rev         end if         end          ...

Program to find the root of the quadratic equation

C      Program to find the root of the quadratic equation         write(*,*)'Enter the values of a,b,c'         read(*,*)a,b,c         d=b*b-(4.0*a*c)         if (d.eq.0)then         write(*,*)'The root is real and equal.'         x1=-b/(2.0*a)         write(*,*)'The equal root is :',x1         else if (d.gt.0)then         write(*,*)'The roots are real and distinct.'         x1=(-b+sqrt(d))/(2.0*a)         x2=(-b-sqrt(d))/(2.0*a)         write(*,*)'The roots are :',x1,' and ',x2         else    ...

Program to find prime numbers between two integers

C      Program to find prime numbers between two integers         write(*,*)'Enter the limits:'         read(*,*)m,n         if (m.gt.n)then         temp=m         m=n         n=temp         end if         i=m         print*,'The prime numbers between are given below:'  20   do j=2,i/2         r=mod(i,j)         if(r.eq.0)goto 10         end do         write(*,*)i  10   if(i.lt.n)then         i=i+1         goto 20 ...

Program to find prime or composite number

C      Program to find prime or composite number         write(*,*)'Input the integer:'         read(*,*)n         kount=0         if (n.gt.1)then         do i=1,(n/2)         l=mod(n,i)         if (l.eq.0) then         kount=kount+1         end if         end do         if (kount.eq.1)then         write(*,*)'The number is prime.'         else         write(*,*)'The number is composite.'         end if         e...

Prime factor of a given integer

C      Prime factor of a given integer         write(*,*)'Input an integer:'         read(*,*)n         write(*,*)'The prime factor(s) of the integer is given below:'         do i=2,n         r=mod(n,i)         if (r.ne. 0.0)goto 10         do j=2,i/2         if(mod(i,j).eq.0)goto 10         end do         write(*,*)i  10   end do         end         

Program to find whether a number is perfect square or not

C      Program to find whether a number is perfect square or not         write(*,*)'Enter the number:'         read(*,*)x         y=sqrt(x)         if (x.eq.y**2)then         write(*,*)'The number is a perfect square.'         else         write(*,*)'The number is not a perfect square.'         endif         end

Program to find perfect numbers between 1 to 10000

C      Program to find perfect numbers between 1 to 10000         write(*,*)'The perfect numbers between 1 and 10000 are:'         do i=1,10000         sum=0         do j=1,(i/2)         r=mod(i,j)         if (r.eq.0)then         sum=sum+j         end if         end do         if (sum.eq.i)then         write(*,*)i         end if         end do         end        

Program to check whether a number is perfect or not

C      Program to check whether a number is perfect or not         write(*,*)'Input the number:'         read(*,*)n         sum=0         write(*,*)'The factors excluding that number are:'         do i=1,(n/2)         r=mod(n,i)         if (r.eq.0)then         write(*,*)i         sum=sum+i         end if         end do         if (sum .eq. n)then         write(*,*)'The number is perfect.'         else         write(*,*)'The number is not perfect....

Program to find the 1st nth terms and their sum of fibonacci series

C      Program to find the 1st nth terms and their sum of fibonacci series         write(*,*)'Enter the number of terms you want to see'         read(*,*)n         i=1         j=1         sum=0         write(*,*)'The 1st',n,'terms are:'         do l=1,n         write(*,*)i         sum=sum+i         k=i+j         i=j         j=k         end do         write(*,*)'The sum of the series is:',sum         end

Program to find the fibonacci series whose last term does not exceed the desired limit

!       Program to find the fibonacci series whose last term does not exceed the desired limit         write(*,*)'Enter the desired limit:'         read(*,*)n         print*,'The fibonacci series whose last term is not greater than',n,' is:'         i=1         j=1         do while (i.lt.n)         write(*,*)i         k=i+j         i=j         j=k         end do         end        

Program to find fibonacci series upto n terms

C     Program to find fibonacci series upto n terms        write(*,*)'Enter the terms you want see:'        read(*,*)n        i=1        j=1        write(*,*)'The series is:'        do l=1,n        write(*,*)i        k=i+j        i=j        j=k        end do        end       

Program to find the digits of a given number and their sum

C      Program to find the digits of a given number and their sum         write(*,*)'Enter the integer:'         read(*,*)n         m=n         sum=0         if (n.eq.0)then         write(*,*)'The number is',n         write(*,*)'The sum is',sum         else         write(*,*)'The digits are given below :'         do while (n.ne.0)         r=abs(mod(n,10))         write(*,*)r         sum=sum+r         n=n/10         end do     ...

Program to arrange the number in decending order

C      Program to arrange the number in decending order         dimension a(100)         write(*,*)'Enter the no. of terms:'         read(*,*)n         write(*,*)'Enter the numbers:'         do i=1,n         read(*,*)a(i)         end do         do i=1,n-1         do j=i+1,n         if (a(i).lt.a(j))then         temp=a(i)         a(i)=a(j)         a(j)=temp         end if         end do         end do  ...

Program in fortran to arrange the order in ascending order

C      Program in fortran to arrange the order in ascending order         dimension a(100)         write(*,*)'Enter the number of data:'         read(*,*)n         write(*,*)'Now, input the data:'         do i=1,n         read(*,*)a(i)         end do         do i=1,n-1         do j=i+1,n         if (a(i).gt.a(j))then         temp=a(i)         a(i)=a(j)         a(j)=temp         end if         end do         end ...

Program to find the sum of AP series

!       Program to find the sum of AP series         real::a,d         integer::n         write(*,*)'Enter the number of terms, 1st term and common difference:'         read(*,*)n,a,d         sum=0         do i=0,n-1         term=a+i*d         sum=sum+term         end do         write(*,*)'The sum of the AP series is',sum         end        

Program to find the value of cosine of a given angle

C      Program to find the value of cosine of a given angle         Write(*,*)'Enter the value of the angle in degree:'         read(*,*)x         y=(acos(-1.0)*x)/180.0         sum=0.0         term=1.0         i=0         s=1.0         dowhile(abs(term).ge.1.0E-6)         term=(y**i/fact(i))*s         sum=sum+term         i=i+2         s=-s         end do         write(*,10)sum 10    format(2x,'The value of cosx is',f16.4)       ...

Program to find sine of a given angle

C      Program to find sine of a given angle         write(*,*)'Enter the angle in degree:'         read(*,*)y         sum=0.0         term=1.0         i=1         s=1.0         x=(acos(-1.0)*y)/180.0         dowhile (abs(term).ge.1.0E-6)         term=(x**i/fact(i))*s         sum=sum+term         i=i+2         s=-s         end do         write(*,10)y,sum  10   format(2x,'The value of sin',f16.2,' is',f16.4)         end   ...

Program to find the sum of GP series

C      Program to find the sum of GP series         print*,'Enter the number of terms, 1st term and common ratio:'         read(*,*)n,a,r         sum=0         do i=0,n-1         sum=sum+a*r**i         end do         write(*,*)'The sum of the GP series is',sum         end        

Program to find the factors of an number

C      Program to find the factors of an number         write(*,*)'Enter the integer:'         read(*,*)n         write(*,*)'The factors are of the given no. are:'         do i=1,n         r=mod(n,i)         if (r.eq.0)then         write(*,*)i         end if         end do         end        

Program to find the factorial of a non-negative integer

C      Program to find the factorial of a non-negative integer         write(*,*)'Enter a non-negative integer:'         read(*,*)n         write(*,*)'The factorial of',n,'is',fact(n)         end          C      Program sub function         function fact(n)         fact=1         do i=1,n         fact=fact*i         end do         return         end

Program to test whether a number is positive or not

C      Program to test whether a number is positive or not         write(*,*)'Input the number:'         read(*,*)n         if (n.eq.0)then         write(*,*)'The entered number is zero.'         else if (n.gt.0)then         write(*,*)'The entered number is positive.'         else         write(*,*)'The entered number is negative.'         end if         end

Program to find the volume and surface area of a cuboid

C      Program to find the volume and surface area  of a cuboid         write(*,*)'Enter the length:'         read(*,*)r         write(*,*)'Enter the width:'         read(*,*)w         write(*,*)'Enter the height:'         read(*,*)h         a=2.0*(w*r+r*h+h*w)         v=w*r*h         d=sqrt(w**2+r**2+h**2)         write(*,10)a         write(*,20)v         write(*,30)d  10   format(2x,'The area of the cuboid is',f16.4)  20   format(2x,'The volume of the cuboid is',f16.4)  30   format(2x,'The space di...

Program to find the volume and total surface area of a cone

C      Program to find the volume and total surface area of a cone         write(*,*)'Enter the radius:'         read(*,*)r         write(*,*)'Enter the height:'         read(*,*)h         a=acos(-1.0)*r*(r+sqrt(r*r+h*h))         v=((acos(-1.0)*r*r*h)/3.0)         write(*,10)a         write(*,20)v 10    format(2x,'The total surface area of the cone is',f16.4) 20    format(2x,'The volume of the cone is',f16.4)         end

To check whether a number is devisible by 7 or not

C      To check whether a number is devisible by 7 or not         write(*,*)'Input the integer number:'         read(*,*)n         if (mod(n,7).eq. 0)then         write(*,*)'The number is divisible to 7.'         else         write(*,*)'The number is not divisible to 7.'         end if         end

Program to find sum of the series 2 + 4 + 2 + 4 + 2 + ... upto a no. of terms

C       Program to find sum of the series 2 + 4 + 2 + 4 + 2 + ... upto a no. of terms         write(*,*)'Input the no. of terms:'         read(*,*)n         sum=0         p=2         do i=1,n         sum=sum+p         p=6-p         end do         write(*,*)'The sum of the given series is:',sum         end        

Program to find the sum of the series 1 + 1/3 + 1/5 + ... upto n terms

C      Program to find the sum of the series 1 + 1/3 + 1/5 + ... upto n terms         write(*,*)'Enter the no. of terms:'         read(*,*)n         sum=0.0         i=1         do j=1,n         sum=sum+1.0/i         i=i+2         end do         write(*,10)sum  10   format(2x,'The sum of the series is',f16.4)         end        

Program to find the sum of a series upto a no. of terms

c                                                                   (4n-3)(4n-2) c      Program to find the sum of the series ------------------ upto a no. of terms c                                                                      4n(4n-1)         write(*,*)'Enter the no. of terms:'         read(*,*)n         sum=0       ...

Program to find sum of n^2 series

C      Program to find sum of n^2 series         write(*,*)'Enter the no. of terms:'         read(*,*)n         sum=0.0         do i=1,n         term=i**2         sum=sum+term         end do         write(*,*)'The sum of the given series is:',sum         end        

Program to find the sum and average using array

C      Program to find the sum and average using array         dimension a(100)         sum=0.0         write(*,*)'Enter the no. of data you want to enter:'         read(*,*) n         write(*,*)'Now, enter the data:'         do i=1,n         read(*,*)a(i)         sum=sum+a(i)         end do         ave=sum/real(n)         write(*,*)'The sum of the given numbers is',sum         write(*,*)'The average of the given numbers is',ave         end        

Program to find the scalar product of two vectors

C      Program to find the scalar product of two vectors         dimension x(20),y(20)         product=0.0         write(*,*)'Enter the total no. components in each vector:'         read(*,*)n         write(*,*)'Enter the components of the first vector:'         do i=1,n         read(*,*)x(i)         end do         write(*,*)'Enter the components of the second vector:'         do i=1,n         read(*,*)y(i)         end do         do i=1,n         product=product+x(i)*y(i)  ...

Program to find the sum of first n numbers

C      Program to find the sum of first n numbers         write(*,*)'Enter the desired limit:'         read(*,*)n         write(*,*)'The numbers are:'         sum=0.0         do i=1,n         write(*,*)i         sum=sum+i         end do         write(*,*)'The sum of the numbers is :',sum         end        

Program to find the sum of all odd numbers between 1 and 20

C      Program to find the sum of all odd numbers between 1 and 20         write(*,*)'The odd numbers between 1 to 20 are :'         sum=0         do i=1,20,2         write(*,*)i         sum=sum+i         end do         write(*,*)'The sum of these numbers is:',sum         end        

Program to find the value of n-c-r

C      Program to find the value of n-c-r         integer n,r,i         real ncr         write(*,*)'Enter the Positive integers n,r:'         read(*,*)n,r         ncr=fact(n)/(fact(r)*fact(n-r))         write(*,*)'The value of ncr is',ncr         end          C      Program sub function         function fact(n)         fact=1         do i=1,n         fact=fact*i         end do         return         end

Program to find the maximum and minimum among n numbers

C      Program to find the maximum and minimum among n numbers         write(*,*)'Enter the number of variables:'         read(*,*)n         write(*,*)'Enter any one variable:'         read(*,*)x         max=x         min=x         write(*,*)'Enter the other variables:'         do i=2,n         read(*,*)y         if (max.lt.y)max=y         if (min.gt.y)min=y         end do         write(*,*)'The max number is',max         write(*,*)'The min number is',min     ...

Program to find upto n-th odd integers and their sum

C      Program to find upto n-th odd integers and their sum         write(*,*)'Enter the limit:'         read(*,*)n         write(*,*)'The odd integers between 0 and',n,' are:'         sum=0.0         do i=1,n,2         write(*,*)i         sum=sum+i         end do         write(*,*)'The sum of these odd integers are :',sum         end                 

Program to find the sum upto n-th even integers

C       Program to find the sum upto n-th even integers         write(*,*)'Enter the limit:'         read(*,*)n         write(*,*)'The even integers between 0 and',n,' are :'         sum=0         do i=2,n,2         write(*,*)i         sum=sum+i         end do         write(*,*) 'The sum of these even numbers are',sum         end