Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <conio.h>
- double exp1(int base, int power);
- void exp(int base, int power, int backup)
- {
- if (backup != 0)
- {
- exp1(base, power);
- exp(base, power, backup - 1);
- }
- }
- double exp1(int base, int power) //By incrementing
- {
- static double expo = 1;
- if (power != 0)
- {
- exp(base, power - 1, base);
- return expo += base - 1; //Debugging
- }
- return 1;
- }
- double exp2(int power, int base) //By multiplying
- {
- if (power == 0)
- return 1;
- return base * exp2(power - 1, base);
- }
- void main()
- {
- int base, power, choice;
- printf("Enter the base and power:\n");
- scanf("%d %d", &base, &power);
- redo:
- printf("1: Increment\n2: Multiply?\n");
- scanf("%d",&choice);
- switch (choice)
- {
- case 1:
- printf("%.0f", exp1(base, power));
- break;
- case 2:
- printf("%.0f", exp2(base, power));
- break;
- default:
- printf("INVALID CHOICE.\n\n");
- goto redo;
- }
- getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement