0% found this document useful (0 votes)
57 views23 pages

Database Management

The document describes a C program for a calculator app with 7 functions: addition, subtraction, multiplication, division, present value, future value, and net present value. It includes the algorithms for each function and the full C code to build the calculator.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views23 pages

Database Management

The document describes a C program for a calculator app with 7 functions: addition, subtraction, multiplication, division, present value, future value, and net present value. It includes the algorithms for each function and the full C code to build the calculator.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 23

C PROGRAM TO DESIGN CALCULATOR

Course Name: Introduction to Programming and Database Management


Course Code: ACT 2203

Prepared by:
Greg Anindya Talukder
Roll: 17211042
Section: B
Department of Accounting and Information Systems
Session: 2016-17

Prepared for:
Mohammod Akbar Kabir
Associate Professor
Adjunct Faculty
Faculty of Business Studies
Bangladesh University of Professionals

Date of Submission:
29th October, 2018
Problem statement
To make a calculator using C programming. To solve this problem I used C
programming language. In my calculator I included seven functions, which are-
Addition, Subtraction, Multiplication, Division, Present Value, Future Value and
Net Present Value.

Algorithm
ADDITION
1. Start

2. Input two number (a,b)

3. Sum=a+b

4. Print result

5. End

SUBTRACTION
1. Start

2. Input two number (a,b)

3. Sub=a-b

4. Print result

5. End
MULTIPLICATION
1. Start

2. Input two number (a,b)

3. Sub=a*b

4. Print result

5. End

DIVISION
1. Start

2. Input two number (a,b)

3. D=a/b

4. Print result

5. End

Present value
1. Start

2. Input initial cash inflow, interest rate, time (n)

3. PV=c1/(1+interest rate)n

4. Print result

5. End
Future value
1. Start

2. Input cash flow, Interest rate, time

3. FV = C0 *(1+interest rate)n

4. Print result

5. End

Net Present value


1. Start

2. Input c0

3. Input time (t)

4. Input cash flow for each year & save in c[t], interest (I)

5. NPV=∑co/(1+i)n -NCO

7. NPV= total-C0

8. Print result

9. End
C programming code for making a
calculator
#include <stdio.h>

#include <stdlib.h>

#include<math.h>

int main()

int menu,t; //Variable for the number the user inputs

float num1, num2, result, c1,r,n,e,power,pv,c0;; //Float variables for the user
input and output, used floats in case the user enters e.g. 14.7

printf("Enter a number from the list below\n\n");

printf("1. Addition\n");

printf("2. Subtraction\n");

printf("3. Multiplication\n");

printf("4. Division\n");

printf("5. pv\n");

printf("6. fv\n");

printf("7. npv\n\n");
printf("Enter number: "); //User input for the calculator menu

scanf("%d", &menu);

printf("\n");

switch(menu) //switch statement for menu

case 1:

printf("You entered Addition\n\n");

printf("Enter first number: "); //User input for first number

scanf("%f", &num1);

printf("Enter second number: "); //User input for second number

scanf("%f", &num2);

printf("%.2f + %.2f = %.2f\n", num1, num2, result); //Addition output

break;

case 2:

printf("You entered Subtraction\n\n");


printf("Enter first number: "); //User input for first number

scanf("%f", &num1);

printf("Enter second number: "); //User input for second number

scanf("%f", &num2);

printf("\n");

result = num1 - num2; //Subtraction calculation

printf("%.2f - %.2f = %.2f\n", num1, num2, result); //Subtraction output

break;

case 3:

printf("You entered Multiplication\n\n");

printf("Enter first number: "); //User input for first number

scanf("%f", &num1);

printf("Enter second number: "); //User input for second number

scanf("%f", &num2);

printf("\n");
result = num1 * num2; //Multiplication calculation

printf("%.2f * %.2f = %.2f\n", num1, num2, result); //Multiplication Output

break;

case 4:

printf("You entered Division\n\n");

printf("Enter first number: "); //User input for first number

scanf("%f", &num1);

printf("Enter second number: "); //User input for first number

scanf("%f", &num2);

printf("\n");

result = num1 / num2; //Division calculation

printf("%.2f / %.2f = %.2f\n", num1, num2, result);

break;

case 5:
printf("You entered pv\n\n");

printf("\nEnter the value of C1 : ");

scanf("%f",&c1);

printf("\nEnter the value of interest rate : ");

