+ 4
What's going on....
How the below code yields 2011 as it's output since I got 1011 only.... #include <stdio.h> int recur(int num) { if((num/2) !=0) return recur(num/2)*10+num%2; } int main() { int i=11; printf("%d",recur(i)); return 0; } https://code.sololearn.com/ciOTa10WPp2g/?ref=app
7 Antworten
+ 3
The recursive function is missing a base case. There's nothing returned when the `if` onditional evaluates to false.
Add this under the `if` block
return num;
+ 2
Ipang Thank you for your concern
+ 1
Recursion is quite a complex subject. I still find it difficult to explain. Someone will eventually.
0
Ipang then how it will be 2011
0
Why do you expect 2011? The question is not “how to change the code to produce specific output”. The question is “what I’m trying to achieve and how to change the code to cover it”.
0
JayV okay then can you explain how the output will be 2011
- 1
Write the Python code of a program that reads an integer, and prints the integer it is a multiple of
either 2 or 5 but not both. If the number is a multiple of 2 and 5 both, then print "Multiple of 2 and 5 both". For all other numbers, the program prints "Not a multiple we want". For example, 2, 4, 5, 6, 8, 12, 14, 15, 16, 18, 22... ie. this includes multiples of 2 only and multiples of 5 only, NOT multiples of 2 and 5 both or other numbers
hint: we may use the modulus (6) operator for checking the divisibility
hin(2): we can consider the number to be an integer
Sample Input 1:
6
Sample Output 1:
6
Sample Input 2:
15
Sample Output 2:
15
Sample Input 3:
10
Sample Output 3:
Multiple of 2 and 5 both
Sample Input 4:
17
Sample Output 4:
Not a multiple we want
Can any one hlp me with this???