shad Posted December 21, 2011 Share Posted December 21, 2011 hello! every one!I have one assignment hoping you all will help me.question one1) write a php program to display first ten even numbers.2) write a php program to display odd numbers between "X and y"?3) write a php program to display multiplicatoin table of five ? and the output should be of the form5 * 1 = 5............5 * 10 = 504) write a php program to to convert a number into wordseg: 999 should be displayed as nine nine nine :facepalm:help plzthanks in advance Link to comment Share on other sites More sharing options...
TheGallery Posted December 21, 2011 Share Posted December 21, 2011 Are there any limitations or you are allowed to use any method to do them? Link to comment Share on other sites More sharing options...
shad Posted December 21, 2011 Author Share Posted December 21, 2011 it should be generated only in php no other scripting lang should be used_eg: if if..else while for loop etchope you got it Link to comment Share on other sites More sharing options...
Ingolme Posted December 21, 2011 Share Posted December 21, 2011 So, why aren't you able to do it? It's quite a simple task. I don't think you would learn anything if you had somebody else do it for you. Problem-solving is an essential ability in a programmer.Try to write some code, at least, and show some of your attempt to see where you went wrong. Link to comment Share on other sites More sharing options...
shad Posted December 22, 2011 Author Share Posted December 22, 2011 So, why aren't you able to do it? It's quite a simple task. I don't think you would learn anything if you had somebody else do it for you. Problem-solving is an essential ability in a programmer. Try to write some code, at least, and show some of your attempt to see where you went wrong. thanx for your comments.. I got it !even number generation<?php$i=2;$num=20;for($i=2;$i<=num;$i+=2){echo $i."<br>"}?> 0dd number;$i=1;for($i=1;$i<=20;$i+=2){echo $i."<br>"}?> Multiplication table<?php$i=1;$res;while($i<=10){$res=5*$i;echo "5". "*". "=". "$res"."<br>"}?> But last program can you plz help me number to name conversion Link to comment Share on other sites More sharing options...
TheGallery Posted December 22, 2011 Share Posted December 22, 2011 Did you check your code? Because you got some basic mistakes there. In your first 2 pieces of code you define $i 2 times (one before the loop and one in the loop). What is more you forget to put a semicolon ( ; ) in your echo statements, and last but not least in the last part, you don't change the value of $i inside the loop. You made an infinite loop there. Oh also your last echo statement is a mess, the result you would get from that would be 5*=$res . Your variables should go outside the double-quotes. The correct statement would be this echo "5 * " . $i . " = " . $res . "<br>"; (assuming you fixed what i said about $i) Link to comment Share on other sites More sharing options...
Ingolme Posted December 22, 2011 Share Posted December 22, 2011 Number to name conversion. There are many ways to do it, I can tell you one way: What you need to do is cast your number to a string ( strval() works) and then turn that string into an array using str_split(). Then go through each character in the array and print the appropriate string for the number. You could use an array or a switch(){} to determine which string goes to which number. Don't forget to put spaces between the strings. Link to comment Share on other sites More sharing options...
shad Posted December 23, 2011 Author Share Posted December 23, 2011 Did you check your code? Because you got some basic mistakes there. In your first 2 pieces of code you define $i 2 times (one before the loop and one in the loop). What is more you forget to put a semicolon ( ; ) in your echo statements, and last but not least in the last part, you don't change the value of $i inside the loop. You made an infinite loop there. Oh also your last echo statement is a mess, the result you would get from that would be 5*=$res . Your variables should go outside the double-quotes. The correct statement would be this echo "5 * " . $i . " = " . $res . "<br>"; (assuming you fixed what i said about $i) yes, I thought it that two times declaring is not needed but influenced by c language. hey for the last line echo is semicolon needed echo "5". "*". "=". "$res"."<br>" Is there any problem giving variables in quotes? Link to comment Share on other sites More sharing options...
shad Posted December 23, 2011 Author Share Posted December 23, 2011 I corrected my code and got reply <?php$i=1;$res;while($i<=10){$res=5*$i;echo "5". "*".$i. "=". $res."<br>";$i++;}?> output as 5*1=55*2=105*3=155*4=205*5=255*6=305*7=355*8=405*9=455*10=50 Link to comment Share on other sites More sharing options...
TheGallery Posted December 23, 2011 Share Posted December 23, 2011 ]Is there any problem giving variables in quotes? If you do that they will be displayed as strings, and won't display their actual value. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.