PHP WEB DEVELOPMENT INTERVIEW CODING PREPARED BY ME OF PITANGENT ANALYTICS AND TECHNOLOGY SOLUTIONS PVT. LTD FOR FRESHERS

PHP WEB DEVELOPMENT INTERVIEW CODING PREPARED BY ME OF PITANGENT ANALYTICS AND TECHNOLOGY SOLUTIONS PVT. LTD FOR FRESHERS

Q1. Write a PHP program to count the number of vowels in a string.

Ans: PROGRAM NO. - 1 =>

<?php

$str="Welcome To Capgemini";

$vow=0;

$str=str_replace(" ", "", $str);

$len=strlen($str);

for ($j=0; $j < $len; $j++) { 

if ($str[$j] == "a" || $str[$j] == "e" || $str[$j] == "i" || $str[$j] == "o" || $str[$j] == "u" || $str[$j] == "A" || $str[$j] == "E" || $str[$j] == "I" || $str[$j] == "O" || $str[$j] == "U") {

$vow++;

}

}

print_r("The number of vowels in a string is: ".$vow);

?>

OUTPUT OF PROGRAM NO. - 1 =>

PROGRAM NO. - 2 =>

<?php

$str="Welcome To Pitangent";

$vow=0;

$str=str_replace(" ", "", $str);

$length=strlen($str);

for ($i=0; $i < $length; $i++) { 

if ($str[$i] == 'a' || $str[$i] == 'e' || $str[$i] == 'i' || $str[$i] == 'o' || $str[$i] == 'u' || $str[$i] == 'A' || $str[$i] == 'E' || $str[$i] == 'I' || $str[$i] == 'O' || $str[$i] == 'U') {

$vow++;

}

}

print_r("The number of vowels in a string is: ".$vow."<br>");

?>

OUTPUT OF PROGRAM NO. - 2 =>


Q2. Write a PHP code to check whether a number is prime or not.

Ans: PROGRAM NO. - 1 =>

<?php

function isPrime($num){

if ($num <= 1) {

return false;

}

for ($i=2; $i <= sqrt($num); $i++) { 

if ($num%$i==0) {

return false;

}

}

return true;

}

$number=19;

if (isPrime($number)) {

echo "$number is a prime number"."<br>";

}

else{

echo "$number is not a prime number";

}

?>

OUTPUT OF PROGRAM NO. - 1 =>


PROGRAM NO. - 2 =>
<?php
function isPrime($num){
if ($num<=1) {
return false;
}
for ($j=2; $j <= sqrt($num); $j++) { 
if ($num%$j==0) {
return false;
}
}
return true;
}
$number=25;
if (isPrime($number)) {
echo "$number is a prime number"."<br>";
}
else{
echo "$number is not a prime number";
}
?>

OUTPUT OF PROGRAM NO. - 2 =>


PROGRAM NO. - 3 =>
<?php
function isPrime($num){
if ($num<=1) {
return false;
}
for ($k=2; $k <= sqrt($num) ; $k++) { 
if ($num%$k==0) {
return false;
}
}
return true;
}
$number=11;
if (isPrime($number)) {
echo "$number is a prime number"."<br>";
}
else{
echo "$number is not a prime number";
}
?>

OUTPUT OF PROGRAM NO. - 3 =>



Comments

Popular posts from this blog

Programmings Based On Array And String Functions To Merge The 2 Arrays, Then After Merge Convert Into String And Then Find Out The 1st And Last Word From The Reverse String

PHP WEB DEVELOPMENT INTERVIEW QUESTIONS ASKED IN APOLLO HOSPITAL ALONG WITH MY OWN CONCEPTS AND MY OWN EXPLANATION ANSWERS(PART - 1) REST OF THE QUESTIONS AND ANSWERS WILL BE PREPARED BY ME IN MY NEXT BLOG

Mini Project On Multi User CRUD Operations(Create, Read, Update & Delete) Of Donar Details Of Indian Nationals Who Donate To Ramkrishna Math, Belur Math Using PDO (PHP Data Objects) With Proper Explanation Of Each And Every Individual Line Of The Code Of connection.php Page, form.php Page, formaction.php Page, admin_display.php Page, client_display.php Page, edit.php Page, editaction.php Page And delet.php Page (Here You Will Find The Image Of Sayang Sri Ramkrishna Dev, Sayang Sri Ma Sarada Devi & Sayang Sri Swami Vivekananda) In My CRUD Operation