How to programatically find if the code is recursive or iterative

Apr 8, 2014 at 7:07am
Is there any way to programatically find if the given code is taking recursive
approach or iterative apporaoch using concept of files in C programming.


Apr 8, 2014 at 8:27am
If a function calls itself (directly or indirectly) it's recursive.
Apr 8, 2014 at 8:52am
That i know but is there a way to find it through code..
Apr 8, 2014 at 8:55am
is there a way to find it through code.

What do you mean? What code?
Apr 8, 2014 at 9:06am
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <stdio.h>
int sum(int n);
int main(){
    int num,add;
    printf("Enter a positive integer:\n");
    scanf("%d",&num);
    add=sum(num);
    printf("sum=%d",add);
}
int sum(int n){
    if(n==0)
       return n;
    else
       return n+sum(n-1);    /*self call  to function sum() */
}


I know this code is using recursive approach..

But are there programs or tools that could find if the program submitted in .txt file is using recursive approach or iterative approach.
Apr 8, 2014 at 11:39am
I thought you wanted to write tool to detect recursion, I guess that is not the case.

are there programs or tools that could find if the program ... is using recursive approach or iterative approach.
Probably, I don't think that on it's own is particularly useful. There may be some tool that does this as part of some larger analysis. But I don't know of any.
Apr 9, 2014 at 4:59am
Yes thats d case i wanna detect whether the program is using recursive approach or not, i guess we need to create call graphs for it.
Apr 9, 2014 at 5:32pm
You could use static code analyzers to find out. Check out clang's static analyzers.
Apr 10, 2014 at 10:37am
Or you could create a stack call...

Like list the functions you already know and have already been called
And if one function is being re-called

Then it's a recursive.

With this approach you might also know how many times a functions has been called within a stack.
Apr 11, 2014 at 7:00am
So is there any program already wriiten for above solution
Apr 12, 2014 at 10:35pm
Topic archived. No new replies allowed.