A weird output ? : I am new to the C.Sc course and we are taught C program. 

I was trying some of the basic stuff. Currently I am learning User-Defined-Function. 

The following code is the one I was trying with. I know it is pretty simple but I am not able to understand why it is producing such weird output.


    #include <stdio.h>
    
    int add(int a); //function declaration
    
    int main (void)
    
    {
    	int b,sum;
    	printf("\nEnter a number: ");
    	scanf("%d", &b);
    
    	sum = add(b); //function calling
    
    	printf("\nSum: %d\n\n", sum);
    
    }
    
    int add(int a) //function definition	
    
    {
    	int result;
    	for(int i = 0; i < a; i++)
    	
    	{
    		result = result + i;
    		return result;
    
    	}
    
    	
    } 


The output for 1 is 32743

The output for 2 is 32594

The output for 3 is 32704

The weird thing is output change each time for the same number. 

It's just weird considering my experience in C.Sc. till date. Kindly explain what the program is doing.

**This is the right place to post problems like this. Right ?** 

 