Fundamental Programming
Fundamental Programming
Fundamental Programming
Programming Fundamental
1. Write a program to convert number of days to years, weeks and days from the given number.
Example.
Data : 373 days
Output :373 days = 1 year(s), 1 Week(s) and 1 day(s)
$days = 373;
$days / 365 = $years;
$weeks = ($days % 365) / 7;
$days1 = $days (($years * 365 + ($weeks * 7);
2. Write a program to calculate diameter, circumference and area of the circle from the given
radius. Example.
Data : radius = 10,
Output : Diameter : 20 Circumference : 62.79
Area : 314
$radius = 10
$diameter = 2 * $radius
Echo $diameter
$Circumference = 2 * (22/7) * ($radius * $radius)
Echo $circumference
$area = 22/7 * $radius * 2
Example.
Data :
Physics = 95
Chemistry = 90
Biology = 87
Math = 93
Computer = 90
4.
Write a program to check if the sales is profit or loss from two variable, c
ost price and sales price
of the product.
Example 1.
Data
:
Sales Price = 1000
Cost Price = 800
Output : Profit = 200
Example 2.
Data
:
Sales Price = 950
Cost Price = 1000
Output : Loss = 50
$cost = 800
$sales = 1000
$output = 0
5.
6.
7. Write a to check whether the number is prime number or not.
Example.
Data : 17
Output
:
17 is prime number
$num = 17
$Check = True;
for ($i = 2; $i < $num; $i++)
{
if ($num % $i == 0)
{
$bCheck = False;
break;
}
if ($bCheck)
{ echo 'Prime';}
else
{echo 'NOT prime'; }
8.
9. Write a function to check whether the given number is even or odd using. Example.
$num = 10
if ($num % 2 == 0)
{
Echo is even number
}
elseif ($num % 2 != 0)
{echo is odd number; }
10. Write a recursive function to calculate factorial from the given number. Example.
Data : 5 Output :
Factorial of 5 = 120
$number = 5
function factorial($number) {
if ($number < 2) {
return 1;
} else {
Example.
Data : 22345
if ($var == 0;) {
return 0
if ($var !=0;) {
12. $input = 5;
echo "_"; }
echo "*";
echo "<br>";}
?>