#include<stdio.h>
int f(int,int);
int main()
{
printf("%d",f(20,1));
return 0;
}
int f(int n,int k)
{
if(n==0) return 0;
else if(n%2)return f(n/2,2*k)+k;
else return f(n/2,2*k)-k;
}
how this program is working and generating output as 9....?
Answer / kodam
n=20, k =1
if, else if false. so it will call
f(n/2,2*k)-k ==> f(10,2)-1
if, else if false
f(n/2,2*k)-k ==> f(5, 4)-2
if is false. else if is true
f(n/2,2*k)+k ==> f(2, 8)+4
if, else if false
f(n/2,2*k)-k ==> f(1, 16)-8
if is false. else if is true
f(n/2,2*k)+k ==> f(0, 32)+16
now n is zero.
output
------
-1-2+4-8+16 = 9
| Is This Answer Correct ? | 7 Yes | 0 No |
Reverse the part of the number which is present from position i to j. Print the new number.[without using the array] eg: num=789876 i=2 j=5 778986
What is meant by initialization and how we initialize a variable?
What is the meaning of this decleration? unsigned char (*pArray[10][10]); please reply.
how to multiply two number taking input as a string (considering sum and carry )
Does c have enums?
What is the difference between exit() and _exit()?
Write a program to enter the name and age. If age>28 then find salary categories. if age<28 then find that you are gaduate or not.
write a c program thal will find all sequences of length N that produce the sum is Zero, print all possible solutions?
Tell us two differences between new () and malloc ()?
What is f'n in math?
Print all the palindrome numbers.If a number is not palindrome make it one by attaching the reverse to it. eg:123 output:123321 (or) 12321
Can math operations be performed on a void pointer?