C Programming - Functions - Discussion

Discussion Forum : Functions - Find Output of Program (Q.No. 6)
6.
What will be the output of the program?
#include<stdio.h>
int sumdig(int);
int main()
{
    int a, b;
    a = sumdig(123);
    b = sumdig(123);
    printf("%d, %d\n", a, b);
    return 0;
}
int sumdig(int n)
{
    int s, d;
    if(n!=0)
    {
        d = n%10;
        n = n/10;
        s = d+sumdig(n);
    }
    else
        return 0;
    return s;
}
4, 4
3, 3
6, 6
12, 12
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
51 comments Page 5 of 6.

Aakanksha said:   1 decade ago
Can anybody give me full execution of this program ?

Sowmya said:   1 decade ago
@Hagesh

Can you explain this in clear way?

Amisha aggarwal said:   9 years ago
Super @Vivek, your approach is nice.

Hakesh said:   7 years ago
What to do with return 0 statement?

Siva said:   9 years ago
Good explanation @Taher Ali.

Debjani said:   6 years ago
Why the value of b is 6?
(2)

Deepak Johnson said:   6 years ago
Why the value of b is 6?

Trupti said:   9 years ago
Good explanation @Vivek.

Sandeep said:   1 decade ago
Vivek explained nice.

Satyanarayana said:   1 decade ago
Very nice vivek.


Post your comments here:

Your comments will be displayed after verification.