Thread: problem with printing elements of a array using recursion program

  1. #16
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    Quote Originally Posted by cooldude View Post
    i modified the code...but still iam not getting any output........the code was compiled and there are no errors.....
    Code:
    #include<stdio.h>
    void pa(int [],int,int);
     main()
    {
    int a[4]={10,20,30,40};
     pa(a,0,3);
    }
    void pa(int a[],int lb,int ub)
    {
           if(lb==ub)
           printf("%d",a[lb]);
           else
           {
               printf("%d",a[lb]);
               pa(a,lb+1,ub);
           }
    }
    Deleting the int before main did not change anything. Main still returns int, because the compiler assumes int as the return type if none is given. Further, main must return int, to be standard C. Therefore you need to put a return 0 at the end of main. (you can also return something else to tell the OS you got an error, or perhaps some useful information.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  2. #17
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    Quote Originally Posted by iMalc View Post
    write propper English.
    It's all for your own bennefit.
    lol.
    HOPE YOU UNDERSTAND.......

    By associating with wise people you will become wise yourself
    It's fine to celebrate success but it is more important to heed the lessons of failure
    We've got to put a lot of money into changing behavior


    PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
    IDE- Microsoft Visual Studio 2008 Express Edition

  3. #18
    Registered User
    Join Date
    Sep 2009
    Posts
    6
    Code:
    Hi,
    
    
    I compiled and runned your code with VC++6.0 and it went through just right! However, your code in the function void pa( int a[], int lb, int ub) is duplicated.
    
    void pa(int a[],int lb,int ub)
    {
           printf("%d",a[lb]);
           if(lb!=ub)
                pa(a,lb+1,ub);
    }
    
    
    Carle
    _____________________
    Free chat software for you

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  2. printing array elements in ascending order
    By galmca in forum C Programming
    Replies: 29
    Last Post: 10-24-2004, 11:24 PM
  3. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM
  4. problem with printing a structed array using for loop
    By Prezo in forum C++ Programming
    Replies: 2
    Last Post: 09-15-2002, 09:00 AM
  5. problem with 2d array program.
    By Niloc1 in forum C Programming
    Replies: 1
    Last Post: 04-08-2002, 05:47 PM