Program to find the max of 4 number

C Program

#include
int main() {
 int a,b,c,d,max;
 printf("Enter any 4 numbers: ");
 scanf("%d%d%d%d",&a,&b,&c,&d);
 
 if(a > b && a > c && a > d) {
  max = a;
 } else if(b > c && b > d) {
  max = b;
 } else if(c > d) {
  max = c;
 } else {
  max = d;
 }
 
 printf("Max = %d",max);
 return 0;
}

C++ Program

#include
using namespace std;
int main() {
 int a,b,c,d;
 
 cout << "Enter any 4 numbers: ";
 cin >> a >> b >> c >> d;
 
 int max;
 
 if(a > b && a > c && a > d) {
  max = a;
 } else if(b > c && b > d) {
  max = b;
 } else if(c > d) {
  max = c;
 } else {
  max = d;
 }
 
 cout << "Max = " << max << endl;
 return 0;
}

Java Program

import java.util.Scanner;
class Max4 {
 public static void main(String args[]) {
  int a,b,c,d;
  
  Scanner sc = new Scanner(System.in);
  
  System.out.print("Enter any 4 numbers: ");
  a = sc.nextInt();
  b = sc.nextInt();
  c = sc.nextInt();
  d = sc.nextInt();
  
  int max;
  
  if(a > b && a > c && a > d) {
   max = a;
  } else if(b > c && b > d) {
   max = b;
  } else if(c > d) {
   max = c;
  } else {
   max = d;
  }
  
  System.out.println("Max = "+max);
 }
}

Go Lang

package main
import "fmt"

func main() {
 var a,b,c,d int
 fmt.Print("Enter any 4 numbers: ")
 fmt.Scan(&a,&b,&c,&d)
 
 var max int
 if a > b && a > c && a > d {
  max = a
 } else if b > c && b >d {
  max = b
 } else if c > d {
  max = c
 } else {
  max = d
 }
 
 fmt.Print("Max = ",max)
}

PHP

if(isset($_POST['sub'])) {
 $a = $_POST['a'];
 $b = $_POST['b'];
 $c = $_POST['c'];
 $d = $_POST['d'];

 if($a > $b && $a > $c && $a > $c) {
  $max = $a;
 } elseif($b > $c && $b > $d) {
  $max = $b;
 } elseif ($c > $d) {
  $max = $c;
 } else {
  $max = $d;
 }

 echo "Max = ".$max;
}

Comments

Popular posts from this blog

Arrays in C Language

Variable Naming & Scope of Variable

Inline V/S Block Level Element

Variables in Go lang

Identifiers

String in golang

Identify Variable type and values in go lang

Decision Making in Go lang

Installing go lang

Sum of two numbers in go lang