C programming-apurbo datta

Post on 17-Jan-2017

304 views 2 download

transcript

C Programing

Created by 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.

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

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.

variables

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.

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.

(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

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.

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)

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:

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;

   } 

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;