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 (19)

PPTX
Python operators part2
Vishal Dutt
 
PPTX
Operators in C/C++
Shobi P P
 
DOCX
C – operators and expressions
Chukka Nikhil Chakravarthy
 
PPTX
Operators in C & C++ Language
PreSolutions Softwares
 
PPT
C operator and expression
LavanyaManokaran
 
PPT
Operators and Expressions in C++
Praveen M Jigajinni
 
PPT
Arithmetic operator
Jordan Delacruz
 
PPT
Operator & Expression in c++
bajiajugal
 
PPTX
Basic c operators
dishti7
 
PPT
Basic c operators
Anuja Lad
 
PPTX
Operators and expressions in C++
Neeru Mittal
 
PPT
2. operators in c
amar kakde
 
PPTX
Operator.ppt
Darshan Patel
 
PPTX
Relational operators
Graphic Era Hill University,Bhimtal
 
DOC
Report on c
jasmeen kr
 
PPT
Operators in c language
Amit Singh
 
PPTX
Operator in c programming
Manoj Tyagi
 
PPT
6 operators-in-c
Rohit Shrivastava
 
PPTX
Operators
Krishna Kumar Pankaj
 
Python operators part2
Vishal Dutt
 
Operators in C/C++
Shobi P P
 
C – operators and expressions
Chukka Nikhil Chakravarthy
 
Operators in C & C++ Language
PreSolutions Softwares
 
C operator and expression
LavanyaManokaran
 
Operators and Expressions in C++
Praveen M Jigajinni
 
Arithmetic operator
Jordan Delacruz
 
Operator & Expression in c++
bajiajugal
 
Basic c operators
dishti7
 
Basic c operators
Anuja Lad
 
Operators and expressions in C++
Neeru Mittal
 
2. operators in c
amar kakde
 
Operator.ppt
Darshan Patel
 
Report on c
jasmeen kr
 
Operators in c language
Amit Singh
 
Operator in c programming
Manoj Tyagi
 
6 operators-in-c
Rohit Shrivastava
 

Similar to Programming C Part 02 (20)

PPTX
C - programming - Ankit Kumar Singh
AnkitSinghRajput35
 
PPTX
PROGRAMMING IN C - Operators.pptx
Nithya K
 
DOCX
Programming Fundamentals lecture 7
REHAN IJAZ
 
PPTX
COM1407: C Operators
Hemantha Kulathilake
 
PDF
Introduction to programming c and data-structures
Pradipta Mishra
 
PDF
C Operators and Control Structures.pdf
MaryJacob24
 
PDF
Introduction to programming c and data structures
Pradipta Mishra
 
DOCX
PPS 2.2.OPERATORS ARITHMETIC EXPRESSIONS/ARITHMETIC OPERATORS/RELATIONAL OPER...
Sitamarhi Institute of Technology
 
PPTX
C Operators and Control Structures.pptx
ramanathan2006
 
PPTX
C Programming Language Part 4
Rumman Ansari
 
PPTX
introduction to c programming and C History.pptx
ManojKhadilkar1
 
PPTX
Operators in C programming language.pptx
b221382
 
PPTX
Expressions using operator in c
Saranya saran
 
PPTX
C operators
AbiramiT9
 
PPT
6 operators-in-c
Rohit Shrivastava
 
PPTX
Structured Programming Unit-4-Operators-and-Expression.pptx
SuryaBasnet1
 
PDF
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 2 of 5 by...
ssuserd6b1fd
 
PPTX
operators_group_2[1].pptx PLEASE DOWNLOAD
aluffssdd804
 
PPTX
C programming(Part 1)
Dr. SURBHI SAROHA
 
PDF
Types of Operators in C
Thesis Scientist Private Limited
 
C - programming - Ankit Kumar Singh
AnkitSinghRajput35
 
PROGRAMMING IN C - Operators.pptx
Nithya K
 
Programming Fundamentals lecture 7
REHAN IJAZ
 
COM1407: C Operators
Hemantha Kulathilake
 
Introduction to programming c and data-structures
Pradipta Mishra
 
C Operators and Control Structures.pdf
MaryJacob24
 
Introduction to programming c and data structures
Pradipta Mishra
 
PPS 2.2.OPERATORS ARITHMETIC EXPRESSIONS/ARITHMETIC OPERATORS/RELATIONAL OPER...
Sitamarhi Institute of Technology
 
C Operators and Control Structures.pptx
ramanathan2006
 
C Programming Language Part 4
Rumman Ansari
 
introduction to c programming and C History.pptx
ManojKhadilkar1
 
Operators in C programming language.pptx
b221382
 
Expressions using operator in c
Saranya saran
 
C operators
AbiramiT9
 
6 operators-in-c
Rohit Shrivastava
 
Structured Programming Unit-4-Operators-and-Expression.pptx
SuryaBasnet1
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 2 of 5 by...
ssuserd6b1fd
 
operators_group_2[1].pptx PLEASE DOWNLOAD
aluffssdd804
 
C programming(Part 1)
Dr. SURBHI SAROHA
 
Types of Operators in C
Thesis Scientist Private Limited
 
Ad

Recently uploaded (20)

PDF
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
PPTX
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
PPTX
Neurodivergent Friendly Schools - Slides from training session
Pooky Knightsmith
 
PPTX
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
PDF
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
PDF
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
PDF
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
PPTX
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
PDF
Geographical Diversity of India 100 Mcq.pdf/ 7th class new ncert /Social/Samy...
Sandeep Swamy
 
PPTX
How to Handle Salesperson Commision in Odoo 18 Sales
Celine George
 
PPTX
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
PPTX
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
PDF
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
PPTX
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
PPTX
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
PPTX
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
PDF
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
PDF
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PPTX
Post Dated Cheque(PDC) Management in Odoo 18
Celine George
 
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
Neurodivergent Friendly Schools - Slides from training session
Pooky Knightsmith
 
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
Geographical Diversity of India 100 Mcq.pdf/ 7th class new ncert /Social/Samy...
Sandeep Swamy
 
How to Handle Salesperson Commision in Odoo 18 Sales
Celine George
 
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
Post Dated Cheque(PDC) Management in Odoo 18
Celine George
 
Ad

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.