function - Make a program that calculates the sum of the first 20 Fibonacci numbers -


i need write program has sum of first 20 fibonacci numbers. using 2 functions summon size , sum of 20 numbers. have far.

#include <stdio.h> int main( ) {     int fib[20] = {0,1};         int *fib_ptr = &fib[2];       for(int = 0; < 20; i++){         *fib_ptr = *(fib_ptr - 1) + *(fib_ptr - 2);         fib_ptr++;      }     for(int x = 0; < 20; x++)         printf(“%4d”, fib[x]);     printf(“\n”);     return 0; } 

i know makes fibonacci numbers , not sum.

instead of printf @ end, add numbers when looping through @ end.

sum += fib[x] 

Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -