#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);
}
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;}}
The max that someone can have is 50. I think the max anyone has ever had is 19
#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; }
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
Number 197, Umbreon, is found by evolving an Eevee with max happiness during the night.
java is very most important language in computer field. .net is also useful