Sponsored Content
Top Forums UNIX for Dummies Questions & Answers nested loop:multiplication table Post 302362392 by danmero on Thursday 15th of October 2009 11:33:08 PM
Old 10-16-2009
Code:
# for x in {1..5};do for y in {1..5};do echo -n "$(( $x * $y )) ";done;echo;done
1 2 3 4 5
2 4 6 8 10
3 6 9 12 15
4 8 12 16 20
5 10 15 20 25

 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

nested loop

I have two do loops. When I break of the inner loop it doesn't go back to the outer loop but exit the program. (5 Replies)
Discussion started by: chinog
5 Replies

2. Shell Programming and Scripting

Variable in While Loop Nested If

Hi all, I'm having problems with the setting a variable in a nested if statement. It doesn't seem to change even if it mets the 'if' condition. My script essentially looks for a user name from the output from a kerberos command. When I find the user name, I tried to change a variable and exit... (6 Replies)
Discussion started by: geass
6 Replies

3. UNIX for Dummies Questions & Answers

nested hash table

Hi, I have a nested hash table say for example as follows: %coins = ( 1 => { "Quarter"=>25, "Dime"=>10, "Nickel"=>5, }, 2 => { "asd"=>34, "qwe"=>45, ... (0 Replies)
Discussion started by: arthi
0 Replies

4. Shell Programming and Scripting

nested loop problem

Please see the following script. basic="a b c" advance="d e f" A="basic advance" for g in $A do echo $g done The result would be obviously basic advance I want to ask how can i get the following result using $A in for loop a b c (5 Replies)
Discussion started by: mmunir
5 Replies

5. UNIX for Dummies Questions & Answers

Multiplication using bc in a for loop

Hi, I would like to carry out a multiplication in a for loop but some how I get always zero. The result of the multiplication must be assigned to the variable x. Here is teh code for (( i=1;i<=15;i++)); do x=$( printf "%s\n " 'scale = 10; i*5.0*335.0*3.0/1000.0' | bc) echo $x $i... (5 Replies)
Discussion started by: f_o_555
5 Replies

6. Shell Programming and Scripting

Error with "multiplication table" in shell script

#!/bin/sh echo Enter the multiplication number required: read number for i in 1 2 3 4 5 6 7 8 9 10 do echo "$number * $i = expr $number \* $i" done I am not getting the output for this multiplication table. (4 Replies)
Discussion started by: vinodpaw
4 Replies

7. UNIX for Dummies Questions & Answers

Nested loop code

Greetings, Would anyone be able to tell me why this nested loop doesn't seem to work in any variation? for i in {1..8} do echo "i is "$i for j in {1..i} do echo "j is "$j done doneoutput is always along the lines of i is 1... (7 Replies)
Discussion started by: barnhillec
7 Replies

8. Shell Programming and Scripting

Nested if loop

Hi Team, I just want to check whether my nested if loop used is correct or not. if ] if ] export1 else export2 fi else if ] export3 else export4 fi fi Thanks Shiva (5 Replies)
Discussion started by: shivashankar_S
5 Replies

9. Homework & Coursework Questions

Multiplication Table in UNIX

How can I produce this kind of output? Enter a number: 3 MULTIPLICATION TABLE: 0 1 2 3 1 1 2 3 2 2 4 6 3 3 6 9 When you enter a number, it should show you the corresponding multiplication table. Plus we need to use for loops that I do not actually know. Thanks in advance! Here is my... (2 Replies)
Discussion started by: larkha
2 Replies
ROUND(3)								 1								  ROUND(3)

round - Rounds a float

