473,385 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Multiplying in a loop

Hey.
My program inputs a number (n) and then outputs the result of all of the numbers up to and including n multiplied together.
E.g.
n = 7
result = 1 * 2 * 3 * 4 * 5 * 6 * 7

I know that I need to use a loop to get all the numbers but then how do I multiply them all together?
Thanks
Apr 20 '07 #1
2 2684
chella
51
Hey.
My program inputs a number (n) and then outputs the result of all of the numbers up to and including n multiplied together.
E.g.
n = 7
result = 1 * 2 * 3 * 4 * 5 * 6 * 7

I know that I need to use a loop to get all the numbers but then how do I multiply them all together?
Thanks
Hi,
The logic to obtain this is simple. Have a for loop with the condition (i<=n)
Inside the for loop have 'res=res*i' (initialize res to 1)
The 'res' will have the expected value.

Regards,
chella
Apr 20 '07 #2
Sorry it took awhile but thanks so much for that.
Apr 22 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Charles Alexander | last post by:
Hello I am new to php & MySQL - I am trying to retrieve some records from a MySQL table and redisplay them. The data in list form looks like this: Sample_ID Marker_ID Variation ...
2
by: cplusplus | last post by:
Hello, I have newbie question. I'm stuck on this current assignment. Write a program that prompts the user for two integer values, passes the values to a function where they are multiplied...
2
by: Targa | last post by:
<input NAME="TAXRATE" onBlur="this.form.TAX.value = (this.form.TAXRATE.value - 0) * (this.form.ITEM1TOTAL.value - 0) + (this.form.ITEM2TOTAL.value - 0) " Size="4"> In my TAX field I get...
4
by: JMCN | last post by:
Hello - This should be an easy function to multiple all amounts if they are negative values (< 0). however, i get an error message on the db.openrecordset because it assumes that i want to count...
2
by: k | last post by:
I have aproblem when multiplying 2 float 638.9 * 382.8 should = 244570.92 results giving 244570.922 both numbers are float variables , tried using double to...
3
by: Dave | last post by:
Hello I've created a student database for our program that I also need to get statistics from. It's in Access 2003. The statistics would be things like Male-Female percentage, percentage of...
32
by: cj | last post by:
When I'm inside a do while loop sometimes it's necessary to jump out of the loop using exit do. I'm also used to being able to jump back and begin the loop again. Not sure which language my...
2
by: John McMonagle | last post by:
Say I have a dictionary like below: d = {(100,500):, (100,501):, (100,502):} Say I want to multiply all the values of the dictionary by 2: for key in d.keys(): d = map(lambda x: x*2,...
3
by: damhotpepper | last post by:
How do I total 2 columns by multiplying their values together. Table Products, UnitQty x Unit Price ? Any help would be great.
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.