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

1) a. Compute n!! Write a program to compute n!! given that n!!=1.3.5.7…n if n i

ID: 3912893 • Letter: 1

Question

1)
a. Compute n!!
Write a program to compute n!! given that n!!=1.3.5.7…n if n is odd and
n!!=2.4.6.8…n if n is even
b. Compute Fibonacci sequences
Write a program to print Fibonacci sequences with the given value n, knowing that:
f0 = f1 = 1;
fn = fn-1 + fn-2
2) Write a Taxi meter program to calculate the taxi fare for a given mileage.
a. The 1st 2km is 15,000 VND
b. The next 250m will cost 2000
c. If the travel distance is larger than 30km then each extra km will cost only 5000VND
Allow user to input the travel distance in km and print the amount of money to be paid

Explanation / Answer

1(a)

//program to calculate n!!

#include<stdio.h>

int main(){

int num,fact=1,i;

printf("enter number : ");

scanf("%d",&num);

if(num%2){

for(i=1;i<=num;i+=2)

fact*=i;

}

else{

for(i=2;i<=num;i+=2)

fact*=i;

}

printf("%d!! : %d",num,fact);

return 0;

}

1(b)

//program to calculate fabonacci sequence

#include<stdio.h>

int main(){

int num,i;

printf("Enter number : ");

scanf("%d",&num);

int arr[num+1];

arr[0]=1;

arr[1]=1;

for(i=2;i<=num;i++)

arr[i]=arr[i-1]+arr[i-2];

printf("Fabonacci sequence : ");

for(i=0;i<=num;i++)printf("%d ",arr[i]);

}

2)

//program to calculate fare

#include<stdio.h>

int main(){

int distance,cost=15000,num,value;

printf("Enter distance in km : ");

scanf("%d",&distance);

num=distance;

distance=distance-2;

if(distance>0){

if(distance<=28)

cost=cost+distance*8000;

else{

cost=cost+28*8000;

distance=distance-28;

cost=cost+distance*5000;

}

}

if (num<=0)cost=0;

printf("Total fare of %d km : %d",num,cost);

}