Sponsored Content
Full Discussion: Math Tool
Top Forums Shell Programming and Scripting Math Tool Post 302690605 by PranavEcstasy on Thursday 23rd of August 2012 07:31:03 AM
Old 08-23-2012
Math Tool

Hi all,
I am new to PERL scripts, and i have made my first script which i am posting here.
This math tool performs all basic arithmatic functions.


Code:
#!/usr/bin/perl
print "\t----------Welcome to Maths Tool-----------\n";
do
{
print "Enter your choice :";
print "\n\t1)Addition\n\t2)Subtraction\n\t3)Multiplication\n\t4)division\n";
$a = <>;
if ($a == 1)
{
print "\nHow many numbers you wanna add...??\t";
chomp($b = <>);
print "Enter $b numbers : \n";
for ($count = 1; $count <= $b; $count++)
{
$c = <>;
$d = $d + $c;
}
print "Addition is : $d\n";
}
elsif ($a == 2)
{
print "\nEnter two numbers to subtract :\n";
$b = <>;
$c = <>;
$d = $b - $c;
print "Subtraction is : $d\n";
}
elsif ($a == 3)
{
print "\nHow many numbers you wanna multiply...??";
chomp($b = <>);
$d = 1;
print "\nEnter $b numbers : \n";
for ($count = 1; $count <= $b; $count++)
{
$c = <>;
$d = $d * $c;
}
print "Multiplicationn is : $d\n";
}
elsif ($a ==4)
{
print "\nEnter two numbers to subtract :\n";
$b = <>;
$c = <>;
$d = $b / $c;
print "Division is : $d\n";
}
else
{
print "\nWRONG CHOICE!\n";
}
print "\nDo u want to continue <y/n>";
chomp($var = <>);
} while($var eq "y");
print "\n\t------------Thanks for using Maths Tool--------------\n\n";


PS : This is really a very simple code but its my first one. So I just wanted to know your opinions and comments about it.

Thanks.

Moderator's Comments:
Mod Comment Please view this code tag video for how to use code tags when posting code and data.
 

10 More Discussions You Might Find Interesting

1. Programming

math.h not working? o.0

Alright, umm i cant get this to work. im looking at some example and a book i have. when i try to compile my program i get an error message. ld: 0711-317 ERROR: Undefined symbol: .sqrt ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more information. I did #include<math.h> after my... (2 Replies)
Discussion started by: primal
2 Replies

2. Shell Programming and Scripting

Math calculation help

Hi, I wrote this script awk -F"\t" '{if ((($1 == 586) || ($1 == 68030)) && (($2/1024) < 512)) print $0"\t"(512-($2/1024))"\t"(512-($2/1024))/256}' pcs.txt But I want from the calculation in red to get rid of the decimal part. Like instead of 1.75 to keep only 1.Please somebody tell me what... (4 Replies)
Discussion started by: sickboy
4 Replies

3. Programming

something about <math.h>

Hi, I got an easy problem for you but really difficult for me 'cause I am pretty new to this field I got header file <math.h> included in my .c file , then I write the code as below: k = sqrt(i); /* both variables k and i are int */ then I cc temp.c it says like this undefined... (4 Replies)
Discussion started by: blf0
4 Replies

4. Programming

some math problems in C

I want to calculate secant method using C language That is a program----> #include<stdio.h> #include<math.h> #include<stdlib.h> main() { double fx(double x); double x0,x1,x2,f0,f1,f2,err; int n,i; printf("\n\n f(x) =x*x*x-5*x-7"); printf("\n\nEnter an interval in" ... (4 Replies)
Discussion started by: cdfd123
4 Replies

5. UNIX for Dummies Questions & Answers

math in unix

I have 2 variables a=2 b=1 i want to add a and b how do i do this in unix using just the echo command and by assigning it to a different variable like c? (13 Replies)
Discussion started by: khestoi
13 Replies

6. Shell Programming and Scripting

math help

$ x=1 $ y=1.5 $ z=$((x*y)) bash: 1.5: syntax error: invalid arithmetic operator (error token is ".5") What's wrong? (2 Replies)
Discussion started by: rockbike
2 Replies

7. Shell Programming and Scripting

