Guys,
I have been working on this for two days. I think I need to say
base = exp somewhere but if I do it after the scanf it going to override the scanf will it not. If I do it before the scanf, the scanf will override the values. Needless to say I am thoroughly confused.
Code:
#include <stdio.h>
2
3 int main(void)
4 {
5 float base, exp, product, a;
6 double result;
7
8
9
10
11 printf("Enter base\n");
12 scanf("%f",&base);
13 printf("Enter exponent\n");
14 scanf("%f",&exp);
15
16 printf("The exponent is %f\n",exp);
17 printf("The base is %f\n",base);
18 result = 0;
19 product = 1;
20 for( a = 1; a <= exp; a++)
21 {
22 product *= exp;
23 printf("The product is %f\n",product);
24
25
26 printf("The variable A is equal to %f\n",a);
27
28
29
30 result = base * product;
31 printf("Result is %f\n",result);
32 if ( 0 == product - base)
33 return base;
34
35 }
36
37 return 0;
38 }
The exponent is 3.000000
The base is 5.000000
The product is 3.000000
The variable A is equal to 1.000000
Result is 15.000000
The product is 9.000000
The variable A is equal to 2.000000
Result is 45.000000
The product is 27.000000
The variable A is equal to 3.000000
Result is 135.000000