|
|
Choosing A Webhost: |
Re: Mathmatical Question, Formula to multiply a number by smaller amounts?: msg#00192windows.devel.dotnet.cx
On Wed, 28 Sep 2005 14:35:08 -0700, Zeusbwr <zeusbwr@xxxxxxxxx> wrote: >double dMod = 1.05; // Modifier >double dNumber = 1; // Number i wish to modify > >for( int i = 0; i < 5; i++ ){ > > dNumber = dNumber * dMod; > Console.Writeline( "Here is your {0} number: {1}, i, dNumber ); > dMod = dMod * 0.95; > >} > > >Now what i want to do is exactly that, each iteration i want to >multiple a number by a ever smaller number. But the thing is, dMod >cant change. > >Would it be possible to accomplish what is done with that loop, >without modifying dMod? Well, if I understand you correctly you just need to use powers (which are essentially repeated multiplications, if the exponent is an integer). double dMod = 1.05; // Modifier double dNumber = 1; // Number i wish to modify for( int i = 0; i < 5; i++ ) { dNumber = dNumber * (dMod ^ (i + 1)); Console.Writeline( "Here is your {0} number: {1}, i, dNumber ); } So, you never modify dMod but you get the same results. My C++ is rusty so you need to look up the exact syntax for raising a number to an integer power. If I recall correctly C(++) has no built-in support for raising a number to a non-integer power but you don't need that. (You can work around that by using exp and ln anyway.) BTW, this is hugely off-topic. In the future you're better off asking such things in any newsgroup that has "math" in its name (e.g. comp.sci.math) HTH Sven =================================== This list is hosted by DevelopMentor® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: Mathmatical Question, Formula to multiply a number by smaller amounts?, phil paxton |
|---|---|
| Next by Date: | Re: Mathmatical Question, Formula to multiply a number by smaller amounts?, Zeusbwr |
| Previous by Thread: | Re: Mathmatical Question, Formula to multiply a number by smaller amounts?, phil paxton |
| Next by Thread: | Re: Mathmatical Question, Formula to multiply a number by smaller amounts?, Zeusbwr |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
Free MagazinesCisco NewsReceive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business. subscribe Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field. subscribe The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business. subscribe Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company. subscribe Total Telecom Total Telecom is "The Economist of the communications industry". subscribe |