+ Reply to Thread
Results 1 to 4 of 4

Thread: Write output of given program

  1. #1
    TopGun Guest

    Write output of given program

    Code:
    int x=1234;
    int y = func(x);
    
    
    int func(int x)
    {
    	int j;
    	if (x <10)
    		return x;
    	else {
    		j = x%10 + func(x/10);
    		printf("%d",j);
    	}
    }

  2. #2
    jalajb2k7 Guest
    it outputs the sum of digits

  3. #3
    ashishsachdeva is offline Junior Member
    Join Date
    Mar 2011
    Posts
    3
    since there is no statement like return j; in the else part of func, hence 3 is printed first and then 2 random numbers after that...
    if the else part is like :
    else {
    j = x%10 + func(x/10);
    printf("%d",j);
    return j;
    }

  4. #4
    ashishsachdeva is offline Junior Member
    Join Date
    Mar 2011
    Posts
    3
    then the ouptut is:
    3610

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Output of given code
    By Surfer in forum Bloomberg
    Replies: 0
    Last Post: 26th May 2010, 23:24
  2. Output of the program
    By Surfer in forum C++ Fundamentals
    Replies: 1
    Last Post: 23rd April 2010, 11:38
  3. Replies: 0
    Last Post: 22nd September 2009, 11:59

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts