Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #include <math.h>
- int subtract(int num);
- int power(int frstdigit, int thrddigit);
- void random();
- void randomtwo();
- void random()
- {
- srand(time_t(NULL));
- int num = (100 + rand() % (999 - 100 + 1));
- printf("%d\n", num);
- int third = num % 10;
- int first = (num / 10) / 10;
- int result = power(first, third);
- printf("%d", result);
- randomtwo();
- }
- int power(int frstdigit, int thrddigit)
- {
- if (thrddigit == 0)
- return 1;
- else
- return frstdigit * power(frstdigit, thrddigit - 1);
- }
- void randomtwo()
- {
- srand(time_t(NULL));
- int rando = (10000 + rand() % (99999 - 10000 + 1));
- printf("\n5 digit rando %d\n", rando);
- int result = subtract(rando);
- printf("\n%d\n", result);
- }
- int subtract(int num)
- {
- if (num < 10)
- return num;
- int leftMostDigit = num % 10;
- int remainingNumber = num / 10;
- int result = leftMostDigit - subtract(remainingNumber);
- if (result < 0)
- result *= -1;
- return result;
- }
- int main() {
- random();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement