SlideShare a Scribd company logo
Dhaka University of Engineering & Technology, (DUET) Gazipur
Department of Textile Engineering
Course NO: CSE- 3702
Course Name: Computer Applications and Programming (Sessional)
Date of Submission: 28-03-2021
Experiment No: 02
Name of the Experiment: Introduction to C operator.
Submitted To
Mr. Khawja Imran
Masud
Lecturer,
Department of CSE,
DUET
Submitted By
Name: Md. Rasel Mondal
Student ID: 175013
Year/Semester: 3/1
Session: 2019-20
Report No: 02
Report Name: Introduction to C operator.
1.0 Objectives:
1. To know about C operator.
2.0 Theory:
2.1 C- Operator:
An operator is a symbol that tells the compiler to perform specific
mathematical or logical functions. C language is rich in built-in
operators and provides the following types of operators –
• Arithmetic Operators
• Relational Operators
• Logical Operators
• Bitwise Operators
• Assignment Operators
2.1.1 Arithmetic Operators:
The following table shows all the arithmetic operators supported by the C language.
Assume variable A holds 20 and variable B holds 10, then −
Operator Description Example
+ Adds two operands. A + B =
30
− Subtracts second operand from the first. A − B =
10
* Multiplies both operands. A * B =
200
/ Divides numerator by de-numerator. A/B = 2
% Modulus Operator and remainder of after an integer division. A%B = 0
++ Increment operator increases the integer value by one. A++ = 21
-- Decrement operator decreases the integer value by one. B-- = 9
Example:
#include <stdio.h>
int main()
{
int a = 20, b= 10, c;
c = a + b;
printf("a+b= %dn", c );
c = a - b;
printf("a-b= %dn", c );
c = a * b;
printf("a*b= %dn", c );
c = a / b;
printf("a/b= %dn", c );
c = a % b;
printf("a%b= %dn", c );
c =++a;
printf("a++= %dn", c );
c =--b;
printf("b--= %dn", c);
return 0;
}
Output:
2.1.2 Relational Operators:
The following table shows all the relational operators supported by C language.
Assume variable A holds 20 and variable B holds10 then −
Operator Description Example
== Checks if the values of two operands are equal or not. If yes,
then the condition becomes true.
(A == B)
is not
true.
!= Checks if the values of two operands are equal or not. If the
values are not equal, then the condition becomes true.
(A!= B)
is true.
> Checks if the value of left operand is greater than the value of
right operand. If yes, then the condition becomes true.
(A > B)
is true.
< Checks if the value of left operand is less than the value of
right operand. If yes, then the condition becomes true.
(A < B)
is not
true.
>= Checks if the value of left operand is greater than or equal to
the value of right operand. If yes, then the condition becomes
true.
(A >= B)
is true.
<= Checks if the value of left operand is less than or equal to the
value of right operand. If yes, then the condition becomes
true.
(A <= B)
is not true.
Example:
#include <stdio.h>
int main()
{
int a=20, b=10, c;
c =a== b;
printf("c =a==b %dn", c);
c =a<b;
printf("c =a<b %dn", c);
c =a>b;
printf("c =a>b %dn", c);
c =a<=b;
printf("c =a<=b %dn", c);
c =a>=b;
printf("c= a>=b %dn", c);
return 0;
}
Output:
2.2.3 Logical Operators:
Following table shows all the logical operators supported by C language. Assume
variable A holds 1 and variable B holds 0, then −
Operator Description Example
&& Called Logical AND operator. If both the operands are non-
zero, then the condition becomes true.
(A &&
B) is
false.
|| Called Logical OR Operator. If any of the two operands is
non-zero, then the condition becomes true.
(A || B)
is true.
! Called Logical NOT Operator. It is used to reverse the logical
state of its operand. If a condition is true, then Logical NOT
operator will make it false.
!(A &&
B) is
true.
Example:
#include <stdio.h>
int main()
{
int a=1, b=0, c;
c=a&&b ;
printf("a&&b= %dn",c );
c=a||b ;
printf("a||b= %dn",c );
c= !(a&&b) ;
printf("!a&&b= %dn",c);
return 0;
}
Output:
2.2.4 Bitwise Operators:
The following table lists the Bitwise operators supported by C. Assume variable 'A'
holds 60 and variable 'B' holds 13, then −
Operator Description Example
& Binary AND Operator copies a bit to the result if it exists in
both operands.
(A & B)
= 12,
i.e., 0000
1100
| Binary OR Operator copies a bit if it exists in either operand. (A | B) =
61, i.e.,
0011
1101
^ Binary XOR Operator copies the bit if it is set in one operand
but not both.
(A ^ B)
= 49,
i.e., 0011
0001
Example:
#include <stdio.h>
int main()
{
int a= 60; /* 60 = 0011 1100 */
int b = 13; /* 13 = 0000 1101 */
int c;
c = a & b; /* 12 = 0000 1100 */
printf("a&b %dn",c );
c = a | b; /* 61 = 0011 1101 */
printf("a|b %dn", c );
c = a ^ b; /* 49 = 0011 0001 */
printf("a^b %dn", c );
return 0;
}
Output:
2.1.5 Assignment Operators:
The following table lists the assignment operators supported by the C language −
Operator Description Example
= Simple assignment operator. Assigns values from right side
operands to left side operand
C = A +
B will
assign the
value of
A + B to
C
+= Add AND assignment operator. It adds the right operand to
the left operand and assign the result to the left operand.
C += A is
equivalent
to C = C
+ A
-= Subtract AND assignment operator. It subtracts the right
operand from the left operand and assigns the result to the
left operand.
C -= A is
equivalent
to C = C -
A
*= Multiply AND assignment operator. It multiplies the right
operand with the left operand and assigns the result to the left
operand.
C *= A is
equivalent
to C = C
* A
/= Divide AND assignment operator. It divides the left operand
with the right operand and assigns the result to the left
operand.
C /= A is
equivalent
to C = C /
A
Example:
#include <stdio.h>
int main()
{
int a=20, c ;
c = a;
printf("c = %dn", c );
c += a;
printf("c+ = %dn", c );
c -= a;
printf(" c- = %dn", c );
c *= a;
printf(" c* = %dn", c );
c /= a;
printf(" c/ = %dn", c );
return 0;
}
Output:
2.2 Lab Assessment Task:
2.2.1 Write a program to convert temperature from Celsius to Fahrenheit.
#include <stdio.h>
int main()
{
int celsius, fahrenheit;
printf("Enter temperature in Celsius: ");
scanf("%d", &celsius);
/* celsius to fahrenheit conversion formula */
fahrenheit = (celsius * 9 / 5) + 32;
printf("%d Celsius = %d Fahrenheit", celsius, fahrenheit);
return 0;
}
Output:
2.2.2 Write a program to Calculate the area of a circle.
#include <stdio.h>
int main()
{
float radius, area;
printf("Enter the radius of a circle:");
scanf("%f", &radius);
area = 3.1416*radius*radius;
printf("Area of the circle. %.4f", area);
return 0;
}
Output:
3.0 Conclusion:
In this Experiment we know about C operators like Arithmetic, Relational,
Logical, Bitwise and Assignment operator. I hope this experiment will help in my
practical life.

