You are working on max function
 
search
 


Contents:


swap function:
Swapping two values to change their addresses.
a

max function:

The largest number among two.
a

absolute value function:

The positive value of a number.
a

sorting function:

How to sort an array.
a

bisection function:

Bissection method used to solve equations by computing, example of cable strung ..
a

Newton-Raphson function:

To solve equations numerically, example of free fall motion ..
a

Secant function:

To solve equations numerically, example of free fall motion ..
a

isPrime function:

This function tests whether an integer is prime..
a

abundant function:

This function tests whether an integer is abundant..
a

factorial function:

Factorial of an integer..
a

quadratic function:

solving a quadratic equation ..
a

even_odd function:

To know if an integer is even or odd ..
a

mean value function:

To calculate the arithmetic mean of some values..
a

reverse function:

To reverse an integer and to know whether a string is palindrome..
a

least squares function :

To calculate the slope and the y_intercept of a linear equation ..
a

Monte Carlo method:

To calculate integrales or probabilities using Monte Carlo technique ..
a

2 and 3 equations systems solving :

To solve the 2 and 3 equations systems with 2 and 3 variables ..
a

Interpolation and Extrapolation :

To solve for lacking values in graphs or tables ..
a

Integer divisors :

Gives the divisors fo an integer and tests whether it is prime ..
a

Amicable pair :

Gives, if it exists, the amicable number of a given integer ..
a

Perfect numbers :

Tests whether a positive integer is perfect, and more ..
a

Periodic table of elements:

Periodic table of elements in C language, and more ..
a

Playing TicTacToe

Using some Fortran90 language funtionalities, and more ..
a


a
home

   max value
max function



	1. Definition


	This folowinig function gives the largest number among the 
	two given numbers. Among two floats x and y; it outputs x if it is 
	larger than y, otherwise, it will put y.


	2. Example in C language:

	/*
	Here is  the fnction to output the maximum  number among two v
	any numbers .
	*/

	#include <stdio.h>

	int main()
	{
	float value1, value2;

	//Declaring the defined function maximum:
	float maximum(float value1, float value2) ;

	printf("Enter two floats ->  n");
	scanf ("%f""%f", &value1, &value2);

	/*Displaying the two entered values*/

	printf("The read values are: %6.2f and %6.2fn", value1, value2);

	/* Displaying the maximum  */

	printf("The max number is: %6.2fn", maximum(value1, value2));

	return 0;
	}


	/*Defininig the function maximum*/

	float maximum ( float x1, float x2 )
	{
	if ( x1 < x2 )
	return      x2 ;
	else
	return       x1 ;
	}

3. Other example in Fortran90 language

!This program fetches integers from a file "question.txt", call 
!a subroutine max_and_min(array, min, max) and outputs the min and the max 
!(resuls). In the subroutine, an array of dimension 6 A(6) is declared, a 
!loop "do" crosses the array making tests to compare an element of the array 
!to its predecessor. The maximum and minimum are then pointed at the end. 



!1. main program:
!----------------
!
PROGRAM max_min_array
IMPLICIT NONE
integer:: A(6), i, maximum, minimum
OPEN(unit=15, File="question.txt")
Read(15,*) (A(i),i=1,6)
call max_and_min(A,maximum,minimum)
write(*,*) "the maximum is", maximum
write(*,*) "the minimum is", minimum
close(15)
end program midterm
!
!
!2. Subroutine:
!---------------
subroutine max_and_min(A,maximum,minimum)
implicit none
integer:: A(6), i, maximum,minimum
maximum=A(1)
minimum=A(1)
DO i=2,6
	if (A(i)>maximum) THEN
		maximum = A(i)
	end if
	if (A(i)<minimum) THEN
		minimum = A(i)
	end if
end do
end subroutine max_min_array

!------------------END----



!3. example:
!------------
!The file "question.txt" contains:
1 
34
5
26
3
78
9
10

The program compiled with SciTE gives:
>g77 -x f77 -ffree-form -W -Wall "max_min_array.f90" -o "max_min_array.exe"
>Exit code: 0
Executed gives:

C:Fortran90>max_min_array
 the maximum is 78
 the minimum is 1

C:Fortran90>



	


Custom Search


© 2007. The scientificsentence . All rights reserved.