c - Calling a function within a loop -


i trying simple addition function take number x array , add variable i it, iteration variable inside loop. instead of adding each variable individually , producing output of :

3, 2, 7

it produces values of

3, 5, 13.

#include <stdio.h> int add(int x[], int y); int main(void) {     int i;     int a[3] = {3, 1, 5};     for(i=0; i<3; i++)     {         printf("%d \t", i);         printf("%d, %d, equals %d \n", a[i], i,  add(a[i], i));     }     return 0; } int add(int x[], int y){     return x+y; } 

try

int add(int x, int y){     return x+y; } 

Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

c# - MSDN OneNote Api: Navigate to never before opened page without opening a OneNote Application Window -