`{"id":"8173e310-ce3c-4fa6-9e4f-d591b907c444","name":"Power-linear","description":"1. You are given a number x.\r\n2. You are given another number n.\r\n3. You are required to calculate x raised to the power n. Don't change the signature of power function .\r\n\r\nNote -> The online judge can't force you to write the function recursively but that is what the spirit of question is. Write recursive and not iterative logic. The purpose of the question is to aid learning recursion and not test you.","inputFormat":"A number x\r\nA number n","outputFormat":"x raised to the power n","constraints":"1 &lt;= x &lt;= 10\r\n0 &lt;= n &lt;= 9","sampleCode":{"cpp":{"code":"#include<iostream>\r\nusing namespace std;\r\n\r\nint power(int x,int n){\r\n // write your code here\r\n\r\n}\r\n\r\n\r\nint main(){\r\n int n,x; cin>>x>>n;\r\n cout<<power(x,n);\r\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static void main(String[] args) throws Exception {\r\n // write your code here\r\n }\r\n\r\n public static int power(int x, int n){\r\n return 0;\r\n }\r\n\r\n}"},"python":{"code":"def powerLinear(x,n):\n # write your code here\n\n\nnum = int(input())\npower = int(input())\nprint(powerLinear(num,power))"}},"points":10,"difficulty":"easy","sampleInput":"2\r\n5","sampleOutput":"32","questionVideo":"https://www.youtube.com/embed/KYke5cn9jAk","hints":[],"associated":[{"id":"08371522-b324-4d27-9f9d-a54750bbc6e3","name":"(Power Linear) Do we have to keep x constant?","slug":"power-linear-do-we-have-to-keep-x-constant","type":4},{"id":"d04de03f-1e01-431f-bc16-da35f42a1b04","name":"(Power Linear) What is the output when x =2 and n=4?","slug":"power-linear-what-is-the-output-when-x-2-and-n-4","type":4}],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"d341a7c9-1269-409c-b851-0bb512289544","name":"Recursion And Backtracking For Beginners","slug":"recursion-and-backtracking-for-beginners","type":0},{"id":"c7f4bf63-b169-4a9b-8281-9d780357f275","name":"Power-linear","slug":"power-linear","type":1}],"next":{"id":"8ed5e886-1ee3-48af-8ec4-580c2fe09da4","name":"Power-logarithmic","type":1,"slug":"power-logarithmic"},"prev":{"id":"0ed561a5-3298-40cf-aeb3-99b55cdd90ef","name":"Factorial","type":3,"slug":"factorial"}}}`

# Power-linear

1. You are given a number x. 2. You are given another number n. 3. You are required to calculate x raised to the power n. Don't change the signature of power function . Note -> The online judge can't force you to write the function recursively but that is what the spirit of question is. Write recursive and not iterative logic. The purpose of the question is to aid learning recursion and not test you.

`{"id":"8173e310-ce3c-4fa6-9e4f-d591b907c444","name":"Power-linear","description":"1. You are given a number x.\r\n2. You are given another number n.\r\n3. You are required to calculate x raised to the power n. Don't change the signature of power function .\r\n\r\nNote -> The online judge can't force you to write the function recursively but that is what the spirit of question is. Write recursive and not iterative logic. The purpose of the question is to aid learning recursion and not test you.","inputFormat":"A number x\r\nA number n","outputFormat":"x raised to the power n","constraints":"1 &lt;= x &lt;= 10\r\n0 &lt;= n &lt;= 9","sampleCode":{"cpp":{"code":"#include<iostream>\r\nusing namespace std;\r\n\r\nint power(int x,int n){\r\n // write your code here\r\n\r\n}\r\n\r\n\r\nint main(){\r\n int n,x; cin>>x>>n;\r\n cout<<power(x,n);\r\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static void main(String[] args) throws Exception {\r\n // write your code here\r\n }\r\n\r\n public static int power(int x, int n){\r\n return 0;\r\n }\r\n\r\n}"},"python":{"code":"def powerLinear(x,n):\n # write your code here\n\n\nnum = int(input())\npower = int(input())\nprint(powerLinear(num,power))"}},"points":10,"difficulty":"easy","sampleInput":"2\r\n5","sampleOutput":"32","questionVideo":"https://www.youtube.com/embed/KYke5cn9jAk","hints":[],"associated":[{"id":"08371522-b324-4d27-9f9d-a54750bbc6e3","name":"(Power Linear) Do we have to keep x constant?","slug":"power-linear-do-we-have-to-keep-x-constant","type":4},{"id":"d04de03f-1e01-431f-bc16-da35f42a1b04","name":"(Power Linear) What is the output when x =2 and n=4?","slug":"power-linear-what-is-the-output-when-x-2-and-n-4","type":4}],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"d341a7c9-1269-409c-b851-0bb512289544","name":"Recursion And Backtracking For Beginners","slug":"recursion-and-backtracking-for-beginners","type":0},{"id":"c7f4bf63-b169-4a9b-8281-9d780357f275","name":"Power-linear","slug":"power-linear","type":1}],"next":{"id":"8ed5e886-1ee3-48af-8ec4-580c2fe09da4","name":"Power-logarithmic","type":1,"slug":"power-logarithmic"},"prev":{"id":"0ed561a5-3298-40cf-aeb3-99b55cdd90ef","name":"Factorial","type":3,"slug":"factorial"}}}` Editor

# Power-linear

easy

1. You are given a number x. 2. You are given another number n. 3. You are required to calculate x raised to the power n. Don't change the signature of power function . Note -> The online judge can't force you to write the function recursively but that is what the spirit of question is. Write recursive and not iterative logic. The purpose of the question is to aid learning recursion and not test you.

## Constraints

1 <= x <= 10 0 <= n <= 9

## Format

### Input

A number x A number n

### Output

x raised to the power n

## Example

Sample Input

```.css-23h8hz{color:inherit;font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;}2 5```

### Sample Output

`.css-3oaykw{color:var(--chakra-colors-active-primary);font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;font-family:Monospace;}32`

Question Video

Discussions

Show Discussion

Related Resources 