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.
int getGreaterNumber(int num1, int num2)
{
if (num1 > num2)
{
return num1;
}
else
{
return num2;
}
}
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;
}
//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();
}
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*/
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
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".
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));
#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;}
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.
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.
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, & then divide that result by 2.
1. Read the 3 nos a,b,c 2. Let larget = a 3. if b > largest then largest = b 4. if c > 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<stdio.h> int main() { int num1,num2,num3,num4; int smallest; printf("Please enter a number1"); scanf("%d%*c", &num1); printf("Please enter a number2"); scanf("%d%*c" ,&num2); printf("Please enter a number3"); scanf("%d%*c", &num3); Printf("Please enter a numbe4r"); scanf("%d%*c", &num4); /* num1 set as the smallest */ smallest=num1; if(smallest > num2) then smallest=num2; else if smallest >num3 then smallest=num3; else if smallest>num4 then smallest=num4; printf("smallest number:%d\n,smallest"); return(0); endif endif endif }
The smallest is 11 and the largest is 97.
2520 is the smallest multiple of of first ten natural numbers.
The natural numbers are the numbers used to count things (the counting numbers). The smallest number of things you can have when you have some to count is one. Thus the smallest natural number is 1.
The sum of the smallest and largest prime numbers within 10 is 7.
Highlight the numbers and click on the sort button. You can sort ascending (smallest to largest) or descending (largest to smallest).
The smallest one is 100. The largest one is 999. There are 900 of them.
descending order
Done!
Relative
The smallest number is 5000 while largest number is 14999.
I guess that the smallest would be zero, if you don't consider negative numbers. There is no largest palindromic number - you can make them as large as you like.
the difference