Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# Perl programming problem 2

Posted on 2000-04-17
Medium Priority
158 Views
Use the fallowing algebraic formula to write a program in perl that calculates and prints the sum of the integers from 1 to n where n is obtained as user input from the keyboard.

The formula is:  sum of 1 to n:  n x (n+1)
0
Question by:myoreorex
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 6
• 3

Author Comment

ID: 2724419
Adjusted points from 25 to 125
0

LVL 16

Accepted Solution

maneshr earned 500 total points
ID: 2724420
#!/usr/local/bin/perl

print "Enter a number ";
\$user_input=<STDIN>;
chomp(\$user_input); ## Remove the \n from the users input

\$user_input=~ s/\s+//g; ## Remove any white spaces from the user's input.

if (\$user_input!~ /^[+-]?\d+\$/){
exit;
}

\$summ=\$user_input * (\$user_input+1);
print \$summ,"\n";
0

Author Comment

ID: 2724522
This question has a deletion request Pending
0

LVL 16

Expert Comment

ID: 2724709
This question no longer is pending deletion
0

LVL 16

Expert Comment

ID: 2724710
why have you requested a delete for this Q??

0

LVL 16

Expert Comment

ID: 2724719
i think this is what you might want...

#!/usr/local/bin/perl

print "Enter a number ";
\$user_input=<STDIN>;
chomp(\$user_input); ## Remove the \n from the users input
\$user_input=~ s/\s+//g; ## Remove any white spaces from the user's input.
if (\$user_input!~ /^[+-]?\d+\$/){
exit;
}

foreach (1..\$user_input){
\$ans+=\$_;
}
print \$ans,"\n";
0

LVL 16

Expert Comment

ID: 2728133
did you get a chance to try out the solution??

did it work??

let me know.

0

LVL 3

Expert Comment

ID: 2735498
Hmm....

This really looks like someones homework to me.

0

Author Comment

ID: 2735613
Thank you for being the nicest most professional one.

michelle
0

LVL 16

Expert Comment

ID: 2740441
most welcome to be of help to you. :-)

Rgds
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command â€¦
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08â€¦
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: Tâ€¦
Six Sigma Control Plans
###### Suggested Courses
Course of the Month6 days, 23 hours left to enroll