Program to find the max of 3 numbers

C Program

#include<stdio.h>
int main() {
 int a,b,c,max;
 
 printf("Enter any 3 numbers: ");
 scanf("%d%d%d",&a,&b,&c);
 
 if(a > b) {
  if(a > c) {
   max = a;
  } else {
   max = c;
  }
 }else {
  if(b > c) {
   max = b;
  }else {
   max = c;
  }
 }
 printf("Max = %d",max);
}

C++ Program

#include
using namespace std;

int main() {
 int a,b,c;
 
 cout << "Enter any 3 numbers: ";
 cin >> a >> b >> c;
 
 int max;
 if(a > b) {
  if(a > c) {
   max = a;
  } else {
   max = c;
  }
 }else {
  if(b > c) {
   max = b;
  }else {
   max = c;
  }
 }
 
 cout << "Max = " << max << endl;
}

JAva

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

Go Lang

package main

import "fmt"

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

PHP

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

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

 echo "Max = ".$max;
}

Comments

Popular posts from this blog

String in golang

Inline V/S Block Level Element

Floating point Data types in Go lang

Escape Sequence | Formatted Printing | Interview Questions

Sum of two numbers

Operators in C Language| Part-4

Printing in C programming

Arrays in C Language

Program to check a year is leap year or not.

Data types in Java