Write a program to Find Maximum Number From Two Numbers in C
Write a program to Find Maximum Number From Two Numbers in C++
Write a program to Find Maximum Number From Two Numbers in Python
Write a program to Find Maximum Number From Two Numbers in PHP
Write a program to Find Maximum Number From Two Numbers in Java
Write a program to Find Maximum Number From Two Numbers in Java Script
Write a program to Find Maximum Number From Two Numbers in C#
Explanation:
Logic
If num1 > num2, then num1 is the maximum.
Otherwise, num2 is the maximum.
Program to Find Maximum Number From Two Numbers
C
C++
Python
PHP
JAVA
Java Script
C#
#include <stdio.h>
int main() {
int num1, num2;
// Input two numbers
printf("Enter two numbers: ");
scanf("%d %d", &num1, &num2);
// Compare and find the maximum number
if (num1 > num2) {
printf("%d is the maximum number.\n", num1);
} else {
printf("%d is the maximum number.\n", num2);
}
return 0;
}
#include <iostream>
using namespace std;
int main() {
int num1, num2;
// Input two numbers
cout << "Enter two numbers: ";
cin >> num1 >> num2;
// Compare and find the maximum number
if (num1 > num2) {
cout << num1 << " is the maximum number." << endl;
} else {
cout << num2 << " is the maximum number." << endl;
}
return 0;
}
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
# Compare and find the maximum number
if num1 > num2:
print(f"{num1} is the maximum number.")
else:
print(f"{num2} is the maximum number.")
<?php
// Input two numbers
$num1 = (float)readline("Enter the first number: ");
$num2 = (float)readline("Enter the second number: ");
// Compare and find the maximum number
if ($num1 > $num2) {
echo "$num1 is the maximum number.\n";
} else {
echo "$num2 is the maximum number.\n";
}
?>
import java.util.Scanner;
public class MaximumNumber {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Input two numbers
System.out.print("Enter the first number: ");
double num1 = scanner.nextDouble();
System.out.print("Enter the second number: ");
double num2 = scanner.nextDouble();
// Compare and find the maximum number
if (num1 > num2) {
System.out.println(num1 + " is the maximum number.");
} else {
System.out.println(num2 + " is the maximum number.");
}
scanner.close();
}
}
let num1 = parseFloat(prompt("Enter the first number: "));
let num2 = parseFloat(prompt("Enter the second number: "));
// Compare and find the maximum number
if (num1 > num2) {
console.log(num1 + " is the maximum number.");
} else {
console.log(num2 + " is the maximum number.");
}
using System;
class Program {
static void Main() {
// Input two numbers
Console.Write("Enter the first number: ");
double num1 = Convert.ToDouble(Console.ReadLine());
Console.Write("Enter the second number: ");
double num2 = Convert.ToDouble(Console.ReadLine());
// Find the maximum number
if (num1 > num2) {
Console.WriteLine(num1 + " is the maximum number.");
} else {
Console.WriteLine(num2 + " is the maximum number.");
}
}
}