What will be the sum of the digits in the output of the C program given below.

#include <stdio.h>
#include <stdlib.h>
void A(int n)
{
    if(n==0)
    return;
    printf(\"%d\",n);
    B(--n);
    printf(\"%d\",n);
}

void B(int n)
{
    if(n==0)
    return;
    printf(\"%d\",n);
    A(--n);
}

int main(){
A(6);
return 0;
 }

(A) 654321135
(B) 65432112345
(C) 30
(D) 31


Answer: (C)

Explanation: \"\"

Output of above program is 654321135.

Therefore, sum of digits of given output is,

6+5+4+3+2+1+1+3+5 = 30 

So, option (C) is correct.


Quiz of this Question


  • Last Updated : 18 Dec, 2018

Share your thoughts in the comments