Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Write a program that calculates the nth fibanocci number. The equation for th

ID: 643861 • Letter: 1

Question

1. Write a program that calculates the nth fibanocci

number. The equation for the Fibonacci numbers is defined as follows:

Fib(0)=0

Fib(1)=1

Fib(N)=Fib(N?1)+Fib(N?2)

Your program should accept N as a command line argument

You MUST solve this program RECURSIVELY

Unlike the example in class, you may only have ONE RECURSIVE CALL in your function

1. Hint pointers help make this possible.

Examples

1../fib.out 0
The 0th fibanocci number is 0.

2../fib.out 1
The 1th fibanocci number is 1.

3../fib.out 10
The 10th fibanocci number is 55.

2.
binary number is made up of 0's and 1's but the input strings you will receive can also contain 'x''s. An x represents a digit that can be either a 0 or a 1. Your program should display all the possible binary digits that can be formed. For example the string x1x0 could represent either 0100, 0110, 1100, or 1110.

Your program should accept the binary string as a command line argument

You MUST solve this program RECURISIVELY

Examples

1../bin_str.out 0110

0110

2../bin_str.out 01x0

0100

0110

3../bin_str.out xx

00

01

10

11

4 ../bin_str.out 101x100x11x 10101000110

10101000110
10101000111
10101001110

Explanation / Answer

#include
#include


int findFibo(int n);
main()
{
int n,result;

printf("Enter the Nth Number to find Fibonacci of:");
scanf("%d",&n);

result=findFibo(n);
printf("Fibonacci of the %d th Number is :%d",n,result);

getch();
return 0;
}

int findFibo(int n)
{
if ( n == 0 )
return 0;
else if ( n == 1 )
return 1;
else
return ( findFibo(n-1) + findFibo(n-2) );
}

2.

#include
#include

char* convertString(char *c,int len);
int main(int argc,char *argv[])
{
int i,length;
char *cs;
printf("Program Name %s ",argv[0]);
if(argc!=1)
{
printf("The String :%s",argv[1]);
}

length=strlen(argv[1]);

cs=convertString(argv[1],length);

for(i=0;i printf("%c",cs[i]);

getch();
return 0;
}

char* convertString(char *c,int len)
{
char* newchar,newchar1;
int i,count=0;

printf(" ");

for(i=0;i {
if(c[i]=='0'||c[i]=='1')
{
newchar[i]=c[i];
}
if(c[i]=='x')
{
if(count==0)
{
newchar[i]='0';
}
if(count==1)
{
newchar[i]='1';
}
}
}
printf(" ");
for(i=0;i {
printf("%c",newchar[i]);
}
count++;

if(count==1)
return(convertString(c,len));

return newchar;
}