answersLogoWhite

0


Best Answer

#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);

}

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

13y ago

#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);

}

This answer is:
User Avatar

User Avatar

Wiki User

15y ago

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 answer is:
User Avatar

User Avatar

Wiki User

13y ago

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

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

#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);

}

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

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);

}

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

#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);

}

This answer is:
User Avatar

User Avatar

Wiki User

7y ago

#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;

}

This answer is:
User Avatar

User Avatar

Wiki User

6y ago

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;

}

This answer is:
User Avatar

User Avatar

Wiki User

15y ago

int findMax(int x, int y, int z)

{

int max = x;

if(max < y)

max = y;

if(max < z)

max = z;

return max;

}

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Find max and min of given number in c language?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Write a c program to find the sum of numbers between given limits?

int sum (int min, int max) {return (max-min+1)*(max+min)/2;}


Can you write a source code to find the sum and the largest number of a given array?

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]}


How do you Write a java program to find the average of given numbers?

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 &lt; 10; i++) { int input = scan.nextInt(); if(input &gt; max)//test if the number entered is larger than any previous number max = input; if(input &lt; 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 } }


What is the least possible number of iterations for a for loop?

The least possible is no iterations: for (x=0; x&lt;max; ++x) { // ... } In the above example, if max is less than or equal to zero then the body of the loop will not execute.


What is the code for a C program to find the largest and smallest number?

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 &lt; nums_length; ++i) { // update max, if necessary if( nums[i] &gt; max ) { max = nums[i]; } // update min, if necessary if(nums[i] &lt; min) { min = nums[i]; } } } // min and max are now properly set (or both equal to 0 if nums is empty)

Related questions

Find large number in the given two numbers?

int max = a&gt;b?a:b; // set max to the larger of a and b


Write a java programm to find maximum number in the given array?

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;}}


Write a algorithm and flowchart to find largest among N numbers?

Max = 0For K = 1 to NIf Number(K) > Max then Max = Number(K)Next KPrint Max


C program to find out largest and smallest in a list of given numbers using arrays?

#include &lt;iostream&gt; using std::cout; using std::cin; using std::endl; int main() { int max; int num; for (int counter = 0; counter&lt;15; counter++) { cout &lt;&lt;"Enter a number: "; cin &gt;&gt; max; cout &lt;&lt; "Enter another number: "; cin &gt;&gt; num; if (num &gt; max) num = max; cout &lt;&lt; "The largest number is " &lt;&lt;max; } return 0; }


What is the largest number of babies any single woman has ever given birth to?

The max that someone can have is 50. I think the max anyone has ever had is 19


Write a c program to find the sum of numbers between given limits?

int sum (int min, int max) {return (max-min+1)*(max+min)/2;}


How do you pronouce Max in the Samoan language?

Max is pronounced "maka" or "masa"


Can you write a source code to find the sum and the largest number of a given array?

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]}


A c program to find maximum number in a 3 by 3 matrix?

int matrix[][]; // the matrix to find the max in int max = matrix[0][0]; int r,c; for(r = 0; r &lt; 3; ++r) { for(c = 0; c &lt; 3; ++c) { if(matrix[r][c] &gt; max) { max = matrix[r][c]; } } } // max is now the maximum number in matrix


The MIN function is used to determine the highest number in a range.?

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.


What has the author Max H Miller written?

Max H. Miller has written: 'The logic of language development in early childhood' -- subject(s): Language acquisition, Language and logic, Semantics


How do you find max value out of anonymous array in java?

java is very most important language in computer field. .net is also useful