SlideShare a Scribd company logo
1 of 44
C-PROGRAMMING SLIDE-3 	PREPARED BY:- PRADEEP DWIVEDI(pur. B.TECH-IT) 	FROM  HINDUSTAN COLLEGE OF SCIENCE &TECHNOLOGY MOB-+919027843806 E-MAIL-pradeep.it74@gmail.com Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 1
C-3 Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 2 TOPIC:- Operator and expression Conditional or decisional construct.
OPERATOR Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 3 An operator is a symbol that tells the computer to perform certain mathematical and logical manipulation. In c we have three classes of operators.  Unary operator             binary operator       turnery operator (single operand)            (two operand)        (three operand)
OPERATOR Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 4 We have following type of operator Arithmetic operators Relational operators Logical operators Assignment operator Increment and decrement operator Conditional operator Bitwise operator Special operator.
ARITHMETIC OPERATOR Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 5
ARITHMETIC OPERATOR Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 6 Integer arithmetic:- Let a=14,b=4; Then    a-b=10; a+b=18;              a*b=56;               a/b=3;(quotient) a%b=2(remainder)
ARITHMETIC OPERATOR Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 7 Note:-when we have lesser numerator then the denominator that time in the case of division operator answer is always 0. and in case of remainder operator answer is same numerator. 			6/7=0;         -6/-7=0;                             6%7=6;         -6%-7=-6; Note:-during modulo division the sign of result is always the sign of first operand (the divident)                  -14%3=-2;                     -14%-3=-2;                      14%-3=2;
ARITHMETIC OPERATOR Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 8 Real arithmetic:-          x=6.0/7.0=.05743;         y=1.0/3.0=0.333333;         z=-2.0/3.0=-0.666667 Note:- the operator % can not be use real operands. Mixed mode arithmetic:- When one of the operand is real and the other is integer the expression is called a mixed mode arithmetic expression. If either of operand is of the real type than the only real operation is performed and the result is always a real number. 15/10.0=1.5;
PRECEDENCE OF ARITHMETIC OPERATOR Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 9 Higher priority (*,/%) Lower priority (+,-) When we have more than one operator of same priority that time the priority does not matter and associativity comes in picture. And it usually work left to right.
Prog5:- Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 10 /* write a program to convert a temp farenhiet to celcius*/ 	#include<stdio.h> 	#include<conio.h> 	void main() 	{ intfa; 	float c; clrscr(); printf("Enter the farenhite value"); scanf("%d",&fa); 	c=(fa-32)*5.0/9.0; printf("celcius=%f",c); getch(); }
Prog6:- Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 11 /*write a program to convert a given number of days into months and days*/ #include<stdio.h> #include<conio.h> void main() { intmonths,days; printf("Enter days"); scanf("%d",&days); months=days/30; days=days%30; printf("months=%d days=%d",months,days); getch(); }
RELATIONAL OPRATOR Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 12
RELATIONAL OPRATOR Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 13 Eg: 4.5<=10   (true) 4.5<-10     (false) -35>=0        (false) 10<7+5      (true)
RELATIONAL OPERATOR COMLEMENT Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 14
LOGICAL OPERATOR Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 15 We have three logical operators Logical AND(&&) Logical OR(!!) Logical NOT(!) In the case of and operator the answer will be true if both condition’s are true. Otherwise the answer will always be false. In the case of or operator the answer will be false if the both condition are false otherwise the answer will always be true.
NOTE Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 16 Relative precedence of the relational and logical operands is as follows. Highest !                  > >= < <=                 == !=                  && Lowest     !! It is important to remember this when we use these operators is compound expressions.
ASSIGNMENT OPERATOR Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 17 Assignment operator are use to assign the result of an expression to a variable. We have seen the usual assignment operator ‘=‘ . In addition c has a set of ‘shorthand’ assignment operator of the form- Is equivalent to-                    v= v op (exp); V op =exp;
TABLE- SHORT HAND ASSIGNMENT OPERATOR Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 18
CONDITIONAL/DECISIONAL CONSTRUCT Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 19 When we want a selective execution of a program or want to make some decision that time we used conditional or decisional construct. C supports following types of decisional construct:- if  statement switch statement conditional operator statement go to statement
THE IF STATEMENT Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 20 The if statement may be implemented in different forms depending on the complexity of conditions to be tested. the different forms are- simple if statement. if…………..else statement. nested  if…….else statement. else if ladder.
SIMPLE if STATEMENT Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 21 SYNTAX:- 	if(test-expression) { statement-block; } statement-x;
SIMPLE if STATEMENT(flow chart) Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 22
THE if………else STATEMENT Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 23 SYNTAX:- if(test-expression) { true-block statement(s) } else { false-block statement(s) } statement-x;
THE if………else STATEMENT(flow chart) Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 24
NEXTING OF if….else STATEMENTS Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 25 SYNTAX:- if(test condition-1) {  	if(test condition-2) 		{ 		statement-1;             } 		else 		{ 			statement-2;                              }                         }          else  		{ 			statement-3; 		}   statement-x;
NEXTING OF if….else STATEMENTS(flow chart) Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 26
THE else if LADDER Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 27 Syntax:- If(condition-1) 	statetement-1; 	else if(condition-2) 		statement-2; 		else if(condition-3) 		        statement-3; 			else if(condition-n) 				statement-n;  else 	default -statement; statement-x;
THE else if LADDER(flow chart) Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 28
SOME POINTS Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 29 When we have only one condition to check that time we should use the if ……else construct. but if we have multiple condition to check that time we can also use the if ….else but that form is known as nested if…else. when we have the true condition that time if block will execute otherwise only else block will execute. if we have only one statement inside the if or else the curly braces are optional otherwise mandatory. if we don’t want that anything should be happen in false condition that time else is also optional.
Prog 7 Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 30 /*write a program to compare two number*/ #include<stdio.h> #include<conio.h> main() { inta,b; clrscr(); printf("Enter two number"); scanf("%d%d",&a,&b); if(a==b) { printf("both numbers are equal"); } else { printf("both numbers are not equal"); } getch(); return 0; }
Prog 8 Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 31 /*(use of else if ladder) write a prog to check the entered character is vowel or consonant*/ #include<stdio.h> #include<conio.h> void main() { char chr; clrscr(); printf("enter a character "); scanf("%c",&chr); if(chr=='a') printf("the vowel is: %c",chr); else if(chr=='e') printf("the vowel is: %c",chr); else if(chr=='i') printf("the vowel is: %c",chr); else if(chr=='o') printf("the vowel is: %c",chr); else if(chr=='u') printf("the vowel is: %c",chr); else printf("the consonant is: %c",chr); getch(); }
Prog9  Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 32 /*write a program to check the member is voter or not*/ #include<stdio.h> #include<conio.h> void main() { int age; clrscr(); printf("Enter the age of member"); scanf("%d",&age); if(age<18) printf("member is not a voter"); else  printf("member is voter"); getch(); }
THE switch STATEMENT Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 33 switch case is used when we have multiple condition to check. the switch statement tests the value of a given variable(or expression) against a list of case values and when a match is found, a block of statements associated with that case is executed. the syntax of switch statement is as shown in next page.
THE switch STATEMENT Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 34 switch(expression) { case values-1: block-1; break; case value-2: block-2; break; default: default-block; break; } statement-x;
THE switch STATEMENT Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 35 the expression is an integer expression or characters. value-1,value-2,……are constant or constant expressions and are known as case labels. break is a keyword with the help of it we move out from the switch statement. default is an optional case. when present , it will be executed if the value of the expression does not match with any of the case values. if not present, no action takes place if all matches fail and the control goes to the statement-x.
FLOW CHART-selection process of switch statement Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 36
RULES FOR SWITCH STATEMENT Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 37 the switch expression must be an integral type. case labels must be unique. no two labels can have the same value. case labels must end with colon. the break statement transfers the control out of the switch statement. the default label is optional . if present , it will be executed when the expression does not find a matching case labels. there can be at most one default label. the default may be placed anywhere but usually placed at the end. it is permitted to nest switch statement.
prog10 Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 38 /*write a program by using switch case to make a calculator*/ #include<stdio.h> #include<conio.h> void main() { inta,b,c,option; clrscr(); printf("Enter two numbers"); scanf("%d%d",&a,&b); printf("Enter the option which do you wants"); printf("1.Addition"); printf("2.subtraction"); printf("3.multiplication"); printf("4.division"); scanf("%d",&option); switch(option) /*write a program by using switch case to make a calculator*/ #include<stdio.h> #include<conio.h> void main() { inta,b,c,option; clrscr(); printf("Enter two numbers"); scanf("%d%d",&a,&b); printf("Enter the option which do you wants"); printf("1.Addition"); printf("2.subtraction"); printf("3.multiplication"); printf("4.division"); scanf("%d",&option); switch(option)
TURNARY OPERATORY Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 39 This is also termed as conditional operator or The ?:operator. SYNTAX:- The conditional expression is evaluated first. If the result is non-zero, expression is evaluated and is returned as the value of conditional expression. Otherwise, expression2 is evaluated and its value is returned. conditional expression ? expression1:expression2
prog11 Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 40 #include<stdio.h> #include<conio.h> void main() { int num1,num2,max; clrscr(); printf("please insert the value of num1 and num2"); scanf("%d%d",&num1,&num2); max=(num1>num2)?num1:num2; printf("the maximum number is: %d",max); getch(); }
UNARY OPERATOR Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 41 To work on single operand. Increment operator(++) Decrement operator(--) Unary operator can be represented on following ways:- Postfix increment (m++) Prefix increment (++m) Post fix decrement (m--) Prefix decrement (--m)
UNARY OPERATOR Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 42 Postfix:-  If we use postfix increment or decrement that time we first assign or print the value and then increment the value. Prefix:- In prefix increment or decrement we first increment or decrement the value and then assign or print the value. Note:- The precedence and associatively of ++ and --  operators are the same as those of unary + and unary -
prog12 Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 43 /*  Demo for unary operators */ #include<stdio.h> #include<conio.h> void main() { inta,b; clrscr(); a=10; b=a++; printf("the value of a and b: %d %d",a,b); getch(); }
Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 44 		THANK YOU

