You are on page 1of 2

#include <stdio.

h>
#include <stdlib.h>

int main()
{
int choice_num, repick;

printf("Press 1 if you wish to perform basic calculation.\n");


printf("Press 2 if you wish to print Fibonacci series.\n");
printf("Press 3 if you wish to calculate the factorial of a number.\n\n");

do
{
printf("Select from the following options the calculation you wish to
execute.\n");
printf("Please enter your choice:");
scanf("%d",&choice_num);
printf("\n");

switch (choice_num)
{
case 1:
{
double first_num, second_num, sum, difference, product,
quotient;
printf("This is a program that perform basic
calculation.\n");
printf("Please enter the first number:");
scanf("%lf", &first_num);
printf("Please enter the second number:");
scanf("%lf", &second_num);

sum = first_num+second_num;
difference = first_num-second_num;
product = first_num*second_num;
printf("\n");
printf("Results:\n");
printf("Sum = %lf \n", sum);
printf("Difference = %lf \n", difference);
printf("Product = %lf \n", product);
if (second_num == 0)
printf("Quotient is Undefined. Division of Zero is not
allowed.\n\n");
else
{
quotient = first_num/second_num;
printf("Quotient = %lf \n\n", quotient);
}
}
break;
case 2:
{
int i, n, t1 = 0, t2 = 1, next_term;
printf("This is a program that print Fibonacci series.\n");
printf("Enter the number of terms:");
scanf("%d", &n);
printf("Fibonacci Series:");

for (i = 1; i <= n; i++)


{
printf("%d, ", t1);
next_term = t1 + t2;
t1 = t2;
t2 = next_term;
}
printf ("\n\n");
}
break;
case 3:
{
int i,fact = 1,n;
printf("This is a program that calculate the factorial of a
number.\n");
printf("Please enter an integer value for n:");
scanf("%d",&n);
for(i = 1; i <= n ; i++)
{
fact = fact * i;
}
printf("Factorial of %d is: %d\n\n", n, fact);

}
break;
default:
printf("Please re-enter your choice again.\n\n");
break;

}
printf("If you wish to perform again,\n");
printf("Press 1 if Yes\n");
printf("Press 2 if No\n");
printf("Answer:");
scanf("%d",&repick);
printf("\n");
}

while (repick == 1);

printf("End of Program.\n");
printf("Bye!");
return 0;
}

You might also like