KEMBAR78
INTRODUCTION TO COMPUTER PROGRAMMING | PPTX
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

INTRODUCTION TO COMPUTER PROGRAMMING

  • 1.
  • 2.
    INTRODUCTION TO COMPUTERPROGRAMMING 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 Clanguage needs decisions be taken for desired results which are below • simple if • if-else • else if • switch
  • 4.
  • 5.
    else if Syntax if(condition) statement else if(condition) statement elseif(condition) statement else if(condition) Statement else Statement
  • 6.
    Switch statement Switch statementcan 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 andNested 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) { case1: switch(y) { case 1: case 2: case 3: default } case 2: case 3: default: }
  • 9.
    Manual expression tocomputer based expressions
  • 10.
    Operators • Operators arewords 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 CelsiusTemperature 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 FahrenheitTemperature 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 • Wehave 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; voidmain(void) { int num=2; printf(“Number plus four is”,num+4); }
  • 15.
    Arithmetic Assignment Operator Syntax: Arithmeticop= • += (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 +=,-=,++,-- +=(AdditionAssigment 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 incrementand 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