code to explanationWed, 07 Dec 2022

int main() { int n, i, p = 0, q = 1, r, *a, *x, *y, *z; scanf("%d", &n); a = &n; x = &p; y = &q; z = &r; if(*a == 0) printf("\n"); else if(*a == 1) printf("0\n"); else if(*a == 2) printf("1\n"); else if(*a>=3) { for(i=3; i<=*a; i++) { *z = *x + *y; *x = *y; *y = *z; } printf("%d\n", *z); } return 0; }

n is the number of fibonacci numbers to be printed. The pointer a is assigned the address of n. The pointers x and y are assigned the address of p and q. The pointer z is assigned the address of r. The algorithm goes on to check if n equals 0, 1 or 2 and then prints the corresponding output. If the value of n is greater than or equal to 3, the loop runs and goes on to print the nth fibonacci number.

Questions about programming?Chat with your personal AI assistant