Knowee
Questions
Features
Study Tools

Select the correct answerPredict the output of below given code in C.#include<stdio.h>void Function(int N){ if (N == 0)  return;  printf("%d", N%2); Function(N/2);} int main(){  int N=20;  Function(N);  return 0;}Options0110100101111110010000000

Question

Select the correct answerPredict the output of below given code in C.#include<stdio.h>void Function(int N){ if (N == 0)  return;  printf("%d", N%2); Function(N/2);} int main(){  int N=20;  Function(N);  return 0;}Options0110100101111110010000000

🧐 Not the exact question you are looking for?Go ask a question

Solution

The correct answer is 010100.

Here's the step by step explanation:

The given C code is a recursive function that prints the binary representation of a number.

  1. The function is called with N=20.
  2. It checks if N is 0, if not it prints the remainder of N divided by 2, which gives the last digit of the binary representation.
  3. Then it calls itself with N divided by 2, effectively removing the last digit of the binary representation.
  4. This process repeats until N becomes 0, at which point the function returns without printing anything.

The binary representation of 20 is 10100. However, because the function prints the digits in reverse order (it prints the remainder of N divided by 2 before making the recursive call), the output is the reverse of this, which is 010100.

This problem has been solved

Similar Questions

Select the correct answerPredict the output produced by below given code snippet in C.#include<stdio.h>void Function(char *S1, char *S2){ char *Buffer = S1; S1 = S2; S2 = Buffer;}    int main(){ char *S1 = "Code Tantra"; char *S2 = "Coding Castle"; Function(S1, S2); printf("%s,%s", S1, S2); return 0;}Optionschar *S1 = "Code Tantra"; char *S2 = "Coding Castle"; these statements throw segmentation faultThis code prints "Code Tantra,Coding Castle"This code prints "Code Tantra,Code Tantra"This code prints "Coding Castle,Code Tantra"Code throws compile time error

What will be the output of the following C code?

Select the correct answerWhich operator is used for the bitwise AND assignment in C?Options&=&&&&&=

Select the correct answerPredict the output of below given code.#include <stdio.h>int Function(char *S1){ char *S2 = S1; while(*++S1); return (S1-S2);} int main(){ char *Str = "CodeTantra Coding Castle"; printf("%d", Function(Str)); return 0;}Options2524Segmentation Fault26Garbage Value

What is the output of the following program?c = 4231for t in c:  print(t)Options42314 3 2Error4231

1/4

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.