More Related Content

What's hot

What's hot (20)

Operation and expression in c++
Operation and expression in c++Operation and expression in c++
Operation and expression in c++
 
Python operators part2
Python operators part2Python operators part2
Python operators part2
 
Operators in C/C++
Operators in C/C++Operators in C/C++
Operators in C/C++
 
C – operators and expressions
C – operators and expressionsC – operators and expressions
C – operators and expressions
 
Operators in C & C++ Language
Operators in C & C++ LanguageOperators in C & C++ Language
Operators in C & C++ Language
 
C operator and expression
C operator and expressionC operator and expression
C operator and expression
 
Operators and Expressions in C++
Operators and Expressions in C++Operators and Expressions in C++
Operators and Expressions in C++
 
Arithmetic operator
Arithmetic operatorArithmetic operator
Arithmetic operator
 
Operator & Expression in c++
Operator & Expression in c++Operator & Expression in c++
Operator & Expression in c++
 
Basic c operators
Basic c operatorsBasic c operators
Basic c operators
 
Basic c operators
Basic c operatorsBasic c operators
Basic c operators
 
Operators and expressions in C++
Operators and expressions in C++Operators and expressions in C++
Operators and expressions in C++
 
2. operators in c
2. operators in c2. operators in c
2. operators in c
 