More Related Content

What's hot (20)

C preprocesor
C preprocesorC preprocesor
C preprocesor
 
Lập trình C
Lập trình CLập trình C
Lập trình C
 
Lập trình C
Lập trình CLập trình C
Lập trình C
 
UNIT-II CP DOC.docx
UNIT-II CP DOC.docxUNIT-II CP DOC.docx
UNIT-II CP DOC.docx
 
Programming in c function
Programming in c functionProgramming in c function
Programming in c function
 
C Prog. - Decision & Loop Controls
C Prog. - Decision & Loop ControlsC Prog. - Decision & Loop Controls
C Prog. - Decision & Loop Controls
 
C programming Workshop
C programming WorkshopC programming Workshop
C programming Workshop
 
Introduction to Basic C programming 02
Introduction to Basic C programming 02Introduction to Basic C programming 02
Introduction to Basic C programming 02
 
C program compiler presentation
C program compiler presentationC program compiler presentation
C program compiler presentation
 
C++ Introduction
C++ IntroductionC++ Introduction
C++ Introduction
 
Programming in C
Programming in CProgramming in C
Programming in C
 
1 introducing c language
1  introducing c language1  introducing c language
1 introducing c language
 
What is c
What is cWhat is c
What is c
 
C structure
C structureC structure
C structure
 
