0% found this document useful (0 votes)
20 views14 pages

Project Simple Calculator

simple calculator using c
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views14 pages

Project Simple Calculator

simple calculator using c
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

A project report

On
Simple Calculator
Submitted in partial fulfillment of the requirement of
Project – I
Of
Bachelor of Information Technology

Submitted to

Purbanchal University
Biratnagar, Nepal

Submitted By

Sabita Kumari Chaudhary


Salu Sah
Shyam Narayan Yadav

PURBANCHAL SCHOOL OF SCIENCE & TECHNOLOGY


Biratnagar, Morang
August 28, 2024

1
CONTENTS

S.No. Contents Page No.

1. Introduction 3
2. Algorithm 4
3. Flowchart 5
4. Coding 7
5. Conclusion 12
6. Features Recommendation 13
7. Reference 14

2
Chapter 1 : INTRODUCTION

In this topic, we will discuss how we write a calculator program in the


C programming language. A Calculator is a small electronic device
used to perform various arithmetic operations like addition,
subtraction, multiplication, division, percentage, etc. It makes our
calculations easier and faster. It is a portable device that can use
anywhere to perform simple mathematical operations. We use a
scientific or sophisticated calculator in some situations, where we need
to solve complex calculations like trigonometry functions, exponential
operators, degrees, radians, log functions, hyperbolic functions etc.

3
Chapter 2:- Algorithm
An algorithm is a set of commands that must be followed for
a computer to perform calculations or other problem-solving
operations.According to its formal definition, an algorithm is a finite
set of instructions carried out in a specific order to perform a
particular task. It is not the entire program or code; it is simple logic
to a problem represented as an informal description in the form of a
flowchart or pseudocode.

Features:-
1. Finiteness, means it must always terminate after a finite number of
steps.
2. Definiteness, means each step must be precisely defined and clear.
3. Input, means it has zero or more inputs, i.e., an algorithm can run
without taking any input.
4. Output, means it has one or more outputs, i.e., an algorithm must
produce atleast one output.
5. Effectiveness, means it is also generally expected to be effective.
Advantages:-
1.It is a step-wise representation of a solution to a given problem, which
makes it easy to understand.
2. An algorithm uses a definite procedure.
3. It is not dependent on any programming language, so it is easy to
understand for anyone even without programming knowledge.
4. Every step in an algorithm has its own logical sequence so it is easy
to debug.
5. By using algorithm, the problem is broken down into smaller pieces
or steps hence, it is easier for programmer to convert it into an actual program.

Disdvantages
1. Alogorithms is Time consuming.
2. Difficult to show Branching and Looping in Algorithms.
3. Big tasks are difficult to put in Algorithms.
Examples:-
Step 1:- Start
Step 2:- Enter two numbers a & b
Step 3:- Sum two numbers (Sum=a+b)
Step 4:- Print results
Step 5 :- End

4
Chapter 3 :- FLOWCHART

Flowchart:-
A flowchart is a type of diagram that represents a workflow or
process. A flowchart can also be defined as a diagrammatic
representation of an algorithm, a step-by-step approach to solving a
task.

Symbols:-

5
Advantages:-
1. Effective Communication: Flowcharts are better way of
communicating the logic of the system.
2. Easy Debugging and Efficient Testing: The Flowchart helps in
debugging and testing process.
3. Efficient Coding: The flowcharts development phase are very useful
during development.

Disadvantage:-
1. Complex Logic: For complicated logic, flowchart becomes complex and
clumsy.
2. Difficulty in Modifications: If change is required in the logic then
flowchart needs to be redrawn and requires a lot of time.

6
Chapter 4 :- CODING
Program to Create a Simple Calculator Using if-else Statement

// C Program to Make a Simple Calculator using if-else Statements


#include <limits.h>
#include <stdio.h>
// Function that implements the simple calculator
double simpleCalc(double num1, double num2, char op) {
int result;
// Perform the corresponding operation
if (op == '+') {
// Addition
result = num1 + num2;
}
else if (op == '-') {

// Subtraction
result = num1 - num2;
}
else if (op == '*') {

// Multiplication
result = num1 * num2;
}
else if (op == '/') {
// Division
// Check for division by zero
if (num2 != 0) {
result = num1 / num2;
}
else {
printf("Error! Division by zero.\n");
return INT_MIN;

7
}
}
else {
printf("Error! Operator is not correct.\n");
return INT_MIN;
}

return result;
}

int main() {
char op;
double num1, num2;

// Read the operator


printf("Enter an operator (+, -, *, /): ");
scanf("%c", &op);

// Read the two numbers


printf("Enter two operands: ");
scanf("%lf %lf", &num1, &num2);

double result = simpleCalc(num1, num2, op);

printf("Result: %.2lf\n", result);

return 0;
}

8
Simple Calculator Program using switch Statement

// C Program to Make a Simple Calculator using switch-case


// Statements Statements
#include <stdio.h>

// Function to implement simple calculator using switch


// statement
double simpleCalc(double num1, double num2, char op)
{
double result;

// Perform the corresponding operation using


// switch-case
switch (op) {
case '+':

// Addition
result = num1 + num2;
break;
case '-':

// Subtraction
result = num1 - num2;
break;
case '*':

// Multiplication
result = num1 * num2;
break;
case '/':

// Division

9
// Check for division by zero
if (num2 != 0) {
result = num1 / num2;
}
else {
printf("Error! Division by zero.\n");
return -1;
}
break;
default:
printf("Error! Operator is not correct.\n");
return -1;
}
}

int main()
{
char op;
double num1, num2, result;

// Read the operator


printf("Enter an operator (+, -, *, /): ");
scanf("%c", &op);

// Read the two numbers


printf("Enter two operands: ");
scanf("%lf %lf", &num1, &num2);

result = simpleCalc(num1, num2, op);

// Print the result


printf("Result: %.2lf\n", result);

10
return 0;
}

11
Chapter 5 :- CONCLUSION

This project successfully developed a simple calculator application in the C


programming language. The calculator can perform basic arithmetic operations
(addition, subtraction, multiplication, and division) on two user-inputted numbers.

Key Features

 User-friendly interface: Prompts users for input and provides clear


output.
 Accurate calculations: Correctly performs the specified arithmetic
operations.
 Error handling: Implements basic error checking, such as handling
division by zero.
 Modular design: Code is organized into functions for better readability
and maintainability.

12
Chapter 6:- FEATURES RECOMMENDATION

While this project provides a solid foundation, there are opportunities for future
improvements:

 Advanced calculations: Incorporate additional functions like square root,


exponentiation, and trigonometric operations.
 Memory functionality: Allow users to store and recall previous results.
 Graphical user interface (GUI): Develop a more visually appealing
interface using libraries like GTK or Qt.
 Error handling: Implement more robust error checking to handle invalid
input or unexpected scenarios.

13
Chapter 7:- REFRENCE

Special Thanks to :-
1. Gemini AI :- https://gemini.google.com/app/
2. Co- pilot :- https://copilot.microsoft.com/
3. Geeksforgeeks:- https://www.geeksforgeeks.org/

14

You might also like