Fundamental structure  of  programming in 'c'<br />Presented by:<br />Mr. Yogesh Kumar<br />M.Sc. I Sem.(Bioinformatics)<b...
         Getting started with       'c'<br />‘C’ language is simple as compare to the English language<br />Here is steps ...
                Concept  of Algorithm<br />Before planning a program we need to define its logic (the correct sequence of ...
      Concept of flowchart<br />Flowchart is the diagrammatic representation of programs and algorithm . it is generally u...
Only a few symbols  are needed to indicate the  necessary operations in a flowchart. These basic flowchart symbols have be...
Flowchar  to print first 10 multiple of a given natural numbers  using while <br />     example.1                         ...
Tokens in ‘c’<br />
constant’s , variable’s & keyword’s<br />The alphabets ,numbers and special symbols when properly combined form constants ...
Variables and constant in ‘c’.constant is an entity that doesn’t change                                                xx ...
           Types of c constants1.Primary constant 2.Secondary constant<br />PRIMARY CONSTANT<br />SECONDARY CONSTANT<br />...
Types of c variables<br />As we saw earlier , an entity that  may vary during program execution is called a variable.<br /...
                     C keywords<br />Keywords are the words whose meaning has already been explained to the c compiler <br...
                          'C'   operators<br />
Increment and decrement         operators<br />‘C’ has two most useful operators <br />Increment operator    ++ ,(m++)or m...
       Example of conditional operator#include<stdio.h>                         #include<conio.h>                         ...
         TYPES OF PROGRAMMING IN                    'C'                                                            <br />
    Decesion making and branching<br />Decision  statements<br />if statement<br />if else statement<br />switch statement...
     If statement (DECESSION STATEMENT)<br />The general form of if statement is<br />                 if ( condition)<br ...
#include<stdio.h><br />#include<conio.h><br />void main()<br />{<br />float  a,b,big;<br />printf(“enter two numbersn”);<b...
condition<br />Statement-block<br />
            if .....else statement<br />                        if (condition)<br />                          {           ...
Condition<br />?<br />Statement-2<br />Statement-1<br />
         switch statement<br />The switch statement test the value of given expression against a list of case values <br /...
      Example of switch statement<br />#include<stdio.h><br />#include<conio.h><br />void main()<br />{<br />char  grade;<...
There are two types of repetitive structures<br />Conditional controlled (in this body is repetitively executed until the ...
evaluate  the condition.<br />If the condition  true then execute the statement(s)and repeat step 1.<br />If the condition...
Flowchar  to print first 10 multiple of a given natural numbers  using while <br />                                       ...
In while statement, condition is evaluated first. Therefore the body of loop may not be executed at all if condition is no...
            #include<stdio.><br />                 main( )<br />              { <br />int num=1,s=0;<br />                ...
       While loop verses  Do loop<br /><ul><li>The difference b/w. while & do while loop</li></ul>In while the condition  ...
There are situation where you want to have a statement or group of statements to be executed numbers of time and the numbe...
                   #include<stdio.h><br />                   main( )<br />              {<br />int I,s=0;<br />           ...
                Nested for loop <br />Loop construct can be nested or embedded within one another. The inner loop must be ...
                         Odd loop<br />The loop that we have used so far executed the statements within them a finite numb...
THANK YOU ……. .<br />
ANY  QUERIES??<br />
Upcoming SlideShare
Loading in …5
×

C laguage

2,077 views

Published on

this presentation teach u c language and it brlon to yogesh kumar

Published in: Education
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,077
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
101
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

C laguage

  1. 1. Fundamental structure of programming in 'c'<br />Presented by:<br />Mr. Yogesh Kumar<br />M.Sc. I Sem.(Bioinformatics)<br />
  2. 2. Getting started with 'c'<br />‘C’ language is simple as compare to the English language<br />Here is steps comparison…<br />Steps in learning English language<br />Steps in learning ‘c’<br />alphabets<br />words<br />sentences<br />paragraph<br />Constants, variables<br />keywords<br />Alphabets , digits<br />Special symbols<br />program<br />instructions<br />
  3. 3. Concept of Algorithm<br />Before planning a program we need to define its logic (the correct sequence of instructions need to solve the problem at hand).the term algorithm is often used to refer to the logic of a program.<br /> It is a step by step description of how to arrive at the solution of the given problem.(exp..)<br />*Write a program to find the larger of two given numbers.<br />Algorithm.<br />1.Input two numbers a and b<br />2.Assign big=a<br />3. If (b>big)the big=b<br />4.Output big<br />5.stop<br />
  4. 4. Concept of flowchart<br />Flowchart is the diagrammatic representation of programs and algorithm . it is generally used to understand the program and to solve the program<br />It uses boxes of different shapes to denote different types of instructions.<br />The process of drawing a flowchart for an algorithm is often referred to flowcharting<br />
  5. 5. Only a few symbols are needed to indicate the necessary operations in a flowchart. These basic flowchart symbols have been standardized by the American National standards institute (ANSI). <br />As shown……<br /> flow lines<br /> connector <br /> Basic flowchart symbols<br />start<br />processing<br />Input/output<br />decision<br />
  6. 6. Flowchar to print first 10 multiple of a given natural numbers using while <br /> example.1 <br /> no<br /> yes<br />start<br />Read num<br />i=1<br />Is<br />i<=10<br />stop<br />Write<br />(i*num)<br />i=i+1<br />
  7. 7. Tokens in ‘c’<br />
  8. 8. constant’s , variable’s & keyword’s<br />The alphabets ,numbers and special symbols when properly combined form constants , variables & keywords<br />Alphabets A,B,C………..Z<br /> a , b, c ……....z <br />Digits 0,1,2,3……….9<br />Special symbols ~, ’, !, @, #, %, ^, &, =,|,?, /, <br /> [ ] : ; ””,’ <> ., { }<br />
  9. 9. Variables and constant in ‘c’.constant is an entity that doesn’t change xx =3x x=5 we can’t change 3&5 so it is called constant Here at one memory location we can store one value ,we can’t over write it as against this 3&5 do not change , hence are known as constant <br />
  10. 10. Types of c constants1.Primary constant 2.Secondary constant<br />PRIMARY CONSTANT<br />SECONDARY CONSTANT<br />Integer constant<br />Real constant<br />Character constant<br />Array<br />Pointer<br />Structure<br />Union<br />Enum.etc<br />
  11. 11. Types of c variables<br />As we saw earlier , an entity that may vary during program execution is called a variable.<br />Type of variable used in program depend on the type of constant stored in it.<br />Float/real, integer ,or character constant<br />Variable name are name given to locations in memory<br />Exp….<br />float=6.0 (4 byte)<br />Int =6 (2 byte)<br />char=‘a’ (1 byte)<br />
  12. 12. C keywords<br />Keywords are the words whose meaning has already been explained to the c compiler <br />The keywords cannot be used as variable name if we do so, we are typing to assign new value to keywords which is not allowed by compiler <br />There are 32 keywords available in c<br />Some are …….<br />short return double switch register signed<br />long void float union static unsigned<br />int break if goto continue volatile<br />char default for do sizeofenum<br />else case while auto extern typedef ..etc<br />
  13. 13.
  14. 14. 'C' operators<br />
  15. 15.
  16. 16.
  17. 17.
  18. 18. Increment and decrement operators<br />‘C’ has two most useful operators <br />Increment operator ++ ,(m++)or m=m+1<br />Decrement operator -- ,(m--) or m=m-1 <br />m++ simply increase the value by 1<br />m– -simply decrease the value by 1 <br />Conditional operator<br />A ternary operator “?” is used in c to construct conditional expression of the form <br />Expression1 ? Expression2 : expression3;<br />
  19. 19. Example of conditional operator#include<stdio.h> #include<conio.h> void main() { float x,y,big; printf("enter the two valuesn"); scanf("%f%f",&x,&y); big=(x>y? x:y); printf("the largest number is %fn",big); } Run Enter the two number 12 45.70 the largest number is 45.70<br />
  20. 20. TYPES OF PROGRAMMING IN 'C' <br />
  21. 21. Decesion making and branching<br />Decision statements<br />if statement<br />if else statement<br />switch statement<br />Repetitive statements:<br />while loop<br />do while<br />for loop<br />
  22. 22. If statement (DECESSION STATEMENT)<br />The general form of if statement is<br /> if ( condition)<br /> {<br /> Statement-block<br /> }<br />If condition is true the statement block will executed otherwise the statement block will skipped.<br />
  23. 23. #include<stdio.h><br />#include<conio.h><br />void main()<br />{<br />float a,b,big;<br />printf(“enter two numbersn”);<br />scanf(“%f%f”,&a,&b);<br />big=a;<br />if(b>big) big=b;<br />printf(“larger number is:%f”,big);<br />}<br />RUN<br />Enter two numbers<br />12.5 45.0<br />Larger number is 45.0<br /> if statement example<br />
  24. 24. condition<br />Statement-block<br />
  25. 25. if .....else statement<br /> if (condition)<br /> { <br /> statement-1;<br /> }<br /> else<br /> { <br /> statement-2;<br /> }<br />
  26. 26. Condition<br />?<br />Statement-2<br />Statement-1<br />
  27. 27. switch statement<br />The switch statement test the value of given expression against a list of case values <br />General form<br /> switch(expression)<br /> {<br /> case val-1:<br /> statement-1<br /> break;<br /> case val-2:<br /> statement-2;<br /> break;<br /> default:<br /> default-statement;<br /> break;<br />
  28. 28. Example of switch statement<br />#include<stdio.h><br />#include<conio.h><br />void main()<br />{<br />char grade;<br />switch(grade)<br />{<br />case ‘A’:<br />printf(“passed with first division”);<br />break;<br />case ‘B’:<br />printf(“passed with second division”);<br />break;<br />case ‘C’:<br />printf(“conditional pass”;<br />break;<br />default:<br />printf(“fail”);<br />break;<br />}<br />getch();<br />}<br />
  29. 29. There are two types of repetitive structures<br />Conditional controlled (in this body is repetitively executed until the given condition become true)<br />while statement<br />do while statement<br />Counter controlled (in this the number of time the set of statement is executed ex.. )For loop<br />while statement<br /> while(condition)<br /> {<br /> Statement(s);<br /> }<br /> Repetitive structures<br />
  30. 30. evaluate the condition.<br />If the condition true then execute the statement(s)and repeat step 1.<br />If the condition is false then the control is transferred out of loop.<br />Exp…..<br />#include<stdio.h><br />main()<br />{<br />int num=1,s=0;<br /> While(num<=10)<br />{<br /> sum +=num;<br /> num+1=1;<br />}<br />printf(“sum of first 10 natural numbers : %d ”, s);<br />getch();<br />}<br /> RUN<br /> Sum of first 10 natural num is : 55<br />
  31. 31. Flowchar to print first 10 multiple of a given natural numbers using while <br /> no<br /> yes<br />start<br />Read num<br />i=1<br />Is<br />i<=10<br />stop<br />Write<br />(i*num)<br />i=i+1<br />
  32. 32. In while statement, condition is evaluated first. Therefore the body of loop may not be executed at all if condition is not satisfied at the very first attempt. But in do loop, condition is evaluated at the end. Therefore the body of the loop is executed at lest once in this statement <br />The general form of this statement is..<br /> do<br /> { <br /> Statement(s); <br /> }<br /> while (condition);<br />printf(“…………….”);<br /> }<br />
  33. 33. #include<stdio.><br /> main( )<br /> { <br />int num=1,s=0;<br /> do<br /> {<br /> s +=num;<br /> num +=1;<br /> }<br /> while(num<=10);<br />printf(“sum of first natural no is %d”,s) ;<br />getch(); <br /> }<br />Run:<br />Sum of 10 natural number is 55. <br />
  34. 34. While loop verses Do loop<br /><ul><li>The difference b/w. while & do while loop</li></ul>In while the condition is tested before executing body of loop. /In do while the condition is tested after executing the body <br />Body of do loop is executed at lest once but body of while loop may not be executed at all. /In while , If initial the condition is not satisfied the loop will to get executed even once<br />
  35. 35. There are situation where you want to have a statement or group of statements to be executed numbers of time and the number of repetition does not depend on the condition but it is simply a repetition up to a certain numbers. The best way of repetition is a for loop. The general form of the loop for single statement is:<br /> for ( initialization ; condition ; increment)<br /> {<br /> statement(s);<br /> }<br />The for loop statement<br />
  36. 36. #include<stdio.h><br /> main( )<br /> {<br />int I,s=0;<br /> for (i=1;1<=10;i++)<br /> s=s+1;<br />printf(“sum of first natural number is:%d”,s);<br />getch( );<br /> }<br /> Run:<br />Sum of first 10 natural number is : 55<br />For loop example to print 10 natural number<br />
  37. 37. Nested for loop <br />Loop construct can be nested or embedded within one another. The inner loop must be completely embedded with the outer loop . There should no overlapping of loops.<br />**Demonstration of nested loops**<br /> #include<stdio.h><br /> void main()<br /> {<br />intr,c,sum;<br /> for (r=1;r<=3;r++) /*outer loop*/<br /> {<br /> for(c=1;c<=2;c++) /*inner loop*/<br /> {<br /> sum=r+c;<br />printf(“r=%d c=%d sum=%dn”,r,c,sum);<br /> }}<br />getch();<br /> }<br /> Output<br /> r=1 c=1 sum=2<br /> r=1 c=2 sum=3<br /> r=2 c=1 sum=3<br /> r=2 c=2 sum=4<br />
  38. 38. Odd loop<br />The loop that we have used so far executed the statements within them a finite number of times. However, in real life programming, one comes across a situation when it is not known beforehand how many times the statements in the loop are to be executed. This situation can be programmed as shown below:<br />/* execution of a loop an unknown number of times*/<br />#include<stdio.h><br />void main()<br />{<br />Char another;<br />Int num;<br />do<br />{<br />printf(“enter a number”);<br />scanf(“%d”,&num);<br />printf(“square of%d is %d”, num, num*num);<br />Printf(“n want to enter another number y/n”);<br />Scanf(“%c”,&another);<br />}while(another==‘y’);<br />}<br />getch();<br />}<br />Output<br />Enter a number 5<br />Square of 5 is 25<br />Want to enter another number y/n y<br />Enter a number 7<br />Square of 7 is 49<br />Want to enter anotehr number y/n n<br />
  39. 39. THANK YOU ……. .<br />
  40. 40. ANY QUERIES??<br />

×