Largest Number of Two Numbers in C,C++,Java and Python
The program is written to find the largest number between two given numbers. The two numbers are taken as inputs from the user and then the values are compared and the largest value is printed.
For example,
If the two numbers are 5 and 10, then the largest number is 10 which will be displayed as output.
INPUT: Two numbers
OUTPUT: Largest number
PROCESS:
Step 1: [Taking the inputs]
Read a, b [two numbers]
Step 2: [Finding the largest number]
If a>b then
Print “a is largest”
Else
Print “b is largest”
[End of ‘if’]
Step 3: Stop.
TIME COMPLEXITY:
if(a>b) ---------------------------------- O(1)
printf("%d is largest",a);
else -------------------------------------- O(1)
printf("%d is largest",b);
The time complexity of this program is O(1) means it requires a constant time to execute this program.
SPACE COMPLEXITY:
The space complexity of this program is O(1) as it requires a constant number of spaces for any given input.
Related
Contributed by