answersLogoWhite

0


Best Answer

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)

User Avatar

Wiki User

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

Wiki User

14y ago

//The following program will find the largest and smallest number of a group 10

#include

using namespace std;

const int SIZE=10;

int main()

{

int num[SIZE], i ;

for(i=0;i

cout <<"Enter a number: ";

cin >>num[i];

}

//The following will sort all the number in the array from greatest to least

for(i=0;i

for( k=i+1;k

if(num[ i ]

temp= num[ i ];

num[ i ]=num[ k ];

num[ k ]= temp;

}

cout <<" The largest number is "<< num[ 0 ] <

cout <<" The smallest number is "<< num[SIZE-1];

return 0;

}

If you want to find out the same thing for a larger or smaller group of number just change the const int SIZE= ; to equal how many numbers you want to find it from

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

A Discussion has been started about this question. To view it and take part, please click on the middle button shown below.

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

to find smallest and biggest digit in a number

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

What is your question about it.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the code for a C program to find the largest and smallest number?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How do you beat find HQ beach house?

CODE HINTS ( no spoilers)box under umbrella code is on telescopeliving room code is in bathroomold scroll number to letter code use it on the box in the bedroomclick the smallest to largest decimal


Write a program find maximum number from given three number in 8085 micro processor?

This code find s the largest and the smallest number in an array terminated with a zero. It's not exactely a perfect match for the question but I dion't believe in answering question papers. It's always good to let the student do some work. There's enough example here to cut it down to provide an answer to the question. CODE SEGMENT MOV AX,DATA MOV DS,AX ; initialize DS MOV DI, OFFSET ARRAY ; DI points to the array MOV AX, [DI] ; AX contains the first element MOV LARGEST, AX ; initialize largest MOV SMALLEST, AX ; initialize smallest MOV CX,6 ; loop counter Al: MOV AX, [DI] ; get array value CMP AX, SMALLEST ; [DI] = smallest? JGE A2 ; yes : skip MOV SMALLEST, AX ; no : move [DI] to smallest JMP A3 ; as it is smallest, thus no need ; to compare it with the largest . i A2: CMP AX,LARGEST ; [DI] = largest JLE A3 ; yes : skip MOV LARGEST, AX ; no : mov [Dl] to largest A3: ADD DI,2 ; point to next number LOOP A1 ; repeat the loop until CX = 0 MOV AX, 4C00h INT 21h ; halt, return to DOS CODE ENDS DATA SEGMENT ARRAY DW -1, 2000, -4000, 32767, 500, 0 LARGEST DW ? SMALLEST DW ? DATA ENDS END.


How to find the smallest number in c code?

smallest = min (one_number, another_number); ...or... smallest = one_number &lt; another_number ? one_number : another_number;


What does photo shop do with your serial number?

The serial number is a code that unlocks the program.


How the program statement and code are related?

A statement in your program is part of the code. In a low-level programming language, a statement will map directly to a single CPU instruction. In a high-level programming language, a statement is the smallest element of the language's syntax.


What is the code of a c program that will read in a positive integer value and determine If the integer is a prime number and If the integer is a Fibonacci number?

see the program


What is Indoneisian Currency?

The rupiah is the currency of IndonesiaThe smallest coin is 50 rupiah, the largest banknote is 100,000 rupiah.The international trading code is IDR.


What is the computer term used to describe a spelling or grammatical error in a computer program?

That's commonly called a bug. Even the smallest spelling error in a line of computer code can have a 'cascade' effect over the whole program.


Use of m02 code in cnc program?

indicates the number of machined parts.the number id incremented each time m02,m30 m02= program end m30 =


A computer program has been written to break a code the code uses the letters A-G with each letter being used only once If the program can try 1 unique code every second what is the maximum number?

7!


How can MySpace text be changed?

Text on Myspace can be changed and adjusted by using HTML code. One can make the text big, small, or be more specific with ordering the font size as a number between 1 and 7 with 1 being the smallest and 7 being the largest.


What is the largest positive number one can represent in an eight-bit two's complement code?

127.