How to programatically find if the code is recursive or iterative

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.


If a function calls itself (directly or indirectly) it's recursive.
That i know but is there a way to find it through code..
is there a way to find it through code.

What do you mean? What code?
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.
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.
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.
You could use static code analyzers to find out. Check out clang's static analyzers.
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.
So is there any program already wriiten for above solution
Topic archived. No new replies allowed.