#include<stdio.h>
main()
{
int a[50],max,min,n;
printf("enter the noof digits\n");
scanf("%d",&n);
printf("\nenter the numbers");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
max=a[0];
min=a[0];
for(i=1;i<n;i++)
{
if(max<a[i])
max=a[i];
if(min>a[i])
min=a[i];
}
printf("\n max is %d \n min is %d",max ,min);
}
#include<stdio.h>
int main()
{
int a[20],min,max;
int n;
printf("\nEnter the num of elements: ");
scanf("%d",&n);
printf("Enter the elements\n");
for(int i=0;i<n;i++)
{
scanf("%d",&a[i]);
if(i==0)
{
min=max=a[i];
}
if(a[i]<min)
min=a[i];
else if(a[i]>max)
max=a[i];
}
printf("The largest element is %d. The smallest element is %d.", max, min);
}
Here is a simple way: Iterate through the list, keeping track of the largest and smallest values seen so far. If the current value is less than the smallest, replace the smallest with this value. Replace the largest is the current value is greater than it. When you have finished the loop, you have the minimum and maximum values. Initialize the largest and smallest value variables with MAX_INT and MIN_INT from LIMITS.H to ensure that the first value seen replaces it. Or, set an initialized flag to false during initialization, then in the main loop, if it is false then copy the list value into the smallest and largest values and set it to true.
this is a logic to find the max or min number
it is simple and easy.
int min ,max,a[5];
for(i=1;i<5;i++)//basic for loop for iteration purpose
{
scanf("%d",a[i]);//reading array numbers
if (i==1)
{min=a[i];max=a[i];
}
elseif(a[i]<min)min=a[i];//checking for small no
elseif(a[i]>max)max=a[i];//checking for max number
}
then print the max and min values of the program
i have given you the basic idea at the time of entering the values from the keyboard itself it saves the execution time as well as the memory for using extra for loops
#include<stdio.h>
main()
{
int a[50],max,min,n,i;
printf("enter the noof digits\n");
scanf("%d",&n);
printf("\nenter the numbers");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
max=a[0];
min=a[0];
for(i=1;i<n;i++)
{
if(max<a[i])
max=a[i];
if(min>a[i])
min=a[i];
}
printf("\n max is %d \n min is %d",max ,min);
}
It is easier to make two recursion functions, one to calculate the maximum and one for the minimum.we will assume that we will calculate the maximum,minimum of an array of size 100
maximam function :
#include
int max(int a[],int size,int num)
{
if (size 0) return num ;
if (num > a[size])
{
num = a[size] ;
return min(a,size - 1,num) ;
}
else return min(a,size - 1,num) ;
}
a main function to test it out :
int main()
{
int i;int a[100];int b,d;
for (i = 0;i<100;i++)
a[i] = i;
b = max(a,99,a[0]) ;
d= min(a,99,a[0]) ;
printf("\n%d\n%d\n",b ,d);
return (0);
}
#include<stdio.h>
main()
{
int a[50],max,min,n;
printf("enter the noof digits\n");
scanf("%d",&n);
printf("\nenter the numbers");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
max=a[0];
min=a[0];
for(i=1;i<n;i++)
{
if(max<a[i])
max=a[i];
if(min>a[i])
min=a[i];
}
printf("\n max is %d \n min is %d",max ,min);
}
#include<iosys.h>
// Data structure to store min and max valuestypedef struct range {
double min;
double max;
} range_t;
// Returns the min and max values in an array of values of length count
range_t get_range {double* values, unsigned count} {
if (!values !count) /* invoke invalid argument(s) handler */
range_t r = {values[0], values[0]};
for (unsigned k=1; k<size; ++k) {
if (set[k]<r.min) r.min=set[k];
if (set[k]>r.max) r.max=set[k];
}
return r;
}
int main () {
double d[6] = {1.0, 3.14, -2.1, 4.2, -6.0, 2.1};
range_t r = get_range (d, 6);
printf ("Smallest value is: %f\n", r.min); // -6.0
printf ("Largest value is: %f\n", r.max); // 4.2
return 0;
}
Locate and store the largest (max) and smallest (min) values. Then traverse the array looking for a value that is larger than min. If that value is also smaller than max, replace min with that value. After traversing the array, min holds the second largest value. This algorithm requires at least two traversals; both the min and max can be established with a single traversal, then one more traversal to locate the second largest.
The following function will return the range [min:max] of an array of type double:
struct range {double min, double max};
range get_range (double array[], size_t length) {
range r = {array[0], array[0]};
double max = array[0];
for (size_t i=1; i<length; ++i) {
if (r.min>array[i]) r.min=array[i]; if (r.max<array[i]) r.max=array[i];
}
return r;
}
The following function will return the second largest of an array of type double:
double second_largest (double array[], size_t length) {
range r = get_range (array, length);
for (size_t i=1; i<length; ++i) {
if (array[i]>r.min && array[i]<r.max) r.min=array[i]; }
return r.min;
}
int sum (int min, int max) {return (max-min+1)*(max+min)/2;}
In Java, assuming you already created an array of int's, called myArray:int max = myArray[0];int sum = 0;for (int i = 0; i < myArray.length; i++){sum += myArray[i];if (myArray[i] > max)sum = myArray[i]}
import java.util.Scanner; public class Numbers { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int max = -100; int min = 100; int sum = 0; System.out.println("Enter ten integers"); for(int i = 0; i < 10; i++) { int input = scan.nextInt(); if(input > max)//test if the number entered is larger than any previous number max = input; if(input < min)//test if the number entered is smaller than any previous number min = input; sum += input;//add the input to the sum } System.out.println("The maximum number entered is: " + max + "\nThe minimum number entered is: " + min + "\nThe average of the numbers is: " + (sum / 10));//prints out the results } }
The least possible is no iterations: for (x=0; x<max; ++x) { // ... } In the above example, if max is less than or equal to zero then the body of the loop will not execute.
Fist of all, let's assume that by "list" you mean "array." Otherwise we would need your list implementation in order to be able to iterate through the elements. int[] nums; // assume these are the numbers you want to search through int nums_length; // also assume that we know how many numbers are in nums int min; // smallest number in nums int max; // largest number in nums // special case for an empty list of numbers: set min = max = 0 if(nums_length == 0) { min = 0; max = 0; }else { // start min and max off as equal to the first number min = nums[0]; max = nums[0]; // iterate through nums int i; for(i = 1; i < nums_length; ++i) { // update max, if necessary if( nums[i] > max ) { max = nums[i]; } // update min, if necessary if(nums[i] < min) { min = nums[i]; } } } // min and max are now properly set (or both equal to 0 if nums is empty)
int max = a>b?a:b; // set max to the larger of a and b
class maximum{public static void main(string...args){System.out.println(max(new int[]{5,3,6,2,4,61}));}static int max(int[]a){int max=0;for(int i=0;imax)max=a[i];}return max;}}
Max = 0For K = 1 to NIf Number(K) > Max then Max = Number(K)Next KPrint Max
#include <iostream> using std::cout; using std::cin; using std::endl; int main() { int max; int num; for (int counter = 0; counter<15; counter++) { cout <<"Enter a number: "; cin >> max; cout << "Enter another number: "; cin >> num; if (num > max) num = max; cout << "The largest number is " <<max; } return 0; }
The max that someone can have is 50. I think the max anyone has ever had is 19
int sum (int min, int max) {return (max-min+1)*(max+min)/2;}
Max is pronounced "maka" or "masa"
In Java, assuming you already created an array of int's, called myArray:int max = myArray[0];int sum = 0;for (int i = 0; i < myArray.length; i++){sum += myArray[i];if (myArray[i] > max)sum = myArray[i]}
int matrix[][]; // the matrix to find the max in int max = matrix[0][0]; int r,c; for(r = 0; r < 3; ++r) { for(c = 0; c < 3; ++c) { if(matrix[r][c] > max) { max = matrix[r][c]; } } } // max is now the maximum number in matrix
MIN is used to find the lowest number in a range. You would use MAX or LARGE to find the highest number in a range.
Max H. Miller has written: 'The logic of language development in early childhood' -- subject(s): Language acquisition, Language and logic, Semantics
java is very most important language in computer field. .net is also useful