Deep C
Deep CDeep C
Deep C
 
Basic c programming and explanation PPT1
Basic c programming and explanation PPT1Basic c programming and explanation PPT1
Basic c programming and explanation PPT1
 
C fundamentals
C fundamentalsC fundamentals
C fundamentals
 
C programming
C programmingC programming
C programming
 
C formatted and unformatted input and output constructs
C  formatted and unformatted input and output constructsC  formatted and unformatted input and output constructs
C formatted and unformatted input and output constructs
 
F# Eye 4 the C# Guy
F# Eye 4 the C# GuyF# Eye 4 the C# Guy
F# Eye 4 the C# Guy
 

Similar to C programming slide c03

Lecture04 computer applicationsie1_dratifshahzad
Lecture04 computer applicationsie1_dratifshahzadLecture04 computer applicationsie1_dratifshahzad
Lecture04 computer applicationsie1_dratifshahzadAtif Shahzad
 
BPOPS203 PRINCIPLES OF PROGRAMMING USING C LAB Manual.pdf
BPOPS203 PRINCIPLES OF PROGRAMMING USING C LAB Manual.pdfBPOPS203 PRINCIPLES OF PROGRAMMING USING C LAB Manual.pdf
BPOPS203 PRINCIPLES OF PROGRAMMING USING C LAB Manual.pdfSyed Mustafa
 
