Jump to content

shad
 Share

Recommended Posts

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

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.

  • Like 1
Link to comment
Share on other sites

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

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)

Edited by TheGallery
Link to comment
Share on other sites

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

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?

Edited by shad
Link to comment
Share on other sites

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

Edited by shad
Link to comment
Share on other sites

]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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...