i need a code for 2^n and suppose user enter n = 4 , so the output will be 16 . Now whatever output we will get i need sum of numbers in that output e.g here we have 16
i.e 1 + 6 = 7 . plz help me with code

i need a code for 2^n and suppose user enter n = 4 , so the output will be 16 . Now whatever output we will get i need sum of numbers in that output e.g here we have 16
i.e 1 + 6 = 7 . plz help me with code

declare an int ans=1 and another n take input from user in this variable declare a for loop from 0 to n and take ans=ans*2 in the loop this will give you 2^n.and u can use %operator to separate all digits of calculated ans by dividing it with power of 10 .

declare an int ans=1 and another n take input from user in this variable declare a for loop from 0 to n and take ans=ans*2 in the loop this will give you 2^n.and u can use %operator to separate all digits of calculated ans by dividing it with power of 10 .

No. We to not write homework programs for people. That's your job as the student. We can help you when you get stuck, but based on your posts, you aren't stuck since there's no attempt to solve the problem.

(1 << 4) shifts 1 four times. You start out with 0b1 then you get 0b10 then 0b100 then 0b1000 then 0b10000. You started with 1 (decimal) and ended with 0b10000 in binary and 16 in decimal. 2^4 = 16.

Here's an example of it in use:

int n;
for (n = 0; n <= 10; n++) {
printf("n = %d; 2^n = %d\n", n, (1 << n));
}

Result:

n = 0; 2^n = 1
n = 1; 2^n = 2
n = 2; 2^n = 4
n = 3; 2^n = 8
n = 4; 2^n = 16
n = 5; 2^n = 32
n = 6; 2^n = 64
n = 7; 2^n = 128
n = 8; 2^n = 256
n = 9; 2^n = 512
n = 10; 2^n = 1024

In this assignment you are to write a program that finds a path through a “maze”. The maze will be represented by a 2-dimensional array of ints. You will be ...