answersLogoWhite

0


Best Answer

This sounds like a homework assignment, so I will give you some pseudo code instead of straight C code.

[code]

OPEN FILE FOR READING

IF NOT END OF FILE THEN

min = READ FILE INPUT

max = min

ENDIF

WHILE NOT END OF FILE

x = READ FILE INPUT

IF x < min THEN

min = x

ENDIF

IF x > max THEN

max = x

ENDIF

ENDWHILE

CLOSE FILE

[/code]

If you are using C, then you will need to use fopen(), scanf(), fclose() and maybe feof(). If you are using C++ then you can use fstream, must like you would use cin, except that you have to open the stream, check for end of file and close it.

User Avatar

Wiki User

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

Wiki User

14y ago

int getGreaterNumber(int num1, int num2)

{

if (num1 > num2)

{

return num1;

}

else

{

return num2;

}

}

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

int
getLargest(int array[], const int asize) {
int largest = array[0];

int i;

for (i = 1; i < asize; ++i) {

if (largest < array[i])

largest = array[i];

}

return largest;

}

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

//using arrays// #include<stdio.h>

#include<conio.h>

void main()

{

int x[10],i;

clrscr();

printf("enter the values:");

for(i=0;i<10;i++)

scanf("%d",&x[i]);

big=x[0];

for(i=0;i<10;i++)

{

if(big<x[i])

{

big=x[i];

}

}

printf("big value =%d",big);

getch();

}

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

import java.io.*;

class largesmall

{

public static void main(String[] args)

{

int arr[] = { 17, 23,31,45,36,7,32,67,54,30};

int l=0; int i; int s=arr[0];

for(i=0;i<10;i++)

{

if(arr[i]>=l)

{

l=arr[i];

}

}

for(i=0;i<10;i++)

{

if(arr[i]<=s)

{

s=arr[i];

}

}

System.out.println("Largest Value : " +l+ "");

System.out.println("Smallest Value : " +s+ "");

}

}

/* Ashish Ranjan

Jaypee Institute of Information Technology*/

This answer is:
User Avatar

User Avatar

Wiki User

10y ago

Biggest = 0

For N = 1 to 10

If Number(N) > Biggest then Biggest = Number(N)

Next N

Print "The biggest of the ten numbers is "; Biggest

Print "That was fun. Thanks for playing."

END

This answer is:
User Avatar

User Avatar

Wiki User

10y ago

Define two variables for the largest and smallest number. I'll call them "smallest" and "largest" for the following explanation. Read the first number; assume that it is both the largest and the smallest. That is, copy its value to both variables. Read additional values in a loop; for every number:

* If it is less than your variable "smallest", copy its value to variable "smallest".

* If it is larger than your variable "largest", copy its value to variable "largest".

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

In Java

int a, b, c; // assign these values elsewhere

int max = Math.max(a, Math.max(b, c));

int min = Math.min(a, Math.min(b, c));

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you Write a program to read natural numbers from a keyboard Find the largest and the smallest number?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Write a program that will find the smallest largest and average values in a collection of N numbers Get the value of N before scanning each value in the collection of N numbers?

#include #include #include int main(int argc, char *argv[]){int n, smallest, largest, sum, temp;if(argc < 2){printf("Syntax: foo val1[val2 [val3 [...]]]\n");exit(1);}smallest = largest = sum = atoi(argv[1]);for(n = 2; n < argc; n++){temp = atoi(argv[n]);if(temp < smallest) smallest = temp;if(temp > largest) largest = temp;sum += temp;}printf("Smallest: %i\nLargest: %i\nAverage: %i\n", smallest, largest, sum / (argc - 1));return 0;}


What does descending mean in maths?

In Maths, we often talk about ascending and descending order. Ascending order is writing numbers from smallest to largest. Descending order is writing numbers from largest to smallest.


How do you write program to read a set of real numbers and find the range is given by the difference between largest and smallest number?

Use the following algorithm (written in pseudocode). Let largest be the lowest possible real number. Let smallest be the greatest possible real number. Repeat while there is input... { Read real number r from input. If r is greater than largest then let largest be r. If r is less than smallest then let smallest be r. } End repeat. Let range be largest minus smallest. Output range.


To take a neck measurement place the measuring tape?

Around your neck. If you need to know the smallest perimeter, then measure around the smallest part of your neck. If you need to know the largest perimeter, then measure around the largest part of your neck. If you need to know the average perimeter, then measure around the smallest part of your neck AND the largest part of your neck, add the numbers together, &amp; then divide that result by 2.


Write algorithm of a largest number in three numbers?

1. Read the 3 nos a,b,c 2. Let larget = a 3. if b &gt; largest then largest = b 4. if c &gt; largest then largest = c..... If you have to process more nos, read all of them in an array. Assume the first element be largest, do comparison through all elements of the array.... Similar algorithm can be developed for finding the lowest also. /*lab practice 2 damithguruge question 4 */ #include&lt;stdio.h&gt; int main() { int num1,num2,num3,num4; int smallest; printf("Please enter a number1"); scanf("%d%*c", &amp;num1); printf("Please enter a number2"); scanf("%d%*c" ,&amp;num2); printf("Please enter a number3"); scanf("%d%*c", &amp;num3); Printf("Please enter a numbe4r"); scanf("%d%*c", &amp;num4); /* num1 set as the smallest */ smallest=num1; if(smallest &gt; num2) then smallest=num2; else if smallest &gt;num3 then smallest=num3; else if smallest&gt;num4 then smallest=num4; printf("smallest number:%d\n,smallest"); return(0); endif endif endif }

Related questions