-
Help Me?
I need to use the pow() function here so that m and n are integers and n in nonegative, the cal pow(m,n) returns m raised to the nth power: I need to use the following code:
product = 1;
for (i = 1; i< = n; ++i)
prooduct *= m;
Here is what i have come up with so far. Can anyone get get me to solve this problem, please.
#include<stdio.h>
#include<math.h>
int main(void)
{
double m, n, i, product;
printf("\n%s\n%s\n%s\n\n",
"Input m as a positive integer and n as a negative integer.",
"The square root of m and n raised",
"to the n power will now be computed.");
while (0)
scanf("%lf", &n);
product = 1;
for (i = 1; i <= n; ++i)
product *= m;
printf("\n%lf", m);
return 0;
}
:eek:
-
Could you describe your problem more clearly, I'm having trouble parsing it. And consider your thread titles more carefully; "help me" just doesn't cut it.
-Prelude
-
Perlude to a kiss!
And i thought you were one with the universe. I practically wrote the whole book out for everyone to see my problem but as said said sarcastically with a s -n- m tone. Help me just dont cut it.
later prelude
;)
-
>And i thought you were one with the universe.
Only in my mind. ;)
>I practically wrote the whole book out for everyone to see my problem
Then I'll need clarification. Are you supposed to write your own power function or use the standard library pow in math.h? Assuming the user is supposed to enter two integers, one for the value and one for the power, and you need to do the calculations without calling the standard pow, your function may look like this:
Code:
static double power ( int m, int n )
{
double product = 1.0;
while ( n-- > 0 )
product *= m;
return product;
}
That way you simply take the input and then call power with it.
-Prelude
-
I am suppose to use the library <math.h> and from there write a simple program that does as stated above.
This stuff is tough and i am not even a computer science major.
WOWSER!
:p
-
I understand now, I just needed it drilled into my head a bit. ;) I suppose it should be something like this:
Code:
#include <stdio.h>
#include <math.h>
static double power ( int m, int n )
{
double product = 1.0;
while ( n-- > 0 )
product *= m;
return product;
}
int main ( void )
{
int m, n;
printf ( "Input m as a positive integer and n as a negative integer: " );
if ( scanf ( "%d %d", &m, &n ) == 2 ) {
printf ( "The square root of m and n raised to the "
"n power will now be computed.\n" );
printf ( "%f\n", sqrt ( power ( m, n ) ) );
}
return 0;
}
-Prelude