Operator.ppt
Operator.pptOperator.ppt
Operator.ppt
 
Relational operators
Relational operatorsRelational operators
Relational operators
 
Report on c
Report on cReport on c
Report on c
 
Operators in c language
Operators in c languageOperators in c language
Operators in c language
 
Operator in c programming
Operator in c programmingOperator in c programming
Operator in c programming
 
6 operators-in-c
6 operators-in-c6 operators-in-c
6 operators-in-c
 
Operators
OperatorsOperators
Operators
 

Similar to Programming C Part 02

Similar to Programming C Part 02 (20)

Lecture 2 C++ | Variable Scope, Operators in c++
Lecture 2 C++ | Variable Scope, Operators in c++Lecture 2 C++ | Variable Scope, Operators in c++
Lecture 2 C++ | Variable Scope, Operators in c++
 
COM1407: C Operators
COM1407: C OperatorsCOM1407: C Operators
COM1407: C Operators
 
Theory3
Theory3Theory3
Theory3
 
Programming Fundamentals lecture 7
Programming Fundamentals lecture 7Programming Fundamentals lecture 7
Programming Fundamentals lecture 7
 
Computer programming 2 Lesson 7
Computer programming 2  Lesson 7Computer programming 2  Lesson 7
Computer programming 2 Lesson 7
 
Constructor and destructors
Constructor and destructorsConstructor and destructors
Constructor and destructors
 
C Operators and Control Structures.pptx
C Operators and Control Structures.pptxC Operators and Control Structures.pptx
C Operators and Control Structures.pptx
 
C programming(Part 1)
C programming(Part 1)C programming(Part 1)
C programming(Part 1)
 
C++ chapter 2
C++ chapter 2C++ chapter 2
C++ chapter 2
 
C Operators and Control Structures.pdf
C Operators and Control Structures.pdfC Operators and Control Structures.pdf
C Operators and Control Structures.pdf
 
Expressions using operator in c
Expressions using operator in cExpressions using operator in c
Expressions using operator in c
 
C - programming - Ankit Kumar Singh
C - programming - Ankit Kumar Singh C - programming - Ankit Kumar Singh
C - programming - Ankit Kumar Singh
 
Java basic operators
Java basic operatorsJava basic operators
Java basic operators
 
Java basic operators
Java basic operatorsJava basic operators
Java basic operators
 
Operators and it's type
Operators and it's type Operators and it's type
Operators and it's type
 
Operators
OperatorsOperators
Operators
 
itft-Operators in java
itft-Operators in javaitft-Operators in java
itft-Operators in java
 
C sharp part 001
C sharp part 001C sharp part 001
C sharp part 001
 
Java unit1 b- Java Operators to Methods
Java  unit1 b- Java Operators to MethodsJava  unit1 b- Java Operators to Methods
Java unit1 b- Java Operators to Methods
 
C operators
C operators C operators
C operators
 

Recently uploaded

The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationDelapenabediema
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdfTechSoup
 
plant breeding methods in asexually or clonally propagated crops
plant breeding methods in asexually or clonally propagated cropsplant breeding methods in asexually or clonally propagated crops
plant breeding methods in asexually or clonally propagated cropsparmarsneha2
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersPedroFerreira53928
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxJisc
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfVivekanand Anglo Vedic Academy
 
Solid waste management & Types of Basic civil Engineering notes by DJ Sir.pptx
Solid waste management & Types of Basic civil Engineering notes by DJ Sir.pptxSolid waste management & Types of Basic civil Engineering notes by DJ Sir.pptx
Solid waste management & Types of Basic civil Engineering notes by DJ Sir.pptxDenish Jangid
 
Matatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptxMatatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptxJenilouCasareno
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePedroFerreira53928
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfTamralipta Mahavidyalaya
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasGeoBlogs
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonSteve Thomason
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleCeline George
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chipsGeoBlogs
 
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdfINU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdfbu07226
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxEduSkills OECD
 
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptxJose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptxricssacare
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxPavel ( NSTU)
 

Recently uploaded (20)

The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
plant breeding methods in asexually or clonally propagated crops
plant breeding methods in asexually or clonally propagated cropsplant breeding methods in asexually or clonally propagated crops
plant breeding methods in asexually or clonally propagated crops
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Solid waste management & Types of Basic civil Engineering notes by DJ Sir.pptx
Solid waste management & Types of Basic civil Engineering notes by DJ Sir.pptxSolid waste management & Types of Basic civil Engineering notes by DJ Sir.pptx
Solid waste management & Types of Basic civil Engineering notes by DJ Sir.pptx
 
Matatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptxMatatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptx
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 
B.ed spl. HI pdusu exam paper-2023-24.pdf
B.ed spl. HI pdusu exam paper-2023-24.pdfB.ed spl. HI pdusu exam paper-2023-24.pdf
B.ed spl. HI pdusu exam paper-2023-24.pdf
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
 
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdfINU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptxJose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 

