Week 4
Week 4
Problem Statement:
Write a Program which determines the largest and the smallest number that can
be stored in different data types like short, int, long, float, and double. What
happens when you add 1 to the largest possible integer number that can be
stored?
Aim:
Write a Program which determines the largest and the smallest number
Software Requirements:
Description:
Here, the program asks the user to input total number of elements among which
the largest and the smallest is to be found. It then asks for the first number from
the user before the loop, which is assigned to both variable lar and variable sm.
Here, we suppose that lar is the largest number and sm is the smallest number
for now.
Algorithm:
Step 1: Start
Step 2: Declare the variables
Step 3: Enter total number of elements
Step 4: Read the given elements
Step 5: Compute the code part by applying the looping constraints
Step 6: Check the conditions
Step 7: according to the given elements on the screen , it gives the resultant
element is largest element and smallest element.
Step 8: Stop
Flow Chart:
1
Source Code:
#include<stdio.h>
#include<conio.h>
int main()
{
int i, n, lar,sm, elem;
printf ("Enter total number of elements:");
scanf ("%d", &elem);
printf ("Enter first number:");
scanf ("%d", &n);
lar = n;
sm=n;
for (i=1; i<= elem -1 ; i++)
{
printf ("\n Enter another number:");
scanf ("%d",&n);
if (n>lar)
lar=n;
if (n<sm)
sm=n;
}
printf ("\n The largest number is %d", lar);
printf ("\nThe smallest number is %d", sm);
return 0;
}
Compiler (F9): Click on F9 to compile the program which helps us to find the
errors so that the file extends to large.exe file name.
Run (F10): After compilation of the program click on F10 to run the program
and gives output.
Output:
2
Enter another number:40