SlideShare a Scribd company logo
C             Programming
                       Language
               By:
    Yogendra Pal
yogendra@learnbywatch.com
  Dedicated to My mother and Father
t
                                                               y
         Keep your notebook with you.

Write important point and questions that comes in your mind

     Solve Mind band exercise.


                                                               C
                                       Rewind when not clear


              Ask Questions by call or SMS or by mail


Keep Watching Keep Learning

THIS IS ARITHMETIC INSTRUCTIONS


                                   2
What do you know?
•   printf() function?
•   scanf() function?
•   How to write a simple C program?
•   How to compile and run it?
•   If answers are yes then you can go ahead.



                          3
Problem
• Write a program to add two numbers. These
  numbers must input by user.
• For addition (+) we need arithmetic operators.




                        4
Arithmetic Operators
•   * : multiplication         y         z
                               2         4
•   / : division
•   + : addition
•   - : subtraction                2+4
                                    x
•   % : modulus operator            6

•   Variable = constant;
    – x = y + z;

                           5
Result of each operator
•   2*3=6
•   4/2=2
•   4+2=6
•   4–2=2
•   4%3=1
•   4%2=0


                  6
Some Constraints
• Arithmetic operators act on numeric values.
  – (int/float/char) operator (int/float/char)
  – character represents numeric (ASCII) value.
• Modules operator works only when
  – int % int (non-zero).
• Division operator works only when
  – (int/float/char) / (non-zero value).


                             7
You must know
•   int / int = int
•   (int / float) = float
•   (float / int) = float
•   (float / float) = float




                              8
Assignment Operator =
• Assign expression value to an identifier.
• identifier = expression or variable = constant.
• If both operand are of different data types
  then right side value convert into the data
  type of left side identifier.
• Multiple assignment execute from right to left.
  – x = y = z = 5.


                        9
More Assignment Operator…
• *=, /=, %=, +=, -= know as compound
  assignment operator.
• x += 1; means x = x + 1;
• a -= b; means a = a – b;
• m %= (n-7); means m = m % (n-7);




                  10
Addition of two numbers
    start           start
                                  #include<stdio.h>
                                  #include<conio.h>
Define a,b,c      int a,b,c
                                  void main()
initialize b,c   b = 4, c = 2     {
                                            int a, b, c;
 a=b+c            a=b+c                     b = 4;
                                            c = 2;
   print a         print a                  a = b + c;
                                            printf(“%d”,a);
                                            getch();
    stop            stop          }

                             11
Unary Operators
•   Operate upon single operand.
•   - (unary minus)
•   + (unary plus)
•   -- (decrement operator) : decrement by 1
    – i--; or --i; equal to i = i -1;
• ++ (increment operator) : increment by 1
    – i++; or ++i; equal to i = i +1;

                                   12
Unary Operator…
• sizeof : returns the size (bytes) of operand.
  – printf(“integer: %d”,sizeof(i));
• Type Cast is also a unary operator.
• Type Cast changes the data type of operand.
  – (Type) operand;
  – float a = 3.7;
  – (int)a;


                             13
Operator precedence
Operator         Operation                     Precendence
()               Parentheses                   Evaluate First,
                                               Innermost first,
                                               Left to right.
-, +, --, ++,    Unary operators               Right to left
sizeof, (type)
*, / or %        Multiplication, Division or   Left to right.
                 modulus
+ or -           Addition and subtraction      Left to right.
=                Assignment (Multiple)         Right to left.


                                     14
Example of precedence
•   a=2*3/4+4/4+8–2+5/ (3+1)
•   a=2*3/4+4/4+8–2+5/ 4
•   a=6/4+4/4+8–2+5/ 4
•   a=1+4/4+8–2+5/ 4
•   a=1+1+8–2+5/ 4
•   a=1+1+8–2+1
•   a=2+8–2+1
•   a = 10 – 2 + 1
•   a=8+1
•   a=9

                      15
Mind Bend
• Calculate the value.
  – ( 3 * 5.9 – 2 * 6 ) % ( 4 * 8 + 4 )
  –2*((8/6)+(4*(9–4))%(3*2–2)
  – ( 3 * 9 - 3 ) % ( 5 + 3 * 3) / ( 6 - 7 )




                          16
Calculate the average
    start              start


Define a,b,c       Define a,b,c

initialize b,c     initialize b,c

a=b+c/2            a=(b+c)/2

   print a            print a


    stop               stop

                           17
Problem
• Write a program to convert a value from
  kilometer to meter.
• Formula to convert km in to meter is:
  – 1 km = 1000 m so,
  – n km = 1000 * n m
• Now you can solve any formula based
  problem.

                        18
Problem…
• Write a program that convert a lowercase
  character to uppercase character.
• Write a program to calculate the area and
  circumference of the circle.
• Two numbers (x and y) are entered through the
  keyboard. Write a program to interchange the
  value of x and y.
• Write a program that print reverse of a 5 digit
  given number.

                        19
Problem…
• Write a program that calculate the root of a
  quadratic equation.
  – ax2 + bx + c = 0.
• Input marks of five subjects of a student and
  write a program to calculate and print addition
  and percentage of that student.



                           20
Mind Bend
• Write a program that convert a uppercase
  alphabet to lowercase alphabet.
• Write a program to calculate the area and
  perimeter of rectangle.
• Write a program that print reverse of a 3 digit
  given number.



                        21
To get complete benefit of this tutorial solve all the quiz on
                       www.learnbywatch.com

              For any problem in this tutorial mail me at
                    yogendra@learnbywatch.com
                        with the subject “C”

                     For Other information mail at
                       info@learnbywatch.com


Keep Watching Keep Learning

NEXT IS DECISION CONTROL

                                    22

More Related Content

PDF
Lecture 8 increment_and_decrement_operators
PPTX
PPTX
Increment and Decrement operators in C++
PPTX
Chapter 3 dti2143
PPTX
Operators in C/C++
PPTX
Operators-computer programming and utilzation
PPT
Functions & Procedures [7]
PPT
Basic c operators
Lecture 8 increment_and_decrement_operators
Increment and Decrement operators in C++
Chapter 3 dti2143
Operators in C/C++
Operators-computer programming and utilzation
Functions & Procedures [7]
Basic c operators

What's hot (20)

PPT
2. operators in c
PPT
C operators
PPT
Operators in c language
PPTX
C language operators
PPT
Relational operators In C language (By: Shujaat Abbas)
PPTX
Operator in c programming
PPTX
Working with IDE
PPTX
C OPERATOR
PDF
C Building Blocks
DOCX
C programming Lab 1
PPTX
Lect08 exercises
PPT
6 operators-in-c
PPT
Types of operators in C
DOCX
C – operators and expressions
PPT
Mesics lecture 4 c operators and experssions
PPTX
Operators and Expressions in Java
PPT
C operator and expression
PDF
4. operators in c programming by digital wave
PPT
Operators in C++
2. operators in c
C operators
Operators in c language
C language operators
Relational operators In C language (By: Shujaat Abbas)
Operator in c programming
Working with IDE
C OPERATOR
C Building Blocks
C programming Lab 1
Lect08 exercises
6 operators-in-c
Types of operators in C
C – operators and expressions
Mesics lecture 4 c operators and experssions
Operators and Expressions in Java
C operator and expression
4. operators in c programming by digital wave
Operators in C++
Ad

Viewers also liked (14)

PPTX
Arithmetic and logical instructions set
PPTX
Arithmetic instructions
PPT
Arithmetic & logical operations in 8051
PPTX
1.arithmetic & logical operations
PPTX
How to perform well in a job interview
PPTX
Addressing mode & data transfer instruction of 8085
PPT
Complements
PPTX
1's and 2's complement
PPT
Types of instructions
PPTX
1s and 2s complement
PDF
Question paper with solution the 8051 microcontroller based embedded systems...
PPT
Chapter 3 INSTRUCTION SET AND ASSEMBLY LANGUAGE PROGRAMMING
PPTX
Interviewing PPT
Arithmetic and logical instructions set
Arithmetic instructions
Arithmetic & logical operations in 8051
1.arithmetic & logical operations
How to perform well in a job interview
Addressing mode & data transfer instruction of 8085
Complements
1's and 2's complement
Types of instructions
1s and 2s complement
Question paper with solution the 8051 microcontroller based embedded systems...
Chapter 3 INSTRUCTION SET AND ASSEMBLY LANGUAGE PROGRAMMING
Interviewing PPT
Ad

Similar to Arithmetic instructions (20)

PDF
02 - Data Types and Expressions using C.pdf
PPTX
B.sc CSIT 2nd semester C++ Unit2
PDF
ICP - Lecture 5
DOCX
Workshop03.docx lap trinh C cho người mới bắt đầu
PPT
c-programming
PPTX
PPTX
powerpoint presentation on square root factorising
PPTX
CSE115 C Programming Introduction North south university
PPTX
Lecture 7.pptx
PPTX
C operators
PPTX
Java Programming Course for beginners -الدسوقي
PPTX
C-LOOP-Session-2.pptx
PPTX
C Programming Introduction
PPTX
Dti2143 chapter 3 arithmatic relation-logicalexpression
PPTX
C language basics
PPTX
Programming in C by SONU KUMAR.pptx
PPT
slidenotesece246jun2012-140803084954-phpapp01 (1).ppt
PDF
introduction to python programming course 2
PDF
25422733 c-programming-and-data-structures-lab-manual
PPT
Ch02 primitive-data-definite-loops
02 - Data Types and Expressions using C.pdf
B.sc CSIT 2nd semester C++ Unit2
ICP - Lecture 5
Workshop03.docx lap trinh C cho người mới bắt đầu
c-programming
powerpoint presentation on square root factorising
CSE115 C Programming Introduction North south university
Lecture 7.pptx
C operators
Java Programming Course for beginners -الدسوقي
C-LOOP-Session-2.pptx
C Programming Introduction
Dti2143 chapter 3 arithmatic relation-logicalexpression
C language basics
Programming in C by SONU KUMAR.pptx
slidenotesece246jun2012-140803084954-phpapp01 (1).ppt
introduction to python programming course 2
25422733 c-programming-and-data-structures-lab-manual
Ch02 primitive-data-definite-loops

More from Learn By Watch (20)

PPTX
Tutorial 9 fm
PPTX
Phase modulation
PPTX
Demodulation of fm pll detector
PPTX
Demodulation of fm slope and balanced slope detector
PPTX
In direct method of fm generation armstrong method
PPTX
Direct method of fm generation hartley oscillator method
PPTX
Carson's rule
PPTX
Spectrum and power of wbfm
PPTX
Narrow band frequency modulation nbfm
PPTX
General expression of fm signal
PPTX
Angle modulation
PPTX
Frequency division multiplexing
PPTX
Vsb modulation
PPTX
Demodulation of ssb synchronous detector
PPTX
Generarion of ssb phase discrimination method
PPTX
Generarion of ssb frequency discrimination method
PPTX
Ssb modulation
PPTX
Demodulation of dsb sc costas receiver
PPTX
Quadrature carrier multiplexing qam
PPTX
Demodulation of am synchronous detector
Tutorial 9 fm
Phase modulation
Demodulation of fm pll detector
Demodulation of fm slope and balanced slope detector
In direct method of fm generation armstrong method
Direct method of fm generation hartley oscillator method
Carson's rule
Spectrum and power of wbfm
Narrow band frequency modulation nbfm
General expression of fm signal
Angle modulation
Frequency division multiplexing
Vsb modulation
Demodulation of ssb synchronous detector
Generarion of ssb phase discrimination method
Generarion of ssb frequency discrimination method
Ssb modulation
Demodulation of dsb sc costas receiver
Quadrature carrier multiplexing qam
Demodulation of am synchronous detector

Recently uploaded (20)

PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PPTX
Pharma ospi slides which help in ospi learning
PDF
RMMM.pdf make it easy to upload and study
PDF
Classroom Observation Tools for Teachers
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
Cell Structure & Organelles in detailed.
PDF
Insiders guide to clinical Medicine.pdf
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
Complications of Minimal Access Surgery at WLH
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
Basic Mud Logging Guide for educational purpose
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
Lesson notes of climatology university.
PDF
01-Introduction-to-Information-Management.pdf
PPTX
Cell Types and Its function , kingdom of life
PPH.pptx obstetrics and gynecology in nursing
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Anesthesia in Laparoscopic Surgery in India
Renaissance Architecture: A Journey from Faith to Humanism
Pharma ospi slides which help in ospi learning
RMMM.pdf make it easy to upload and study
Classroom Observation Tools for Teachers
2.FourierTransform-ShortQuestionswithAnswers.pdf
O5-L3 Freight Transport Ops (International) V1.pdf
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Cell Structure & Organelles in detailed.
Insiders guide to clinical Medicine.pdf
Abdominal Access Techniques with Prof. Dr. R K Mishra
Complications of Minimal Access Surgery at WLH
human mycosis Human fungal infections are called human mycosis..pptx
Basic Mud Logging Guide for educational purpose
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Lesson notes of climatology university.
01-Introduction-to-Information-Management.pdf
Cell Types and Its function , kingdom of life

Arithmetic instructions

  • 1. C Programming Language By: Yogendra Pal yogendra@learnbywatch.com Dedicated to My mother and Father
  • 2. t y Keep your notebook with you. Write important point and questions that comes in your mind Solve Mind band exercise. C Rewind when not clear Ask Questions by call or SMS or by mail Keep Watching Keep Learning THIS IS ARITHMETIC INSTRUCTIONS 2
  • 3. What do you know? • printf() function? • scanf() function? • How to write a simple C program? • How to compile and run it? • If answers are yes then you can go ahead. 3
  • 4. Problem • Write a program to add two numbers. These numbers must input by user. • For addition (+) we need arithmetic operators. 4
  • 5. Arithmetic Operators • * : multiplication y z 2 4 • / : division • + : addition • - : subtraction 2+4 x • % : modulus operator 6 • Variable = constant; – x = y + z; 5
  • 6. Result of each operator • 2*3=6 • 4/2=2 • 4+2=6 • 4–2=2 • 4%3=1 • 4%2=0 6
  • 7. Some Constraints • Arithmetic operators act on numeric values. – (int/float/char) operator (int/float/char) – character represents numeric (ASCII) value. • Modules operator works only when – int % int (non-zero). • Division operator works only when – (int/float/char) / (non-zero value). 7
  • 8. You must know • int / int = int • (int / float) = float • (float / int) = float • (float / float) = float 8
  • 9. Assignment Operator = • Assign expression value to an identifier. • identifier = expression or variable = constant. • If both operand are of different data types then right side value convert into the data type of left side identifier. • Multiple assignment execute from right to left. – x = y = z = 5. 9
  • 10. More Assignment Operator… • *=, /=, %=, +=, -= know as compound assignment operator. • x += 1; means x = x + 1; • a -= b; means a = a – b; • m %= (n-7); means m = m % (n-7); 10
  • 11. Addition of two numbers start start #include<stdio.h> #include<conio.h> Define a,b,c int a,b,c void main() initialize b,c b = 4, c = 2 { int a, b, c; a=b+c a=b+c b = 4; c = 2; print a print a a = b + c; printf(“%d”,a); getch(); stop stop } 11
  • 12. Unary Operators • Operate upon single operand. • - (unary minus) • + (unary plus) • -- (decrement operator) : decrement by 1 – i--; or --i; equal to i = i -1; • ++ (increment operator) : increment by 1 – i++; or ++i; equal to i = i +1; 12
  • 13. Unary Operator… • sizeof : returns the size (bytes) of operand. – printf(“integer: %d”,sizeof(i)); • Type Cast is also a unary operator. • Type Cast changes the data type of operand. – (Type) operand; – float a = 3.7; – (int)a; 13
  • 14. Operator precedence Operator Operation Precendence () Parentheses Evaluate First, Innermost first, Left to right. -, +, --, ++, Unary operators Right to left sizeof, (type) *, / or % Multiplication, Division or Left to right. modulus + or - Addition and subtraction Left to right. = Assignment (Multiple) Right to left. 14
  • 15. Example of precedence • a=2*3/4+4/4+8–2+5/ (3+1) • a=2*3/4+4/4+8–2+5/ 4 • a=6/4+4/4+8–2+5/ 4 • a=1+4/4+8–2+5/ 4 • a=1+1+8–2+5/ 4 • a=1+1+8–2+1 • a=2+8–2+1 • a = 10 – 2 + 1 • a=8+1 • a=9 15
  • 16. Mind Bend • Calculate the value. – ( 3 * 5.9 – 2 * 6 ) % ( 4 * 8 + 4 ) –2*((8/6)+(4*(9–4))%(3*2–2) – ( 3 * 9 - 3 ) % ( 5 + 3 * 3) / ( 6 - 7 ) 16
  • 17. Calculate the average start start Define a,b,c Define a,b,c initialize b,c initialize b,c a=b+c/2 a=(b+c)/2 print a print a stop stop 17
  • 18. Problem • Write a program to convert a value from kilometer to meter. • Formula to convert km in to meter is: – 1 km = 1000 m so, – n km = 1000 * n m • Now you can solve any formula based problem. 18
  • 19. Problem… • Write a program that convert a lowercase character to uppercase character. • Write a program to calculate the area and circumference of the circle. • Two numbers (x and y) are entered through the keyboard. Write a program to interchange the value of x and y. • Write a program that print reverse of a 5 digit given number. 19
  • 20. Problem… • Write a program that calculate the root of a quadratic equation. – ax2 + bx + c = 0. • Input marks of five subjects of a student and write a program to calculate and print addition and percentage of that student. 20
  • 21. Mind Bend • Write a program that convert a uppercase alphabet to lowercase alphabet. • Write a program to calculate the area and perimeter of rectangle. • Write a program that print reverse of a 3 digit given number. 21
  • 22. To get complete benefit of this tutorial solve all the quiz on www.learnbywatch.com For any problem in this tutorial mail me at yogendra@learnbywatch.com with the subject “C” For Other information mail at info@learnbywatch.com Keep Watching Keep Learning NEXT IS DECISION CONTROL 22