Need help with AWK math

I am trying to do some math, so that I can compare the average of six numbers to a variable. Here is what it looks like (note that when I divide really big numbers, it isn't a real number): $ tail -n 6 named.stats | awk -F\, '{print$1}' 1141804 1140566 1139429 1134210 1084682 895045... (3 Replies)
Discussion started by: brianjb
3 Replies

8. Programming

Math function with C

I have int miles, yards; float kilometers; float kilometers2; miles = 26; yards = 385; kilometers = 1.609 * (miles + yards / 1760.0); where int/float remains a float. How ever if I change it to kilometers = 1.609 * (miles + yards / 1760); ... (7 Replies)
Discussion started by: Fingerz
7 Replies

9. UNIX for Dummies Questions & Answers

Linux Math Help

I am struggling with scripting this challenge a friend and I have. You have file1 and its contents is a single number you have file 2 and its contents are a different number you want to add file1 to file2 and have the output be put into file3 (3 Replies)
Discussion started by: minkyboodle
3 Replies

10. UNIX for Dummies Questions & Answers

Math

i have file (my_file.txt) that looks like this: 000000000000010000 000000000000010000 000000000000005000 000000000000005000 000000000000005000 000000000000005000 000000000000005000 000000000000005000 000000000000005000 000000000000005000 all said and one, it should look... (11 Replies)
Discussion started by: lawsongeek
11 Replies
bigrat(3pm)						 Perl Programmers Reference Guide					       bigrat(3pm)

NAME
bigrat - Transparent BigNumber/BigRationale support for Perl SYNOPSIS
use bigrat; $x = 2 + 4.5," "; # BigFloat 6.5 print 1/3 + 1/4," "; # produces 7/12 DESCRIPTION
All operators (inlcuding basic math operations) are overloaded. Integer and floating-point constants are created as proper BigInts or BigFloats, respectively. Other than bignum, this module upgrades to Math::BigRat, meaning that instead of 2.5 you will get 2+1/2 as output. MODULES USED "bigrat" is just a thin wrapper around various modules of the Math::BigInt family. Think of it as the head of the family, who runs the shop, and orders the others to do the work. The following modules are currently used by bignum: Math::BigInt::Lite (for speed, and only if it is loadable) Math::BigInt Math::BigFloat Math::BigRat MATH LIBRARY Math with the numbers is done (by default) by a module called Math::BigInt::Calc. This is equivalent to saying: use bigrat lib => 'Calc'; You can change this by using: use bigrat lib => 'BitVect'; The following would first try to find Math::BigInt::Foo, then Math::BigInt::Bar, and when this also fails, revert to Math::BigInt::Calc: use bigrat lib => 'Foo,Math::BigInt::Bar'; Please see respective module documentation for further details. SIGN The sign is either '+', '-', 'NaN', '+inf' or '-inf' and stored seperately. A sign of 'NaN' is used to represent the result when input arguments are not numbers or as a result of 0/0. '+inf' and '-inf' represent plus respectively minus infinity. You will get '+inf' when dividing a positive number by 0, and '-inf' when dividing any negative number by 0. METHODS Since all numbers are not objects, you can use all functions that are part of the BigInt or BigFloat API. It is wise to use only the bxxx() notation, and not the fxxx() notation, though. This makes you independed on the fact that the underlying object might morph into a differ- ent class than BigFloat. EXAMPLES
perl -Mbigrat -le 'print sqrt(33)' perl -Mbigrat -le 'print 2*255' perl -Mbigrat -le 'print 4.5+2*255' perl -Mbigrat -le 'print 3/7 + 5/7 + 8/3' perl -Mbigrat -le 'print 12->is_odd()'; LICENSE
This program is free software; you may redistribute it and/or modify it under the same terms as Perl itself. SEE ALSO
Especially bignum. Math::BigFloat, Math::BigInt, Math::BigRat and Math::Big as well as Math::BigInt::BitVect, Math::BigInt::Pari and Math::BigInt::GMP. AUTHORS
(C) by Tels <http://bloodgate.com/> in early 2002. perl v5.8.0 2002-06-01 bigrat(3pm)
All times are GMT -4. The time now is 08:25 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy