The fact that you don't want to do 5*3*3, but rather 5*5*5, to get five cubed. You don't multiply by the exponent, but by the base.
This is a discussion on Newbie help with expontential program within the C Programming forums, part of the General Programming Boards category; The fact that you don't want to do 5*3*3, but rather 5*5*5, to get five cubed. You don't multiply by ...
The fact that you don't want to do 5*3*3, but rather 5*5*5, to get five cubed. You don't multiply by the exponent, but by the base.
I understand that 5 ^ 3 = 5 * 5 * 5.
I don't know how to tell C that 5 * 5 *5 is.
multiples by the exponent. To multiply by the base, you need to multiply by the base:Code:base *= exp;
EDIT: And of course I mean result *= base, not base *= base.Code:base *= base;
Last edited by tabstop; 06-11-2008 at 06:53 PM.
If I say
base = exp won't it override by value for scanf in the for statement?
Not in the for statement in the
below the for statementCode:{ }
That created an infitite loop. It won't stop. What the heck?
I need a for statement based on the exponent to make it stop?
That is pretty cool though.Code:#include <stdio.h> 2 3 int main(void) 4 { 5 float base, exp, product, a; 6 double result; 7 8 9 10 11 12 13 printf("Enter base\n"); 14 scanf("%f",&base); 15 printf("Enter exponent\n"); 16 scanf("%f",&exp); 17 18 printf("The exponent is %f\n",exp); 19 printf("The base is %f\n",base); 20 result = 0; 21 product = 1; 22 for( a = 1; a <= base; a++) 23 { 24 25 base *= base; 26 printf("The exponent is %f\n",exp); 27 printf("The base is %f\n",base); 28 29 30 printf("The variable A is equal to %f\n",a); 31 32 33 34 result = base * exp; 35 printf("Result is %f\n",result); 36 if ( 0 == product - base) 37 return base; 38 39 } 40 41 return 0; 42 }
Where does exponent come into play?Code:for( a = 1; a <= base; a++) 23 { 24 25 base *= base;
I entered 5^3 and it just keeps crawling at 100 mph.
I changed base from exp in the for statment and added
line 25
Do I need two four loops for this?
Thanks tabstop,
Drop me a line on the instant messages with a paypal account and I will send you a little something for your trouble. Apprciate the help man. Now if I can just code this in my larger program I should be in business.
I mean the private messages. Everyone needs a little help with gas these days.