 Every C program requires a main() function where
the program execution begins.
 C programs are written in lowercase letters.
 Every program statement in C program must ends
with a semicolon.
 All variables muat be declared for their types
before they are used in the proggram.
 Compiler directive such as #define or #include are
special instructions to the compiler to help it
compile a program. They do not ends with
semicolon.
 Every opening braces must have a corresponding
closing brace.
POINTS TO REMEMBER
 An operator is a symbol that tells the compiler
to perform certain mathematical or logical
manipulations. C operators can be classified
into a number of catergories :-
OPERATOR & EXPRESSION
 Arithmetic Operators + - * / %
 Relational Operators > < >= <= == !=
 Logical Operators && (and) || (or) !(not)
 Assignment Operators =
 Increment & decrement Operators ++ --
 Ternary Operators exp1? exp2 :exp3;
 Bitwise Operator
 Special Operator ( Sizeof, pointer etc)
TYPES OF OPERATORS
Simple Assignment Short hand Assignment
a=a+1 a + = 1
a=a-1 a - = 1
a=a*1 a * = 1
a=a/1 a / = 1
a=a%1 a % = 1
Short hand Assignment Operator
Algebric Expression C Expression
a x b –c a * b –c
(m +n) (x – y) (m+ n)*(x-y)
a *b/c
3x2
+2x+1 3*x*x+2*x+1
ARITHMETIC EXPRESSION
High Priority * / %
Low Priority + -
1) x=9 -12/3 + 3*2 -1
2) x=9 – 12/6 * (2-1)
3) x=5*16/2 %3
PRECEDENCE OF ARITHMETIC
OPERATOR
Types
If else Switch
Conditional statements
If(condition)
{
//do something if TRUE
}
else {
//do something if FALSE
}
If else
#include<stdio.h>
int main() {
int n;
printf(“Enter a Number”,&n);
if(n%2==0)
printf(“Even Non”);
else
printf(“Odd Non”);
}
Input a number & display it is even
or odd number.
 Input two numbers and display their highest.
 Input a number and display it is postive or
negetive number.
 Input age of a person and display he a Voter or
NonVoter.
 Input three angles of a triangle and check
wheather the triangle is possible or not.
 Input marks of a students in thee subject and
display his Total, Average and grade.
Conditional Programs

operator and expression in c program.pptx

  • 1.
     Every Cprogram requires a main() function where the program execution begins.  C programs are written in lowercase letters.  Every program statement in C program must ends with a semicolon.  All variables muat be declared for their types before they are used in the proggram.  Compiler directive such as #define or #include are special instructions to the compiler to help it compile a program. They do not ends with semicolon.  Every opening braces must have a corresponding closing brace. POINTS TO REMEMBER
  • 2.
     An operatoris a symbol that tells the compiler to perform certain mathematical or logical manipulations. C operators can be classified into a number of catergories :- OPERATOR & EXPRESSION
  • 3.
     Arithmetic Operators+ - * / %  Relational Operators > < >= <= == !=  Logical Operators && (and) || (or) !(not)  Assignment Operators =  Increment & decrement Operators ++ --  Ternary Operators exp1? exp2 :exp3;  Bitwise Operator  Special Operator ( Sizeof, pointer etc) TYPES OF OPERATORS
  • 4.
    Simple Assignment Shorthand Assignment a=a+1 a + = 1 a=a-1 a - = 1 a=a*1 a * = 1 a=a/1 a / = 1 a=a%1 a % = 1 Short hand Assignment Operator
  • 5.
    Algebric Expression CExpression a x b –c a * b –c (m +n) (x – y) (m+ n)*(x-y) a *b/c 3x2 +2x+1 3*x*x+2*x+1 ARITHMETIC EXPRESSION
  • 6.
    High Priority */ % Low Priority + - 1) x=9 -12/3 + 3*2 -1 2) x=9 – 12/6 * (2-1) 3) x=5*16/2 %3 PRECEDENCE OF ARITHMETIC OPERATOR
  • 7.
  • 8.
    If(condition) { //do something ifTRUE } else { //do something if FALSE } If else
  • 9.
    #include<stdio.h> int main() { intn; printf(“Enter a Number”,&n); if(n%2==0) printf(“Even Non”); else printf(“Odd Non”); } Input a number & display it is even or odd number.
  • 10.
     Input twonumbers and display their highest.  Input a number and display it is postive or negetive number.  Input age of a person and display he a Voter or NonVoter.  Input three angles of a triangle and check wheather the triangle is possible or not.  Input marks of a students in thee subject and display his Total, Average and grade. Conditional Programs