Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

Name: Sujeet D Roll No.

: 51 Div: B

Branch: CSE(IoT)

Date of Performance: 21st July, 2023 Subject: Data Structure Experiment No. : 1

Aim:
To write a program for calculator using switch case.

Theory:
C language is the base of all programming languages. The operating system (OS) is built using C.

An entity that may vary during the program execution is called a variable.
Syntax is a combination of data type and variable name. eg. int a; int z; etc.

Rules for decaling variables:

i) Variable is any combination of digit, alphabets, underscore(_)


ii) Variable name is of 32 characters.
iii) The first character of variable must be alphabet or ‘_’
iv) No special symbol other than ‘_’ is allowed.
v) No blank space or commas’,’ are allowed.
vi) Keywords cannot be used as variable names.
vii) Variable names are the names given to the memory location.
viii) Particular type of variable can hold same type of data.

Types of variable:

i) Global
ii) Local

A word whose meaning has already been explained to the compiler is known as Keywords.

An entity does not vary during the program execution is called a Constant.

Operators:

i) Increment and decrement operators: It is used to increment the value of a variable by 1. It is used to
decrease the operand values by 1. The increment operator is represented as the double plus (++) symbol. The
decrement operator is represented as the double minus (--) symbol.
Name: Sujeet D Roll No. : 51 Div: B

Branch: CSE(IoT)

Date of Performance: 21st July, 2023 Subject: Data Structure Experiment No. : 1

ii) Bitwise operators: This is an operator used to perform bitwise operations on bit patterns or binary numerals
that involve the manipulation of individual bits. These are used in: Communication stacks where the
individual bits in the header attached to the data signify important information.
iii) Assignment operators: In this, = assigns the value of its right-hand operand to a variable, a property, or an
indexer element given by its left-hand operand. The result of an assignment expression is the value assigned
to the left-hand operand.
iv) Logical operators: These are generally used for combining two or more relational statements. They return
Boolean values. The logical operators are used primarily in the expression evaluation to make a decision.
These operators allow the evaluation and manipulation of specific bits within the integer.
v) Relational operators: These are the operators used to create a relationship and compare the values of two
operands
vi) Special operators: In the C programming language, special operators are used to perform specific operations
that cannot be done with normal arithmetic or logical operators. These operators are special because they
have their own unique syntax and functionality.
vii) Conditional operators: This is the one and only ternary operator in the C programming language. It can be
used as an alternative for if-else condition if the 'if else' has only one statement each
viii) Arithmetic Operators: These are the type of operators in C that are used to perform mathematical
operations in a C program. They can be used in programs to define expressions and mathematical formulas.
Name: Sujeet D Roll No. : 51 Div: B

Branch: CSE(IoT)

Date of Performance: 21st July, 2023 Subject: Data Structure Experiment No. : 1

Program:
#include<stdio.h>

int add(int a,int b)

{int sol;

sol=a+b;

return(sol);

int sub(int a,int b)

{int sol;

sol=a-b;

return(sol)

int mul(int a,int b)

{int sol;

sol=a*b;

return(sol);

int dvn(int a,int b)

{int sol;

sol=a*b;

return(sol);

}
Name: Sujeet D Roll No. : 51 Div: B

Branch: CSE(IoT)

Date of Performance: 21st July, 2023 Subject: Data Structure Experiment No. : 1

int main()

{int opt,a,b,sol,rem;

printf("menu:\n1)Addition\n2) sunstraction\n3) multiplication\n 4)division\n")

printf("enter a choice:");

scanf("%d",&opt);

switch(opt)

case 1:

printf("enter two numbers for addition:");

scanf("%d%d",&a,&b);

sol=add(a,b);

printf("addition of %d acase1nd %d is %d",a,b,sol);

break;

case 2:

printf("enter two numbers for substraction:");

scanf("%d%d",&a,&b);

sol=suub(a,b);

printf("substraction of %d and %d is %d",b,a,sol);

break;

case 3:

printf("enter two numbers for multiplication:");

scanf("%d%d",&a,&b);

sol=mul(a,b);

printf("multiplication of %d and %d is %d",a,b,sol);

break;
Name: Sujeet D Roll No. : 51 Div: B

Branch: CSE(IoT)

Date of Performance: 21st July, 2023 Subject: Data Structure Experiment No. : 1

case 4:

printf("enter divident:");

scanf("%d",&a);

printf("enter divisor:");

scanf("%d",&b);

sol=dvn(a,b);

rem=a-(b*dvn(a,b));

printf("division of %d and %d is %d",a,b,sol);

break;

default:

printf("invaliid choice!");

break;

return(0);

Output:
Name: Sujeet D Roll No. : 51 Div: B

Branch: CSE(IoT)

Date of Performance: 21st July, 2023 Subject: Data Structure Experiment No. : 1

Result:
Implemented Successfully

You might also like