Programming C Part 02

  • 1. Dhaka University of Engineering & Technology, (DUET) Gazipur Department of Textile Engineering Course NO: CSE- 3702 Course Name: Computer Applications and Programming (Sessional) Date of Submission: 28-03-2021 Experiment No: 02 Name of the Experiment: Introduction to C operator. Submitted To Mr. Khawja Imran Masud Lecturer, Department of CSE, DUET Submitted By Name: Md. Rasel Mondal Student ID: 175013 Year/Semester: 3/1 Session: 2019-20
  • 2. Report No: 02 Report Name: Introduction to C operator. 1.0 Objectives: 1. To know about C operator. 2.0 Theory: 2.1 C- Operator: An operator is a symbol that tells the compiler to perform specific mathematical or logical functions. C language is rich in built-in operators and provides the following types of operators – • Arithmetic Operators • Relational Operators • Logical Operators • Bitwise Operators • Assignment Operators 2.1.1 Arithmetic Operators: The following table shows all the arithmetic operators supported by the C language. Assume variable A holds 20 and variable B holds 10, then − Operator Description Example + Adds two operands. A + B = 30 − Subtracts second operand from the first. A − B = 10 * Multiplies both operands. A * B = 200
  • 3. / Divides numerator by de-numerator. A/B = 2 % Modulus Operator and remainder of after an integer division. A%B = 0 ++ Increment operator increases the integer value by one. A++ = 21 -- Decrement operator decreases the integer value by one. B-- = 9 Example: #include <stdio.h> int main() { int a = 20, b= 10, c; c = a + b; printf("a+b= %dn", c ); c = a - b; printf("a-b= %dn", c ); c = a * b; printf("a*b= %dn", c ); c = a / b;
  • 4. printf("a/b= %dn", c ); c = a % b; printf("a%b= %dn", c ); c =++a; printf("a++= %dn", c ); c =--b; printf("b--= %dn", c); return 0; } Output: 2.1.2 Relational Operators: The following table shows all the relational operators supported by C language. Assume variable A holds 20 and variable B holds10 then − Operator Description Example
  • 5. == Checks if the values of two operands are equal or not. If yes, then the condition becomes true. (A == B) is not true. != Checks if the values of two operands are equal or not. If the values are not equal, then the condition becomes true. (A!= B) is true. > Checks if the value of left operand is greater than the value of right operand. If yes, then the condition becomes true. (A > B) is true. < Checks if the value of left operand is less than the value of right operand. If yes, then the condition becomes true. (A < B) is not true. >= Checks if the value of left operand is greater than or equal to the value of right operand. If yes, then the condition becomes true. (A >= B) is true. <= Checks if the value of left operand is less than or equal to the value of right operand. If yes, then the condition becomes true. (A <= B) is not true. Example: #include <stdio.h> int main() { int a=20, b=10, c; c =a== b; printf("c =a==b %dn", c);
  • 6. c =a<b; printf("c =a<b %dn", c); c =a>b; printf("c =a>b %dn", c); c =a<=b; printf("c =a<=b %dn", c); c =a>=b; printf("c= a>=b %dn", c); return 0; } Output: 2.2.3 Logical Operators: Following table shows all the logical operators supported by C language. Assume variable A holds 1 and variable B holds 0, then − Operator Description Example
  • 7. && Called Logical AND operator. If both the operands are non- zero, then the condition becomes true. (A && B) is false. || Called Logical OR Operator. If any of the two operands is non-zero, then the condition becomes true. (A || B) is true. ! Called Logical NOT Operator. It is used to reverse the logical state of its operand. If a condition is true, then Logical NOT operator will make it false. !(A && B) is true. Example: #include <stdio.h> int main() { int a=1, b=0, c; c=a&&b ; printf("a&&b= %dn",c ); c=a||b ; printf("a||b= %dn",c ); c= !(a&&b) ; printf("!a&&b= %dn",c); return 0; } Output:
  • 8. 2.2.4 Bitwise Operators: The following table lists the Bitwise operators supported by C. Assume variable 'A' holds 60 and variable 'B' holds 13, then − Operator Description Example & Binary AND Operator copies a bit to the result if it exists in both operands. (A & B) = 12, i.e., 0000 1100 | Binary OR Operator copies a bit if it exists in either operand. (A | B) = 61, i.e., 0011 1101 ^ Binary XOR Operator copies the bit if it is set in one operand but not both. (A ^ B) = 49, i.e., 0011 0001 Example: #include <stdio.h> int main()
  • 9. { int a= 60; /* 60 = 0011 1100 */ int b = 13; /* 13 = 0000 1101 */ int c; c = a & b; /* 12 = 0000 1100 */ printf("a&b %dn",c ); c = a | b; /* 61 = 0011 1101 */ printf("a|b %dn", c ); c = a ^ b; /* 49 = 0011 0001 */ printf("a^b %dn", c ); return 0; } Output: 2.1.5 Assignment Operators: The following table lists the assignment operators supported by the C language − Operator Description Example
  • 10. = Simple assignment operator. Assigns values from right side operands to left side operand C = A + B will assign the value of A + B to C += Add AND assignment operator. It adds the right operand to the left operand and assign the result to the left operand. C += A is equivalent to C = C + A -= Subtract AND assignment operator. It subtracts the right operand from the left operand and assigns the result to the left operand. C -= A is equivalent to C = C - A *= Multiply AND assignment operator. It multiplies the right operand with the left operand and assigns the result to the left operand. C *= A is equivalent to C = C * A /= Divide AND assignment operator. It divides the left operand with the right operand and assigns the result to the left operand. C /= A is equivalent to C = C / A Example: #include <stdio.h> int main() { int a=20, c ;
  • 11. c = a; printf("c = %dn", c ); c += a; printf("c+ = %dn", c ); c -= a; printf(" c- = %dn", c ); c *= a; printf(" c* = %dn", c ); c /= a; printf(" c/ = %dn", c ); return 0; } Output: 2.2 Lab Assessment Task: 2.2.1 Write a program to convert temperature from Celsius to Fahrenheit. #include <stdio.h> int main()
  • 12. { int celsius, fahrenheit; printf("Enter temperature in Celsius: "); scanf("%d", &celsius); /* celsius to fahrenheit conversion formula */ fahrenheit = (celsius * 9 / 5) + 32; printf("%d Celsius = %d Fahrenheit", celsius, fahrenheit); return 0; } Output: 2.2.2 Write a program to Calculate the area of a circle. #include <stdio.h> int main() { float radius, area;
  • 13. printf("Enter the radius of a circle:"); scanf("%f", &radius); area = 3.1416*radius*radius; printf("Area of the circle. %.4f", area); return 0; } Output: 3.0 Conclusion: In this Experiment we know about C operators like Arithmetic, Relational, Logical, Bitwise and Assignment operator. I hope this experiment will help in my practical life.