0% found this document useful (0 votes)
310 views7 pages

PHP Exercise PDF

The document describes 20 different PHP programming challenges involving numeric, string and logic operations. These include writing programs to calculate the sum of digits in a number, determine if a number is even or odd, check if a number is prime, print the table of a given number, calculate the factorial of a number, check if a number is an Armstrong number, check if a number is a palindrome, print the Fibonacci series with and without recursion, reverse a given number, reverse a given string, swap two numbers with and without a third variable, add two numbers, subtract two numbers, calculate the area of a triangle and rectangle, determine if a given year is a leap year, print alphabet triangles, print a number triangle with a given
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
310 views7 pages

PHP Exercise PDF

The document describes 20 different PHP programming challenges involving numeric, string and logic operations. These include writing programs to calculate the sum of digits in a number, determine if a number is even or odd, check if a number is prime, print the table of a given number, calculate the factorial of a number, check if a number is an Armstrong number, check if a number is a palindrome, print the Fibonacci series with and without recursion, reverse a given number, reverse a given string, swap two numbers with and without a third variable, add two numbers, subtract two numbers, calculate the area of a triangle and rectangle, determine if a given year is a leap year, print alphabet triangles, print a number triangle with a given
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

1) Sum of Digits

Write a PHP program to print sum of digits.

Input: 23

Output: 5

Input: 624

Output: 12

2) Even or odd number

Input: 23

Output: odd number

Input: 12

Output: even number

3) Prime number
Write a PHP program to check prime number.

Input: 17

Output: not prime number

Input: 57

Output: prime number

4) Table of number
Write a PHP program to print table of a number.

Input: 2
Output: 2 4 6 8 10 12 14 16 18 20

Input: 5

Output: 5 10 15 20 25 30 35 40 45 50

5) Factorial
Write a PHP program to print factorial of a number.

Input: 5

Output: 120

Input: 6

Output: 720

6) Armstrong number
Write a PHP program to check armstrong number.

Input: 371

Output: armstrong

Input: 342

Output: not armstrong

7) Palindrome number
Write a PHP program to check palindrome number.

Input: 121

Output: not palindrome number

Input: 113
Output: palindrome number

8) Fibonacci Series
Write a PHP program to print fibonacci series without using recursion and using recursion.

Input: 10

Output: 0 1 1 2 3 5 8 13 21 34

9) Reverse Number
Write a PHP program to reverse given number.

Input: 234

Output: 432

10) Reverse String


Write a PHP program to reverse given string.

Input: Ali

Output: ilA

11) Swap two numbers


Write a PHP program to swap two numbers with and without using third variable.

Input: a=5 b=10

Output: a=10 b=5

12) Adding Two Numbers


Write a PHP program to add two numbers.

First Input: 10

Second Input: 20

Output: 30

13) Subtracting Two Numbers


Write a PHP program to subtract two numbers.

First Input: 50

Second Input: 10

Output: 40

14) Area of Triangle


Write a PHP program to find area of triangle.

Base Input: 10

Height Input: 15

Output: 75

15) Area of rectangle


Write a PHP program to find the area of rectangle.

Length Input: 10

Width Input: 20

Output: 200
16) Leap Year
Write a PHP program to find if the given year is leap year or not.

Input: 2000

Output: Leap Year

Input: 2001

Output: Not Leap Year

17) Alphabet Triangle using PHP method


Write a PHP program to print alphabet triangle.

Output:

A
ABA
ABCBA
ABCDCBA
ABCDEDCBA

18) Alphabet Triangle Pattern


Write a PHP program to print alphabet triangle.

Output:

A
ABA
ABCBA
ABCDCBA
ABCDEDCBA

19) Number Triangle


Write a PHP program to print number triangle.

Output:

enter the range= 6


1
121
12321
1234321
123454321
12345654321

20) Star Triangle


Write a PHP programs to print star triangle.

Output:

Output:

Output:
Output:

Output:

You might also like