scanf("%f",&r);

printf("\nEnter the value of number of periods : ");

scanf("%f",&n);

e=1+r;

power=pow(e,n);

pv=c1/power;

printf("\nThe result is : %.2f\n",pv);

pv=0;

break;

case 6:

printf("You entered fv\n\n");

printf("\nEnter the value of C0 : ");

scanf("%f",&c1);

printf("\nEnter the value of interest rate : ");

scanf("%f",&r);

printf("\nEnter the value of number of periods : ");

scanf("%f",&n);

e=1+r;
power=pow(e,n);

pv=c1*power;

printf("\nThe result is : %.2f\n",pv);

pv=0;

break;

case 7:

printf("You entered npv\n\n");

printf("\n Enter C0 : ");

scanf("%f",&c0);

printf("\n Enter year : ");

scanf("%d",&t);

//t=t+1;

int i;

float C[t], alpha[t],total=0,npv;

for(i=0; i<t; i++)

printf("%d year cash flow : ",i+1);

scanf("%f",&C[i]);

printf("\nEnter the value of interest rate : ");

scanf("%f",&r);

r=r/100;
e=1+r;

for(i=0; i<t; i++)

power=pow(e,i+1);

alpha[i]=C[i]/power;

for(i=0; i<t; i++)

total=total+alpha[i];

npv= total-c0;

printf("\nThe result is : %.2f\n",npv);

npv=0;

break;

return 0;

printf("\n");

result = num1 + num2; //Addition calculation

printf("%.2f + %.2f = %.2f\n", num1, num2, result); //Addition output


break;

case 2:

printf("You entered Subtraction\n\n");

printf("Enter first number: "); //User input for first number

scanf("%f", &num1);

printf("Enter second number: "); //User input for second number

scanf("%f", &num2);

printf("\n");

result = num1 - num2; //Subtraction calculation

printf("%.2f - %.2f = %.2f\n", num1, num2, result); //Subtraction output

break;

case 3:

printf("You entered Multiplication\n\n");

printf("Enter first number: "); //User input for first number

scanf("%f", &num1);
printf("Enter second number: "); //User input for second number

scanf("%f", &num2);

printf("\n");

result = num1 * num2; //Multiplication calculation

printf("%.2f * %.2f = %.2f\n", num1, num2, result); //Multiplication Output

break;

case 4:

printf("You entered Division\n\n");

printf("Enter first number: "); //User input for first number

scanf("%f", &num1);

printf("Enter second number: "); //User input for first number

scanf("%f", &num2);

printf("\n");

result = num1 / num2; //Division calculation


printf("%.2f / %.2f = %.2f\n", num1, num2, result);

break;

case 5:

printf("You entered pv\n\n");

printf("\nEnter the value of C1 : ");

scanf("%f",&c1);

printf("\nEnter the value of interest rate : ");

scanf("%f",&r);

printf("\nEnter the value of number of periods : ");

scanf("%f",&n);

e=1+r;

power=pow(e,n);

pv=c1/power;

printf("\nThe result is : %.2f\n",pv);

pv=0;

break;

case 6:

printf("You entered fv\n\n");

printf("\nEnter the value of C0 : ");

scanf("%f",&c1);

printf("\nEnter the value of interest rate : ");


scanf("%f",&r);

printf("\nEnter the value of number of periods : ");

scanf("%f",&n);

e=1+r;

power=pow(e,n);

pv=c1*power;

printf("\nThe result is : %.2f\n",pv);

pv=0;

break;

case 7:

printf("You entered npv\n\n");

printf("\n Enter C0 : ");

scanf("%f",&c0);

printf("\n Enter year : ");

scanf("%d",&t);

//t=t+1;

int i;

float C[t], alpha[t],total=0,npv;

for(i=0; i<t; i++)

printf("%d year cash flow : ",i+1);

scanf("%f",&C[i]);
}

printf("\nEnter the value of interest rate : ");

scanf("%f",&r);

r=r/100;

e=1+r;

for(i=0; i<t; i++)

power=pow(e,i+1);

alpha[i]=C[i]/power;

for(i=0; i<t; i++)

total=total+alpha[i];

npv= total-c0;

printf("\nThe result is : %.2f\n",npv);

npv=0;

break;

return 0;

}
Addition

Substraction
Multiplication
Division
Present value
Future value
Net present value

You might also like