পোস্টগুলি

Learn PHP লেবেল থাকা পোস্টগুলি দেখানো হচ্ছে

Write a program which takes some input into an Array from console and finds the second last occurrence of a number from that array.

Problem Number : 3 Write a program which takes some input into an Array from console and finds the second last occurrence of a number from that array. (print the index) Sample Input: 10 15 2 35 11 9 7 2 47 13 2 2 Sample Output: 7 Source code :  Download Solution for this problem : <?php //echo "Hello World !"; echo "<br/>"; $a=array(10,15,2,35,11,9,7,2,47,13,2); $count=0;   for($i=count($a)-1;$i>0;$i--) { if($a[$i]==2) { $count++; } if($count==2){ break; } } echo $i; // echo $count; echo "<br/>"; echo "<br/>"; ?> Sample Input: 10 15 2 35 11 9 7 2 47 13 2 2 Sample Output: 7

Write a program which takes a string as input and finds the number of occurrence of “i”.

Problem number : 2 Write a program which takes a string as input and finds the number of occurrence of “i”. Sample Input: University Sample Output: 2 Solution For this problem : <?php //echo "Hello World !"; echo "<br/>"; $name="university"; $count=0;   for($i=0;$i<strlen($name);$i++) { if($name[$i]=="i") { $count++; } } echo $count; echo "<br/>"; echo "<br/>"; ?> Sample Input: University Sample Output: 2

Write a program which can print the following sequences: Sample Output: 1, 10, 100, 1000, ……, N 1, 3, 6, 10, 15, ……, N

Problem number : 1  Write a program which can print the following sequences: Sample Output: 1, 10, 100, 1000, ……, N 1, 3, 6, 10, 15, ……, N Solution for this problem : <?php //echo "Hello World !"; echo "<br/>"; $a=1;   for($i=0;$i<4;$i++){ echo $a; echo ",&nbsp;"; $a=$a*10; } echo "...... , N"; echo "<br/>"; echo "<br/>"; $n=1; for($j= 0; $j < 5; $j++){ $res = $n*($n+1)/2; echo $res; $n++; echo ",&nbsp;"; } echo "...... , N"; echo "<br/>"; echo "<br/>"; ?> Sample Output: 1, 10, 100, 1000, ……, N 1, 3, 6, 10, 15, ……, N