SYNOPSIS
float round (float $val, [int $precision], [int $mode = PHP_ROUND_HALF_UP]) DESCRIPTION
Returns the rounded value of $val to specified $precision (number of digits after the decimal point). $precision can also be negative or zero (default). Note PHP doesn't handle strings like "12,300.2" correctly by default. See converting from strings. PARAMETERS
o $val - The value to round o $precision - The optional number of decimal digits to round to. o $mode - Use one of the following constants to specify the mode in which rounding occurs. +--------------------+---------------------------------------------------+ | Constant | | | | | | | Description | | | | +--------------------+---------------------------------------------------+ | | | | PHP_ROUND_HALF_UP | | | | | | | Round $val up to $precision decimal places away | | | from zero, when it is half way there. Making 1.5 | | | into 2 and -1.5 into -2. | | | | | | | |PHP_ROUND_HALF_DOWN | | | | | | | Round $val down to $precision decimal places | | | towards zero, when it is half way there. Making | | | 1.5 into 1 and -1.5 into -1. | | | | | | | |PHP_ROUND_HALF_EVEN | | | | | | | Round $val to $precision decimal places towards | | | the next even value. | | | | | | | |PHP_ROUND_HALF_ODD | | | | | | | Round $val to $precision decimal places towards | | | the next odd value. | | | | +--------------------+---------------------------------------------------+ RETURN VALUES
The rounded value EXAMPLES
Example #1 round(3) examples <?php echo round(3.4); // 3 echo round(3.5); // 4 echo round(3.6); // 4 echo round(3.6, 0); // 4 echo round(1.95583, 2); // 1.96 echo round(1241757, -3); // 1242000 echo round(5.045, 2); // 5.05 echo round(5.055, 2); // 5.06 ?> Example #2 $mode examples <?php echo round(9.5, 0, PHP_ROUND_HALF_UP); // 10 echo round(9.5, 0, PHP_ROUND_HALF_DOWN); // 9 echo round(9.5, 0, PHP_ROUND_HALF_EVEN); // 10 echo round(9.5, 0, PHP_ROUND_HALF_ODD); // 9 echo round(8.5, 0, PHP_ROUND_HALF_UP); // 9 echo round(8.5, 0, PHP_ROUND_HALF_DOWN); // 8 echo round(8.5, 0, PHP_ROUND_HALF_EVEN); // 8 echo round(8.5, 0, PHP_ROUND_HALF_ODD); // 9 ?> Example #3 $mode with precision examples <?php /* Using PHP_ROUND_HALF_UP with 1 decimal digit precision */ echo round( 1.55, 1, PHP_ROUND_HALF_UP); // 1.6 echo round( 1.54, 1, PHP_ROUND_HALF_UP); // 1.5 echo round(-1.55, 1, PHP_ROUND_HALF_UP); // -1.6 echo round(-1.54, 1, PHP_ROUND_HALF_UP); // -1.5 /* Using PHP_ROUND_HALF_DOWN with 1 decimal digit precision */ echo round( 1.55, 1, PHP_ROUND_HALF_DOWN); // 1.5 echo round( 1.54, 1, PHP_ROUND_HALF_DOWN); // 1.5 echo round(-1.55, 1, PHP_ROUND_HALF_DOWN); // -1.5 echo round(-1.54, 1, PHP_ROUND_HALF_DOWN); // -1.5 /* Using PHP_ROUND_HALF_EVEN with 1 decimal digit precision */ echo round( 1.55, 1, PHP_ROUND_HALF_EVEN); // 1.6 echo round( 1.54, 1, PHP_ROUND_HALF_EVEN); // 1.5 echo round(-1.55, 1, PHP_ROUND_HALF_EVEN); // -1.6 echo round(-1.54, 1, PHP_ROUND_HALF_EVEN); // -1.5 /* Using PHP_ROUND_HALF_ODD with 1 decimal digit precision */ echo round( 1.55, 1, PHP_ROUND_HALF_ODD); // 1.5 echo round( 1.54, 1, PHP_ROUND_HALF_ODD); // 1.5 echo round(-1.55, 1, PHP_ROUND_HALF_ODD); // -1.5 echo round(-1.54, 1, PHP_ROUND_HALF_ODD); // -1.5 ?> CHANGELOG
+--------+---------------------------------------------------+ |Version | | | | | | | Description | | | | +--------+---------------------------------------------------+ | 5.3.0 | | | | | | | The $mode parameter was introduced. | | | | | 5.2.7 | | | | | | | The inner workings of round(3) was changed to | | | conform to the C99 standard. | | | | +--------+---------------------------------------------------+ SEE ALSO
ceil(3), floor(3), number_format(3). PHP Documentation Group ROUND(3)
All times are GMT -4. The time now is 07:40 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy