SlideShare a Scribd company logo
1 of 17
COMPUTER PROGRAMMING
Imtiaz Ali
INTRODUCTION TO COMPUTER PROGRAMMING
1) Decisions in C, simple if, if-else, else if and switch statement,
Nested if and switch.
2) Manual expression to Computer Expressions
3) Operators, Arithmetic and Arithmetic assignment operators
Decisions in C
C language needs decisions be taken for desired results which are
below
• simple if
• if-else
• else if
• switch
Simple if
Syntax
if(condition)
statement
if-else
Syntax
if(condition)
Statement
else
statement
else if
Syntax
if(condition)
statement
else if(condition)
statement
else if(condition)
statement
else if(condition)
Statement
else
Statement
Switch statement
Switch statement can be used instead of simple if, if else and else if
Syntax
int x;
x=value;
switch( x)
{
case 1:
case 2:
case 3:
default:
}
Nested if and Nested switch statement
• If can be nested
• If condition inside if
• Switch can be nested, which means switch inside switch
Syntax
if(condition)
{
if(condition)
printf(“Ok”);
}
int x=value;
int y=value;
switch(x)
{
case 1:
switch(y)
{
case 1:
case 2:
case 3:
default
}
case 2:
case 3:
default:
}
Manual expression to computer based expressions
Operators
• Operators are words or symbols that cause a program to do
something to variables.
• For example, the arithmetic operators (+) and (-) cause a
program to add or subtract two numbers.
• Many different kind of operators
• + Addition
• - Subtraction
• * Multiplication
• / Division
• % Remainder
Fahrenheit to Celsius Temperature conversion
#include<stdio.h>
void main(void)
{
int ftemp,ctemp;
pritnf((“Type temperature in degree fahrenheit”);
scanf((“%d”,&ftemp);
ctemp=(ftemp-32)*5/9;
printf(“Temperature in degree Celsius is %d”,ctemp);
}
Celsius to Fahrenheit Temperature conversion
#include<stdio.h>
void main(void)
{
int ftemp,ctemp;
pritnf((“Type temperature in degree fahrenheit”);
printf(“Temperature in degree Celsius is %d”,ctemp);
}
Operator Precedence
• We have parenthesis around (ftemp-32) known as precedence.
• The fact (*) abd (/) are evaluated before(+) and(-).
• We say that (*) and (/) has higher precedence than (+) and (-).
Remainder Operator
• Remainder operator(sometimes called modulor operator)
may be unfamiliar to you.
• It is used to find remainder when one number is divided by
another
• For example answer=13%5
value is 3
Expressions versus Variables
Days=years*365;
void main(void)
{
int num=2;
printf(“Number plus four is”,num+4);
}
Arithmetic Assignment Operator
Syntax:
Arithmetic op=
• += (Addition Assignment Operator)
• -= (Subtraction Assignment Operator)
• *= (Multiplication Assignment Operator)
• /= (Division Assignment Operator)
• %= (Remainder Assignment Operator)
• a+=1 is same as=> a=a+1
• a-=1 is same as=> a=a-1
• a*=1 is same as=> a=a*1
• a/=1 is same as=> a=a/1
• a%=1 is same as a=a%1
Increment, Decrement Operators
+=,-=,++,--
+=(Addition Assigment Operator)
It is also known as increment operator
Syntax:
variable+=value;
variable=variable+value
-=(Subtraction Assigment Operator)
It is also known as decrement operator
Syntax:
Variable-=value;
variable=variable-value
• Postfix increment and Postfix decrement Operator
• Prefix increment and Prefix decrement Operator
Op++
• It is postfix increment operator
++Op
• It is prefix increment operator
Op--
• It is postfix decrement operator
--Op
• It is prefix decrement operator

More Related Content

What's hot

Operators and expressions
Operators and expressionsOperators and expressions
Operators and expressions
vishaljot_kaur
 

What's hot (20)

Expressions in c++
 Expressions in c++ Expressions in c++
Expressions in c++
 
Operators and expressions in C++
Operators and expressions in C++Operators and expressions in C++
Operators and expressions in C++
 
Operators and Expressions
Operators and ExpressionsOperators and Expressions
Operators and Expressions
 
C OPERATOR
C OPERATORC OPERATOR
C OPERATOR
 
Unit 7. Functions
Unit 7. FunctionsUnit 7. Functions
Unit 7. Functions
 
Introduction to Selection control structures in C++
Introduction to Selection control structures in C++ Introduction to Selection control structures in C++
Introduction to Selection control structures in C++
 
C# operators
C# operatorsC# operators
C# operators
 
Operation and expression in c++
Operation and expression in c++Operation and expression in c++
Operation and expression in c++
 
Operators and expressions
Operators and expressionsOperators and expressions
Operators and expressions
 
[ITP - Lecture 06] Operators, Arithmetic Expression and Order of Precedence
[ITP - Lecture 06] Operators, Arithmetic Expression and Order of Precedence[ITP - Lecture 06] Operators, Arithmetic Expression and Order of Precedence
[ITP - Lecture 06] Operators, Arithmetic Expression and Order of Precedence
 
Operators in C++
Operators in C++Operators in C++
Operators in C++
 
Unit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in cUnit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in c
 
Chap 5 c++
Chap 5 c++Chap 5 c++
Chap 5 c++
 
C – operators and expressions
C – operators and expressionsC – operators and expressions
C – operators and expressions
 
COM1407: Program Control Structures – Decision Making & Branching
COM1407: Program Control Structures – Decision Making & BranchingCOM1407: Program Control Structures – Decision Making & Branching
COM1407: Program Control Structures – Decision Making & Branching
 
Variables, Data Types, Operator & Expression in c in detail
Variables, Data Types, Operator & Expression in c in detailVariables, Data Types, Operator & Expression in c in detail
Variables, Data Types, Operator & Expression in c in detail
 
Parsing
ParsingParsing
Parsing
 
Basic c operators
Basic c operatorsBasic c operators
Basic c operators
 
Operator in c programming
Operator in c programmingOperator in c programming
Operator in c programming
 
Operators in C Programming
Operators in C ProgrammingOperators in C Programming
Operators in C Programming
 

Similar to INTRODUCTION TO COMPUTER PROGRAMMING

Cs1123 4 variables_constants
Cs1123 4 variables_constantsCs1123 4 variables_constants
Cs1123 4 variables_constants
TAlha MAlik
 
Lab 4 reading material formatted io and arithmetic expressions
Lab 4 reading material formatted io and arithmetic expressionsLab 4 reading material formatted io and arithmetic expressions
Lab 4 reading material formatted io and arithmetic expressions
AksharVaish2
 

Similar to INTRODUCTION TO COMPUTER PROGRAMMING (20)

3.Loops_conditionals.pdf
3.Loops_conditionals.pdf3.Loops_conditionals.pdf
3.Loops_conditionals.pdf
 
Control Structures.pptx
Control Structures.pptxControl Structures.pptx
Control Structures.pptx
 
Chaptfffffuuer05.PPT
Chaptfffffuuer05.PPTChaptfffffuuer05.PPT
Chaptfffffuuer05.PPT
 
Learning C programming - from lynxbee.com
Learning C programming - from lynxbee.comLearning C programming - from lynxbee.com
Learning C programming - from lynxbee.com
 
Operators
OperatorsOperators
Operators
 
Control statments in c
Control statments in cControl statments in c
Control statments in c
 
Token and operators
Token and operatorsToken and operators
Token and operators
 
Condition Stmt n Looping stmt.pptx
Condition Stmt n Looping stmt.pptxCondition Stmt n Looping stmt.pptx
Condition Stmt n Looping stmt.pptx
 
Mit6 087 iap10_lec02
Mit6 087 iap10_lec02Mit6 087 iap10_lec02
Mit6 087 iap10_lec02
 
Claguage 110226222227-phpapp02
Claguage 110226222227-phpapp02Claguage 110226222227-phpapp02
Claguage 110226222227-phpapp02
 
Code optimization
Code optimization Code optimization
Code optimization
 
Code optimization
Code optimization Code optimization
Code optimization
 
Programming for Problem Solving
Programming for Problem SolvingProgramming for Problem Solving
Programming for Problem Solving
 
C fundamental
C fundamentalC fundamental
C fundamental
 
Cs1123 4 variables_constants
Cs1123 4 variables_constantsCs1123 4 variables_constants
Cs1123 4 variables_constants
 
Embedded systems
Embedded systemsEmbedded systems
Embedded systems
 
Lab 4 reading material formatted io and arithmetic expressions
Lab 4 reading material formatted io and arithmetic expressionsLab 4 reading material formatted io and arithmetic expressions
Lab 4 reading material formatted io and arithmetic expressions
 
Programming Fundamentals
Programming FundamentalsProgramming Fundamentals
Programming Fundamentals
 
Lecture 3
Lecture 3Lecture 3
Lecture 3
 
Code Tuning
Code TuningCode Tuning
Code Tuning
 

More from imtiazalijoono

More from imtiazalijoono (20)

Embedded systems io programming
Embedded systems   io programmingEmbedded systems   io programming
Embedded systems io programming
 
Embedded systems tools & peripherals
Embedded systems   tools & peripheralsEmbedded systems   tools & peripherals
Embedded systems tools & peripherals
 
Importance of reading and its types.
Importance of reading and its types.Importance of reading and its types.
Importance of reading and its types.
 
Negative amplifiers and its types Positive feedback and Negative feedback
Negative amplifiers and its types Positive feedback  and Negative feedbackNegative amplifiers and its types Positive feedback  and Negative feedback
Negative amplifiers and its types Positive feedback and Negative feedback
 
Multistage amplifiers and Name of coupling Name of multistage amplifier
Multistage amplifiers and Name of coupling Name of multistage amplifierMultistage amplifiers and Name of coupling Name of multistage amplifier
Multistage amplifiers and Name of coupling Name of multistage amplifier
 
Loop Introduction for Loop while Loop do while Loop Nested Loops Values of...
Loop Introduction for Loop  while Loop do while Loop  Nested Loops  Values of...Loop Introduction for Loop  while Loop do while Loop  Nested Loops  Values of...
Loop Introduction for Loop while Loop do while Loop Nested Loops Values of...
 
Programming Fundamentals and basic knowledge
Programming Fundamentals and basic knowledge Programming Fundamentals and basic knowledge
Programming Fundamentals and basic knowledge
 
Programming Fundamentals Functions in C and types
Programming Fundamentals  Functions in C  and typesProgramming Fundamentals  Functions in C  and types
Programming Fundamentals Functions in C and types
 
Software Development Software development process
Software Development Software development processSoftware Development Software development process
Software Development Software development process
 
Programming Fundamentals Decisions
Programming Fundamentals  Decisions Programming Fundamentals  Decisions
Programming Fundamentals Decisions
 
C Building Blocks
C Building Blocks C Building Blocks
C Building Blocks
 
Programming Fundamentals Arrays and Strings
Programming Fundamentals   Arrays and Strings Programming Fundamentals   Arrays and Strings
Programming Fundamentals Arrays and Strings
 
Programming Fundamentals and Programming Languages Concepts Translators
Programming Fundamentals and Programming Languages Concepts TranslatorsProgramming Fundamentals and Programming Languages Concepts Translators
Programming Fundamentals and Programming Languages Concepts Translators
 
Programming Fundamentals and Programming Languages Concepts
Programming Fundamentals and Programming Languages ConceptsProgramming Fundamentals and Programming Languages Concepts
Programming Fundamentals and Programming Languages Concepts
 
Programming Global variable
Programming Global variableProgramming Global variable
Programming Global variable
 
Array Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional arrayArray Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional array
 
NTRODUCTION TO COMPUTER PROGRAMMING Loop as repetitive statement,
NTRODUCTION TO COMPUTER PROGRAMMING Loop as repetitive statement,NTRODUCTION TO COMPUTER PROGRAMMING Loop as repetitive statement,
NTRODUCTION TO COMPUTER PROGRAMMING Loop as repetitive statement,
 
Arithmetic and Arithmetic assignment operators
Arithmetic and Arithmetic assignment operatorsArithmetic and Arithmetic assignment operators
Arithmetic and Arithmetic assignment operators
 
COMPUTER PROGRAMMING
COMPUTER PROGRAMMINGCOMPUTER PROGRAMMING
COMPUTER PROGRAMMING
 
COMPUTER PROGRAMMING
COMPUTER PROGRAMMINGCOMPUTER PROGRAMMING
COMPUTER PROGRAMMING
 

Recently uploaded

1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
AldoGarca30
 
21P35A0312 Internship eccccccReport.docx
21P35A0312 Internship eccccccReport.docx21P35A0312 Internship eccccccReport.docx
21P35A0312 Internship eccccccReport.docx
rahulmanepalli02
 
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
HenryBriggs2
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
Neometrix_Engineering_Pvt_Ltd
 

Recently uploaded (20)

HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
 
Working Principle of Echo Sounder and Doppler Effect.pdf
Working Principle of Echo Sounder and Doppler Effect.pdfWorking Principle of Echo Sounder and Doppler Effect.pdf
Working Principle of Echo Sounder and Doppler Effect.pdf
 
Max. shear stress theory-Maximum Shear Stress Theory ​ Maximum Distortional ...
Max. shear stress theory-Maximum Shear Stress Theory ​  Maximum Distortional ...Max. shear stress theory-Maximum Shear Stress Theory ​  Maximum Distortional ...
Max. shear stress theory-Maximum Shear Stress Theory ​ Maximum Distortional ...
 
Call for Papers - Journal of Electrical Systems (JES), E-ISSN: 1112-5209, ind...
Call for Papers - Journal of Electrical Systems (JES), E-ISSN: 1112-5209, ind...Call for Papers - Journal of Electrical Systems (JES), E-ISSN: 1112-5209, ind...
Call for Papers - Journal of Electrical Systems (JES), E-ISSN: 1112-5209, ind...
 
Dynamo Scripts for Task IDs and Space Naming.pptx
Dynamo Scripts for Task IDs and Space Naming.pptxDynamo Scripts for Task IDs and Space Naming.pptx
Dynamo Scripts for Task IDs and Space Naming.pptx
 
Lect.1: Getting Started (CS771: Machine Learning by Prof. Purushottam Kar, II...
Lect.1: Getting Started (CS771: Machine Learning by Prof. Purushottam Kar, II...Lect.1: Getting Started (CS771: Machine Learning by Prof. Purushottam Kar, II...
Lect.1: Getting Started (CS771: Machine Learning by Prof. Purushottam Kar, II...
 
21P35A0312 Internship eccccccReport.docx
21P35A0312 Internship eccccccReport.docx21P35A0312 Internship eccccccReport.docx
21P35A0312 Internship eccccccReport.docx
 
Presentation on Slab, Beam, Column, and Foundation/Footing
Presentation on Slab,  Beam, Column, and Foundation/FootingPresentation on Slab,  Beam, Column, and Foundation/Footing
Presentation on Slab, Beam, Column, and Foundation/Footing
 
Passive Air Cooling System and Solar Water Heater.ppt
Passive Air Cooling System and Solar Water Heater.pptPassive Air Cooling System and Solar Water Heater.ppt
Passive Air Cooling System and Solar Water Heater.ppt
 
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
 
DFT - Discrete Fourier Transform and its Properties
DFT - Discrete Fourier Transform and its PropertiesDFT - Discrete Fourier Transform and its Properties
DFT - Discrete Fourier Transform and its Properties
 
8th International Conference on Soft Computing, Mathematics and Control (SMC ...
8th International Conference on Soft Computing, Mathematics and Control (SMC ...8th International Conference on Soft Computing, Mathematics and Control (SMC ...
8th International Conference on Soft Computing, Mathematics and Control (SMC ...
 
Fundamentals of Internet of Things (IoT) Part-2
Fundamentals of Internet of Things (IoT) Part-2Fundamentals of Internet of Things (IoT) Part-2
Fundamentals of Internet of Things (IoT) Part-2
 
Autodesk Construction Cloud (Autodesk Build).pptx
Autodesk Construction Cloud (Autodesk Build).pptxAutodesk Construction Cloud (Autodesk Build).pptx
Autodesk Construction Cloud (Autodesk Build).pptx
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
Ground Improvement Technique: Earth Reinforcement
Ground Improvement Technique: Earth ReinforcementGround Improvement Technique: Earth Reinforcement
Ground Improvement Technique: Earth Reinforcement
 
Databricks Generative AI Fundamentals .pdf
Databricks Generative AI Fundamentals  .pdfDatabricks Generative AI Fundamentals  .pdf
Databricks Generative AI Fundamentals .pdf
 
Path loss model, OKUMURA Model, Hata Model
Path loss model, OKUMURA Model, Hata ModelPath loss model, OKUMURA Model, Hata Model
Path loss model, OKUMURA Model, Hata Model
 
Electromagnetic relays used for power system .pptx
Electromagnetic relays used for power system .pptxElectromagnetic relays used for power system .pptx
Electromagnetic relays used for power system .pptx
 

INTRODUCTION TO COMPUTER PROGRAMMING

  • 2. INTRODUCTION TO COMPUTER PROGRAMMING 1) Decisions in C, simple if, if-else, else if and switch statement, Nested if and switch. 2) Manual expression to Computer Expressions 3) Operators, Arithmetic and Arithmetic assignment operators
  • 3. Decisions in C C language needs decisions be taken for desired results which are below • simple if • if-else • else if • switch
  • 5. else if Syntax if(condition) statement else if(condition) statement else if(condition) statement else if(condition) Statement else Statement
  • 6. Switch statement Switch statement can be used instead of simple if, if else and else if Syntax int x; x=value; switch( x) { case 1: case 2: case 3: default: }
  • 7. Nested if and Nested switch statement • If can be nested • If condition inside if • Switch can be nested, which means switch inside switch Syntax if(condition) { if(condition) printf(“Ok”); }
  • 8. int x=value; int y=value; switch(x) { case 1: switch(y) { case 1: case 2: case 3: default } case 2: case 3: default: }
  • 9. Manual expression to computer based expressions
  • 10. Operators • Operators are words or symbols that cause a program to do something to variables. • For example, the arithmetic operators (+) and (-) cause a program to add or subtract two numbers. • Many different kind of operators • + Addition • - Subtraction • * Multiplication • / Division • % Remainder
  • 11. Fahrenheit to Celsius Temperature conversion #include<stdio.h> void main(void) { int ftemp,ctemp; pritnf((“Type temperature in degree fahrenheit”); scanf((“%d”,&ftemp); ctemp=(ftemp-32)*5/9; printf(“Temperature in degree Celsius is %d”,ctemp); }
  • 12. Celsius to Fahrenheit Temperature conversion #include<stdio.h> void main(void) { int ftemp,ctemp; pritnf((“Type temperature in degree fahrenheit”); printf(“Temperature in degree Celsius is %d”,ctemp); }
  • 13. Operator Precedence • We have parenthesis around (ftemp-32) known as precedence. • The fact (*) abd (/) are evaluated before(+) and(-). • We say that (*) and (/) has higher precedence than (+) and (-). Remainder Operator • Remainder operator(sometimes called modulor operator) may be unfamiliar to you. • It is used to find remainder when one number is divided by another • For example answer=13%5 value is 3
  • 14. Expressions versus Variables Days=years*365; void main(void) { int num=2; printf(“Number plus four is”,num+4); }
  • 15. Arithmetic Assignment Operator Syntax: Arithmetic op= • += (Addition Assignment Operator) • -= (Subtraction Assignment Operator) • *= (Multiplication Assignment Operator) • /= (Division Assignment Operator) • %= (Remainder Assignment Operator) • a+=1 is same as=> a=a+1 • a-=1 is same as=> a=a-1 • a*=1 is same as=> a=a*1 • a/=1 is same as=> a=a/1 • a%=1 is same as a=a%1
  • 16. Increment, Decrement Operators +=,-=,++,-- +=(Addition Assigment Operator) It is also known as increment operator Syntax: variable+=value; variable=variable+value -=(Subtraction Assigment Operator) It is also known as decrement operator Syntax: Variable-=value; variable=variable-value
  • 17. • Postfix increment and Postfix decrement Operator • Prefix increment and Prefix decrement Operator Op++ • It is postfix increment operator ++Op • It is prefix increment operator Op-- • It is postfix decrement operator --Op • It is prefix decrement operator