Even numbers are those which are divisible by 2. Numbers like 2,4,6,8,10, etc are even.
Odd numbers are those which are not divisible by 2. Numbers Like 1, 3, 5, 7, 9, 11, etc are odd.
Program Logic:
- Take Given / Entered Number.
- Divide The Number By 2.
- If the remainder is 0, print even number else print odd number.
<?php
if(isset($_POST['submit']))
{
$num1=$_POST['num1'];
if($num1%2 == 0){
$res = 'even';
}else{
$res = 'odd';
}
echo "<h4 style='text-align:center'>Entered Number " .$num1. " is an " . $res ." Number </h4>";
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Find Number Is Even / Odd</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
</head>
<body>
<div style="margin-top:50px;" class="mainbox col-md-6 col-md-offset-3 col-sm-8 col-sm-offset-2">
<div class="panel panel-info" >
<div class="panel-heading">
<div class="panel-title">Find Number Is Even / Odd</div>
<div style="float:right; font-size: 80%; position: relative; top:-10px"></div>
</div>
<div style="padding-top:30px" class="panel-body" >
<div style="display:none" id="login-alert" class="alert alert-danger col-sm-12"></div>
<form name="add" method="post" class="form-horizontal" role="form">
<div style="margin-bottom: 25px" class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-pencil"></i></span>
<input type="text" class="form-control" name="num1" value="" placeholder="Enter Number" required>
</div>
<div style="margin-top:10px" class="form-group">
<!-- Button -->
<div class="col-sm-12 controls">
<input type="submit" value="Submit" name="submit" id="submit-btn" Class="btn btn-success" />
</div>
</div>
<div class="form-group" id="result" >
<div class="col-md-12 control">
<div style="border-top: 1px solid#888; padding-top:15px; font-size:85%" >
<!--<h3> The Sum Of <?php echo $num1;?> + <?php echo $num2;?> = <?php echo $result;?></h3>-->
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</body>
</html>
0 Comments