• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest Dec 6th, 2018 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #include <stdio.h>
2. int powerOfNum(int base, int exponent);
5.
7. {
8.   if (number != 0)
9.   {
10.     return (number % 10 + recursiveAdd(number/10));
11.   }
12.   else
13.   {
14.     return 0;
15.   }
16. }
17.
18. int powerOfNum(int base, int exponent)
19. {
20.   if(exponent == 0)
21.   {
22.     return 1;
23.   }
24.   if(exponent == 1)
25.   {
26.     return base;
27.   }
28.   else
29.   {
30.     return base * powerOfNum(base, exponent-1);
31.   }
32. }
33.
35. {
37.   printf("%s\n%s\n%s\n\n", "(1) Add the digits of an integer together","(2) Find the power of a number","(3) Quit");
38.   return 0;
39. }
40.
41. int main (void)
42. {
43.   char input = '0';
46.   int baseNum;
47.   int exponentNum;
48.   int powerResult;
49.
50.   int quitLoop = 0;
51.
52.   printf("%s%s\n\n","To select a menu option, type the number that corresponds to that option.","\nEx: Type '2' to find the power of a number");
54.
55.   while (quitLoop == 0)
56.   {
57.     scanf("%c", &input);
58.
59.     if(input == '1')
60.     {
63.
65.
67.
69.     }
70.     if (input == '2')
71.     {
72.       printf("\n%s\n", "Please enter a base number:");
73.       scanf("%d", &baseNum);
74.
75.       printf("%s\n", "Please enter an exponent:");
76.       scanf("%d", &exponentNum);
77.
78.       powerResult = powerOfNum(baseNum, exponentNum);
79.
80.       printf("\nThe number %d to the power of %d is %d\n\n", baseNum, exponentNum, powerResult);
82.
83.     }
84.     if (input == '3')
85.     {
86.       quitLoop = 1;
87.       printf("%s\n", "Goodbye!");
88.     }
89.   }
90.   return 0;
91. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top