VVVV
VVVV
S COLLEGE MOTIHARI
CALCULATER
DATA STRUCTURE
• CPL is common Programming Language.In 1967, BCPL Language ( Basic CPL ) was
• As many of the features were derived from “B” Language thats why it was named as “C”.
• After 7-8 years C++ came into existence which was first example of object oriented
programming .
5 Year 1972
C Programming Language Timeline :
Programming Development
Developed by
Language Year
Before we study the basic building blocks of the C programming language, let us look at a
bare minimum C program structure so that we can take it as a reference in the upcoming
chapters.
• Preprocessor Commands
• Functions
• Variables
• Statements & Expressions
• Comments
Let us look at a simple code that would print the words "Hello World" –
#include <stdio.h>
int main() {
/* my first program in C */
printf("Hello, World! \n");
return 0;
}
The Calculator Project in C is a console-based application that allows users to perform basic
arithmetic operations on two input numbers. The calculator supports addition, subtraction,
multiplication, and division. It incorporates fundamental programming concepts such as functions,
user input handling, and error checking.
Key Features: 1. User Input: The program prompts the user to enter an operator (+, -, *, /) and two
numerical values. The input is read from the user using the scanf function, ensuring flexibility and
ease of interaction.
2. Arithmetic Operations: The calculator performs the selected operation based on the user-
provided operator. The implemented operations include addition, subtraction, multiplication, and
division.
3. Switch Statement: The program utilizes a switch statement to determine the operation tobe
performed, enhancing code readability and maintainability.
4. Error Handling: The calculator includes basic error handling to address potential issueIt checks for
division by zero, ensuring that the program does not crash in such scenarios, and notifies the user of
the error.
5. Functions: The project is organized using functions, promoting modularity and code reusability.
Separate functions are defined for each arithmetic operation (addition, subtraction, multiplication,
division)
6. Result Display: Upon successful calculation, the program displays the result with two decimal
places, enhancing output clarity.
7. Invalid Input Handling: The program checks for invalid operators, providing an error message and
prompting the user to enter a valid operator in case of an input mismatch.
8. Clean Exit: The program returns a status code upon completion, indicating whether the execution
was successful (0) or if there were errors (non-zero)
Future Enhancements:
1. Extended Operations: Extend the calculator to support more advanced mathematical operations,
such as exponentiation, square root, etc.
#INCLUDE<CONIO.H>
// Function declarations
int main() {
char operator;
scanf("%f" , &num1);
scanf("%f" , &num2);
switch (operator) {
case '+':
break;
case '-':
break;
case '*':
break;
case '/':
if (num2 != 0) {
} else {
break;
default:
// Function definitions