C programming questions 7-9 What is wrong in the following C function? (selectin
ID: 3775090 • Letter: C
Question
C programming questions 7-9
What is wrong in the following C function? (selecting the wrong answer deducts 20%) int[] fillArray(int n, int* pval){int a[n]; int j; scan f("%d", pval); for (j = 0; j1, f(i) = f(i - 1) + f(i - 2). The first 10 numbers from the series are 0, 1, 1, 2, 3, 5, 8, 13, 21, 34. Thus, f(0) = 0, f(1) = 1, f(3) = 2, etc. Write in the text box below a function called fib that returns void and that takes as parameters an array v of type int and an integer n that indicates the length of array v of type int and an integer n that indicates the length of array v. This function computes each Fibonacci number f(i) and saves it to array element v[1], for = 0Explanation / Answer
7 )Answer: a function in c cannot return a array..
8)Answer:- inc(&scores[2])
9)Answer:
#include<stdio.h>
void fib(int v[],int n)
{
int i=0;
if(n>2)
{
v[0]=0;
v[1]=1;
for(i=2;i<n;i++)
{
v[i]=v[i-1]+v[i-2];
}
}
else if(n>0&&n<=2)
{
int k=0;
while(n>0)
{ v[k]=k++;
n=n-1;
}
}
else
{
printf(" Error:--Array size should not be empty.. ");
}
}
int main()
{
int n=100,i=0;
int a[n];
printf("Fibonocci numbers:- ");
fib(a,n);
for(i=0;i<n;i++)
{
printf("Fib[%d]:%d ",i,a[i]);
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.