c programming-apurbo datta

53
C Programing Created by APURBO DATTA

Upload: apurbo-datta

Post on 17-Jan-2017

305 views

Category:

Education


2 download

TRANSCRIPT

Page 1: C programming-apurbo datta

C Programing

Created by APURBO DATTA

Page 2: C programming-apurbo datta

What is programing

A programming language is a formal computer language or constructed language designed to communicate instructions to a machine, particularly a computer. Programming languages can be used to create programs to control the behavior of a machine or to express algorithms.

Page 3: C programming-apurbo datta

Language year Developed ByALGOL 1960 International GroupBPCL 1967 Martin RichardsB 1970 Ken ThompsonTraditional C 1972 Dennis RitchieK & R C 1978 Kernighan & Dennis

RitchieANSI C 1989 ANSI CommitteeANSI/ISO C 1990 ISO CommitteeC99 1999 Standardization

Committee

Page 4: C programming-apurbo datta

What is C Programing

• C is a high-level and general purpose programming language that is ideal for developing firmware or portable applications. Originally intended for writing system software, C was developed at Bell Labs by Dennis Ritchie for the Unix Operating System (OS) in the early 1970s.

Page 5: C programming-apurbo datta
Page 6: C programming-apurbo datta
Page 7: C programming-apurbo datta
Page 8: C programming-apurbo datta
Page 9: C programming-apurbo datta

variables

Page 10: C programming-apurbo datta
Page 11: C programming-apurbo datta
Page 12: C programming-apurbo datta
Page 13: C programming-apurbo datta

NOT Operator (!)The NOT operator (!) is used to reverse the results. This operator is mainly used as a key in big complex programs. By using this operator we can reverse the condition easily. Lets try to understand it with an example.If ( !(y>6) )In the above statement I am writing a condition that y should be lesser than or equal to 6. I can also write the same condition asIf (y<=6)Both the statements will give the same results. You can use anyone of them.

Page 14: C programming-apurbo datta

Hierarchy of OperatorsI have given the hierarchy of operators after arithmetic operators. Now we

have learnt about the logical operators (AND OR NOT) too. So the new hierarchy of operators is given below.

Page 15: C programming-apurbo datta

(Expression 1 ? expression 2 : expression 3)It is generally used to avoid small if-else statement. Remember it is not the alternative of if-else clauses. It can used at some places.Lets try to understand it with some simple example.if (x==10)   Y=3;else   Y=9;In the above we are basically checking if x is equal to 10. If condition turns true then it will assign y as 3. Otherwise it will assign y as 9. The same task can be completed using ternary operator.Y=(x==10 ? 3 : 9);

Conditional OperatorsThey are also called ternary operators. As we have to use three arguments to use this operator.

General form of Conditional/Ternary operator

Page 16: C programming-apurbo datta

Nested Conditional OperatorWell nested conditional operators are used very rarely but they are good to make the program compact.A small example of nested ternary operator is given belowSmall = ( x < y ? ( x > z ? 9: 10 ) : ( y > z ? 14: 16 ) ) ;In the above example small is the variable and it will store9 if x<y and x>z10 if x<y and x<z14 if x>y and y>z16 if x>y and y<zSounds confusing? Well that’s why they are used rarely. But like our example, it can sometimes make the program compact.

Page 17: C programming-apurbo datta
Page 18: C programming-apurbo datta
Page 19: C programming-apurbo datta
Page 20: C programming-apurbo datta
Page 21: C programming-apurbo datta
Page 22: C programming-apurbo datta
Page 23: C programming-apurbo datta
Page 24: C programming-apurbo datta
Page 25: C programming-apurbo datta

Switch statement:The switch statement is also an selection statement.It is mostly a matter of preferencewhich you use,if we want to perform addition,subtraction,multiplication and division at your selection this can be done by switch statement.The syntax of switch statement is as follows     switch(expression)

Page 26: C programming-apurbo datta

A do-while statement is a looped structure which is repeated for that particular condition. The

syntax of do-while statement is as follows

Do-while statement:

Page 27: C programming-apurbo datta

While loop:This statement is also a looped structure, in this we pass some condition in while if that

condition is true the loop will continue if it is false the loop terminate.

Let us see the syntax

   while(condition is true)

   {

     action 1;

   } 

Page 28: C programming-apurbo datta

example:

for(i=1;i<=n;i++)

{

  f=f*i;

}

For loop:This statement is very simpler than the other statements in this we declare initialization

value, test value and increment or decrement at a time. Let us see the syntax and one example

of this statement

     for(initial value;test;increment or decrement)

      {

        action 1;

      }

        action 2;

Page 29: C programming-apurbo datta
Page 30: C programming-apurbo datta
Page 31: C programming-apurbo datta
Page 32: C programming-apurbo datta
Page 33: C programming-apurbo datta
Page 34: C programming-apurbo datta
Page 35: C programming-apurbo datta
Page 36: C programming-apurbo datta
Page 37: C programming-apurbo datta
Page 38: C programming-apurbo datta
Page 39: C programming-apurbo datta
Page 40: C programming-apurbo datta
Page 41: C programming-apurbo datta
Page 42: C programming-apurbo datta
Page 43: C programming-apurbo datta
Page 44: C programming-apurbo datta
Page 45: C programming-apurbo datta
Page 46: C programming-apurbo datta
Page 47: C programming-apurbo datta
Page 48: C programming-apurbo datta
Page 49: C programming-apurbo datta
Page 50: C programming-apurbo datta
Page 51: C programming-apurbo datta
Page 52: C programming-apurbo datta
Page 53: C programming-apurbo datta