Coding help please. These three little things keep returning 0.0. What am I doing wrong with each?
PS: the stdio.h is there, but won't show up here because of the BBS codes.
---------------------
ONE
#include <stdio.h>
double fun_double(double, int);
void main(void)
{
double x;
int n;
printf("\n\n\nEnter a number, a space, and the power to raise the first number by: ");
scanf("%f %d", &x, &n);
printf("\nThe result is: %0.2f\n\n", fun_double(x, n) );
}
double fun_double(double x, int n)
{
int i = 0;
double y = 1.0;
for(i = 0; i < n; i++)
{
y *= x;
}
return (y);
}
------------------
TWO
#include <stdio.h>
double fun_double(double, int);
void main(void)
{
double x;
int n;
printf("\n\n\nEnter a number, a space, and the power to raise the first number by: ");
scanf("%f %d", &x, &n);
printf("\nThe result is: %0.2f\n\n", fun_double(x, n) );
}
double fun_double(double x, int n)
{
double z, y = 1.0;
z = x;
while(n)
{
if(n & 1)
{
y *= z;
}
z *= z;
n >>= 1;
}
return (y);
}
------------------
THREE
#include <stdio.h>
double powerfunction(int, int);
void main(void)
{
int base, power;
printf("\n\nEnter base, space, power, and hit ENTER: ");
scanf("%d %d", &base, &power);
printf("\n\nResults is: %d\n\n", powerfunction(base, power) );
}
double powerfunction(int base, int power)
{
int i;
double result = 1.0;
for(i = 0; i < power; i++)
{
result *= base;
}
return result;
}
PS: the stdio.h is there, but won't show up here because of the BBS codes.
---------------------
ONE
#include <stdio.h>
double fun_double(double, int);
void main(void)
{
double x;
int n;
printf("\n\n\nEnter a number, a space, and the power to raise the first number by: ");
scanf("%f %d", &x, &n);
printf("\nThe result is: %0.2f\n\n", fun_double(x, n) );
}
double fun_double(double x, int n)
{
int i = 0;
double y = 1.0;
for(i = 0; i < n; i++)
{
y *= x;
}
return (y);
}
------------------
TWO
#include <stdio.h>
double fun_double(double, int);
void main(void)
{
double x;
int n;
printf("\n\n\nEnter a number, a space, and the power to raise the first number by: ");
scanf("%f %d", &x, &n);
printf("\nThe result is: %0.2f\n\n", fun_double(x, n) );
}
double fun_double(double x, int n)
{
double z, y = 1.0;
z = x;
while(n)
{
if(n & 1)
{
y *= z;
}
z *= z;
n >>= 1;
}
return (y);
}
------------------
THREE
#include <stdio.h>
double powerfunction(int, int);
void main(void)
{
int base, power;
printf("\n\nEnter base, space, power, and hit ENTER: ");
scanf("%d %d", &base, &power);
printf("\n\nResults is: %d\n\n", powerfunction(base, power) );
}
double powerfunction(int base, int power)
{
int i;
double result = 1.0;
for(i = 0; i < power; i++)
{
result *= base;
}
return result;
}