Control structuresin c
Control structuresin cControl structuresin c
Control structuresin cVikash Dhal
 
Boetticher Presentation Promise 2008v2
Boetticher Presentation Promise 2008v2Boetticher Presentation Promise 2008v2
Boetticher Presentation Promise 2008v2gregoryg
 
单元测试必知必会
单元测试必知必会单元测试必知必会
单元测试必知必会智杰 付
 
Building Hierarchy
Building HierarchyBuilding Hierarchy
Building HierarchyMohamed Samy
 
unit2 C-ProgrammingChapter 2 Control statements.pptx
unit2 C-ProgrammingChapter 2 Control statements.pptxunit2 C-ProgrammingChapter 2 Control statements.pptx
unit2 C-ProgrammingChapter 2 Control statements.pptxJavvajiVenkat
 
Assessing the Reliability of a Human Estimator
Assessing the Reliability of a Human EstimatorAssessing the Reliability of a Human Estimator
Assessing the Reliability of a Human EstimatorTim Menzies
 
R Programming: Comparing Objects In R
R Programming: Comparing Objects In RR Programming: Comparing Objects In R
R Programming: Comparing Objects In RRsquared Academy
 
Compiler Construction | Lecture 2 | Declarative Syntax Definition
Compiler Construction | Lecture 2 | Declarative Syntax DefinitionCompiler Construction | Lecture 2 | Declarative Syntax Definition
Compiler Construction | Lecture 2 | Declarative Syntax DefinitionEelco Visser
 
Bti1022 lab sheet 3
Bti1022 lab sheet 3Bti1022 lab sheet 3
Bti1022 lab sheet 3alish sha
 

Similar to C programming slide c03 (20)

additional.pptx
additional.pptxadditional.pptx
additional.pptx
 
Lecture04 computer applicationsie1_dratifshahzad
Lecture04 computer applicationsie1_dratifshahzadLecture04 computer applicationsie1_dratifshahzad
Lecture04 computer applicationsie1_dratifshahzad
 
BPOPS203 PRINCIPLES OF PROGRAMMING USING C LAB Manual.pdf
BPOPS203 PRINCIPLES OF PROGRAMMING USING C LAB Manual.pdfBPOPS203 PRINCIPLES OF PROGRAMMING USING C LAB Manual.pdf
BPOPS203 PRINCIPLES OF PROGRAMMING USING C LAB Manual.pdf
 
Control structuresin c
Control structuresin cControl structuresin c
Control structuresin c
 
Issta13 workshop on debugging
Issta13 workshop on debuggingIssta13 workshop on debugging
Issta13 workshop on debugging
 
Boetticher Presentation Promise 2008v2
Boetticher Presentation Promise 2008v2Boetticher Presentation Promise 2008v2
Boetticher Presentation Promise 2008v2
 
CST2403 NOTES
CST2403 NOTESCST2403 NOTES
CST2403 NOTES
 
单元测试必知必会
单元测试必知必会单元测试必知必会
单元测试必知必会
 
Building Hierarchy
Building HierarchyBuilding Hierarchy
Building Hierarchy
 
Abhik-Satish-dagstuhl
Abhik-Satish-dagstuhlAbhik-Satish-dagstuhl
Abhik-Satish-dagstuhl
 
Control statments in c
Control statments in cControl statments in c
Control statments in c
 
Pg tap
Pg tapPg tap
Pg tap
 
unit2 C-ProgrammingChapter 2 Control statements.pptx
unit2 C-ProgrammingChapter 2 Control statements.pptxunit2 C-ProgrammingChapter 2 Control statements.pptx
unit2 C-ProgrammingChapter 2 Control statements.pptx
 
Assessing the Reliability of a Human Estimator
Assessing the Reliability of a Human EstimatorAssessing the Reliability of a Human Estimator
Assessing the Reliability of a Human Estimator
 
R Programming: Comparing Objects In R
R Programming: Comparing Objects In RR Programming: Comparing Objects In R
R Programming: Comparing Objects In R
 
Compiler Construction | Lecture 2 | Declarative Syntax Definition
Compiler Construction | Lecture 2 | Declarative Syntax DefinitionCompiler Construction | Lecture 2 | Declarative Syntax Definition
Compiler Construction | Lecture 2 | Declarative Syntax Definition
 
Ocs752 unit 1
Ocs752   unit 1Ocs752   unit 1
Ocs752 unit 1
 
L7 pointers
L7 pointersL7 pointers
L7 pointers
 
Unit3 cspc
Unit3 cspcUnit3 cspc
Unit3 cspc
 
Bti1022 lab sheet 3
Bti1022 lab sheet 3Bti1022 lab sheet 3
Bti1022 lab sheet 3
 

C programming slide c03

  • 1. C-PROGRAMMING SLIDE-3 PREPARED BY:- PRADEEP DWIVEDI(pur. B.TECH-IT) FROM HINDUSTAN COLLEGE OF SCIENCE &TECHNOLOGY MOB-+919027843806 E-MAIL-pradeep.it74@gmail.com Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 1
  • 2. C-3 Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 2 TOPIC:- Operator and expression Conditional or decisional construct.
  • 3. OPERATOR Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 3 An operator is a symbol that tells the computer to perform certain mathematical and logical manipulation. In c we have three classes of operators. Unary operator binary operator turnery operator (single operand) (two operand) (three operand)
  • 4. OPERATOR Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 4 We have following type of operator Arithmetic operators Relational operators Logical operators Assignment operator Increment and decrement operator Conditional operator Bitwise operator Special operator.
  • 5. ARITHMETIC OPERATOR Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 5
  • 6. ARITHMETIC OPERATOR Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 6 Integer arithmetic:- Let a=14,b=4; Then a-b=10; a+b=18; a*b=56; a/b=3;(quotient) a%b=2(remainder)
  • 7. ARITHMETIC OPERATOR Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 7 Note:-when we have lesser numerator then the denominator that time in the case of division operator answer is always 0. and in case of remainder operator answer is same numerator. 6/7=0; -6/-7=0; 6%7=6; -6%-7=-6; Note:-during modulo division the sign of result is always the sign of first operand (the divident) -14%3=-2; -14%-3=-2; 14%-3=2;
  • 8. ARITHMETIC OPERATOR Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 8 Real arithmetic:- x=6.0/7.0=.05743; y=1.0/3.0=0.333333; z=-2.0/3.0=-0.666667 Note:- the operator % can not be use real operands. Mixed mode arithmetic:- When one of the operand is real and the other is integer the expression is called a mixed mode arithmetic expression. If either of operand is of the real type than the only real operation is performed and the result is always a real number. 15/10.0=1.5;
  • 9. PRECEDENCE OF ARITHMETIC OPERATOR Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 9 Higher priority (*,/%) Lower priority (+,-) When we have more than one operator of same priority that time the priority does not matter and associativity comes in picture. And it usually work left to right.
  • 10. Prog5:- Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 10 /* write a program to convert a temp farenhiet to celcius*/ #include<stdio.h> #include<conio.h> void main() { intfa; float c; clrscr(); printf("Enter the farenhite value"); scanf("%d",&fa); c=(fa-32)*5.0/9.0; printf("celcius=%f",c); getch(); }
  • 11. Prog6:- Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 11 /*write a program to convert a given number of days into months and days*/ #include<stdio.h> #include<conio.h> void main() { intmonths,days; printf("Enter days"); scanf("%d",&days); months=days/30; days=days%30; printf("months=%d days=%d",months,days); getch(); }
  • 12. RELATIONAL OPRATOR Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 12
  • 13. RELATIONAL OPRATOR Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 13 Eg: 4.5<=10 (true) 4.5<-10 (false) -35>=0 (false) 10<7+5 (true)
  • 14. RELATIONAL OPERATOR COMLEMENT Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 14
  • 15. LOGICAL OPERATOR Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 15 We have three logical operators Logical AND(&&) Logical OR(!!) Logical NOT(!) In the case of and operator the answer will be true if both condition’s are true. Otherwise the answer will always be false. In the case of or operator the answer will be false if the both condition are false otherwise the answer will always be true.
  • 16. NOTE Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 16 Relative precedence of the relational and logical operands is as follows. Highest ! > >= < <= == != && Lowest !! It is important to remember this when we use these operators is compound expressions.
  • 17. ASSIGNMENT OPERATOR Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 17 Assignment operator are use to assign the result of an expression to a variable. We have seen the usual assignment operator ‘=‘ . In addition c has a set of ‘shorthand’ assignment operator of the form- Is equivalent to- v= v op (exp); V op =exp;
  • 18. TABLE- SHORT HAND ASSIGNMENT OPERATOR Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 18
  • 19. CONDITIONAL/DECISIONAL CONSTRUCT Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 19 When we want a selective execution of a program or want to make some decision that time we used conditional or decisional construct. C supports following types of decisional construct:- if statement switch statement conditional operator statement go to statement
  • 20. THE IF STATEMENT Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 20 The if statement may be implemented in different forms depending on the complexity of conditions to be tested. the different forms are- simple if statement. if…………..else statement. nested if…….else statement. else if ladder.
  • 21. SIMPLE if STATEMENT Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 21 SYNTAX:- if(test-expression) { statement-block; } statement-x;
  • 22. SIMPLE if STATEMENT(flow chart) Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 22
  • 23. THE if………else STATEMENT Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 23 SYNTAX:- if(test-expression) { true-block statement(s) } else { false-block statement(s) } statement-x;
  • 24. THE if………else STATEMENT(flow chart) Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 24
  • 25. NEXTING OF if….else STATEMENTS Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 25 SYNTAX:- if(test condition-1) { if(test condition-2) { statement-1; } else { statement-2; } } else { statement-3; } statement-x;
  • 26. NEXTING OF if….else STATEMENTS(flow chart) Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 26
  • 27. THE else if LADDER Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 27 Syntax:- If(condition-1) statetement-1; else if(condition-2) statement-2; else if(condition-3) statement-3; else if(condition-n) statement-n; else default -statement; statement-x;
  • 28. THE else if LADDER(flow chart) Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 28
  • 29. SOME POINTS Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 29 When we have only one condition to check that time we should use the if ……else construct. but if we have multiple condition to check that time we can also use the if ….else but that form is known as nested if…else. when we have the true condition that time if block will execute otherwise only else block will execute. if we have only one statement inside the if or else the curly braces are optional otherwise mandatory. if we don’t want that anything should be happen in false condition that time else is also optional.
  • 30. Prog 7 Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 30 /*write a program to compare two number*/ #include<stdio.h> #include<conio.h> main() { inta,b; clrscr(); printf("Enter two number"); scanf("%d%d",&a,&b); if(a==b) { printf("both numbers are equal"); } else { printf("both numbers are not equal"); } getch(); return 0; }
  • 31. Prog 8 Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 31 /*(use of else if ladder) write a prog to check the entered character is vowel or consonant*/ #include<stdio.h> #include<conio.h> void main() { char chr; clrscr(); printf("enter a character "); scanf("%c",&chr); if(chr=='a') printf("the vowel is: %c",chr); else if(chr=='e') printf("the vowel is: %c",chr); else if(chr=='i') printf("the vowel is: %c",chr); else if(chr=='o') printf("the vowel is: %c",chr); else if(chr=='u') printf("the vowel is: %c",chr); else printf("the consonant is: %c",chr); getch(); }
  • 32. Prog9 Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 32 /*write a program to check the member is voter or not*/ #include<stdio.h> #include<conio.h> void main() { int age; clrscr(); printf("Enter the age of member"); scanf("%d",&age); if(age<18) printf("member is not a voter"); else printf("member is voter"); getch(); }
  • 33. THE switch STATEMENT Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 33 switch case is used when we have multiple condition to check. the switch statement tests the value of a given variable(or expression) against a list of case values and when a match is found, a block of statements associated with that case is executed. the syntax of switch statement is as shown in next page.
  • 34. THE switch STATEMENT Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 34 switch(expression) { case values-1: block-1; break; case value-2: block-2; break; default: default-block; break; } statement-x;
  • 35. THE switch STATEMENT Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 35 the expression is an integer expression or characters. value-1,value-2,……are constant or constant expressions and are known as case labels. break is a keyword with the help of it we move out from the switch statement. default is an optional case. when present , it will be executed if the value of the expression does not match with any of the case values. if not present, no action takes place if all matches fail and the control goes to the statement-x.
  • 36. FLOW CHART-selection process of switch statement Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 36
  • 37. RULES FOR SWITCH STATEMENT Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 37 the switch expression must be an integral type. case labels must be unique. no two labels can have the same value. case labels must end with colon. the break statement transfers the control out of the switch statement. the default label is optional . if present , it will be executed when the expression does not find a matching case labels. there can be at most one default label. the default may be placed anywhere but usually placed at the end. it is permitted to nest switch statement.
  • 38. prog10 Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 38 /*write a program by using switch case to make a calculator*/ #include<stdio.h> #include<conio.h> void main() { inta,b,c,option; clrscr(); printf("Enter two numbers"); scanf("%d%d",&a,&b); printf("Enter the option which do you wants"); printf("1.Addition"); printf("2.subtraction"); printf("3.multiplication"); printf("4.division"); scanf("%d",&option); switch(option) /*write a program by using switch case to make a calculator*/ #include<stdio.h> #include<conio.h> void main() { inta,b,c,option; clrscr(); printf("Enter two numbers"); scanf("%d%d",&a,&b); printf("Enter the option which do you wants"); printf("1.Addition"); printf("2.subtraction"); printf("3.multiplication"); printf("4.division"); scanf("%d",&option); switch(option)
  • 39. TURNARY OPERATORY Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 39 This is also termed as conditional operator or The ?:operator. SYNTAX:- The conditional expression is evaluated first. If the result is non-zero, expression is evaluated and is returned as the value of conditional expression. Otherwise, expression2 is evaluated and its value is returned. conditional expression ? expression1:expression2
  • 40. prog11 Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 40 #include<stdio.h> #include<conio.h> void main() { int num1,num2,max; clrscr(); printf("please insert the value of num1 and num2"); scanf("%d%d",&num1,&num2); max=(num1>num2)?num1:num2; printf("the maximum number is: %d",max); getch(); }
  • 41. UNARY OPERATOR Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 41 To work on single operand. Increment operator(++) Decrement operator(--) Unary operator can be represented on following ways:- Postfix increment (m++) Prefix increment (++m) Post fix decrement (m--) Prefix decrement (--m)
  • 42. UNARY OPERATOR Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 42 Postfix:- If we use postfix increment or decrement that time we first assign or print the value and then increment the value. Prefix:- In prefix increment or decrement we first increment or decrement the value and then assign or print the value. Note:- The precedence and associatively of ++ and -- operators are the same as those of unary + and unary -
  • 43. prog12 Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 43 /* Demo for unary operators */ #include<stdio.h> #include<conio.h> void main() { inta,b; clrscr(); a=10; b=a++; printf("the value of a and b: %d %d",a,b); getch(); }
  • 44. Wednesday, August 25, 2010 PRADEEP DWIVEDI (pur.B.TECH-IT) 44 THANK YOU