Successfully reported this slideshow.
Your SlideShare is downloading. ×

CSE 1201: Structured Programming Language

Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Upcoming SlideShare
ENG 1201: Oral Communication
ENG 1201: Oral Communication
Loading in …3
×

Check these out next

1 of 71 Ad
Advertisement

More Related Content

Recently uploaded (20)

Advertisement

CSE 1201: Structured Programming Language

  1. 1. Course Title: Structured Programming Language Course Code: CSE 1201 Batch: CSE-14 Trimester: Fall-2020 Presented by: Presented for: Stein Joachim Rebeiro (202120001) Abul Hasnat Md. Saiful Islam, Zubayer Farazi (202120003) Associate Professor, Raisa Fabiha (202120004) Chairman, Department of CSE, Notre Dame University, Bangladesh Department: Computer Science & Engineering
  2. 2. Programing Language Defination, Application History of C Programing Language Improtance of Flow Chart Flow Chart, Pseudo Code (Algorithm Example) Control Structure (loop) / break / Continue Decision Making & Branching Operator, Explanation with Appropriate Code Data Type Variable, Constants, Identifier, Rules TOPICS:
  3. 3. PROGRAMMING LANGUAGE DEFINITION: • A FORMAL LANGUAGE COMPRISING A SET OF INSTRUCTIONS • THIS LANGUAGE PROVIDES A WAY OF TELLING A COMPUTER WHAT OPERATIONS TO PERFORM. • EACH PROGRAMMING LANGUAGE HAS A DIFFERENT SET OF SYNTAX RULES • USED TO CREATE PROGRAMS THAT CONTROL THE BEHAVIOR OF A MACHINE
  4. 4. TYPES OF LANGUAGES: Programming language Low level language High level language Machine Language Assembly Language C,C++, Fortran, Java, Python, Basic, Pascal….
  5. 5. Machine language:  The native language of the computer  0 and 1 these two binary digits are used to write this language Assembly Language:  Little easier than machine language  Replaces 1 and 0s with English instructions  Use symbols or Collection of mnemonic codes  It has command like: ADD, MUL, DIV, INP etc. High Level Language:  Close to human language  Easy to learn  C, C++, Fortran, Cobol etc. uses compiler  Python, Basic etc. uses interpreter
  6. 6. Applications of Programming Language: • To create software • Software can be made for calculator or to do mathematical problems • To create web applications • In software development • Games and animations with 3d effects • For game design
  7. 7. HISTORY OF C PROGRAMMING LANGUAGE: • C was evolved from ALGOL, BCPL and B • In 1972 Dennis Ritchie at Bell Laboratories writes C • It was developed along with the UNIX operating system • Added new features and concept like “data types” • In December 1989 American National Standards Institute (ANSI) approved a version of C which is now known as ANSI C
  8. 8. HISTORY OF C PROGRAMMING LANGUAGE: Language Developed Year Developed By ALGOL 1960 International Group BCPL 1967 Martin Richards B 1970 Ken Thompson C 1972 Dennis Ritchie K&R C 1978 Kernighan and Ritchie ANSI C 1989 ANSI Committee ANSI/ISO C 1990 ISO Committee C99 1999 Standard Committee C11 2011 Standard Committee
  9. 9. FLOW CHART: • Diagrammatic representation of logic for solving task • Drawn using boxes of different shapes with lines connecting them to show the flow of control • Make logic of program clearer in a visual form • Diagrammatic representation forms a common medium of communication • Drawn using different kinds of symbols.
  10. 10. BASIC FLOW CHART SYMBOLS, NAME & FUNCTION:
  11. 11. CONTROL STRUCTURE OF FLOW CHART:
  12. 12. EXAMPLES OF FLOW CHART:
  13. 13. IMPORTANCE OF FLOW CHART: A Flowchart - • shows logic of an algorithm • emphasizes individual steps and their interconnections • Helps to control flow from one action to the next
  14. 14. Stein Joachim Reberio
  15. 15. PSEUDO CODE: • Consists of short, readable and formally-styled English language used for explaining an algorithm. • Does not include details like variable declarations, subroutines etc. • Short-hand way of describing computer program • Not based on any programming language • Uses structured constructs of programming language but is not machine readable • Cannot be compiled or executed • No standard for syntax of pseudo code exists
  16. 16. ALGORITHM: • Ordered sequence of finite, well defined, unambiguous instructions for completing a task. • English-like representation of logic to solve problem • Step-by-step procedure for solving problem • For a particular task, different algorithms can be written **We need to select an algorithm based on advantages and disadvantages. Different Algorithms would typically lead to trade off between memory requirements and execution.
  17. 17. Example of Algorithm with Flow Chart:
  18. 18. VARIABLES: • In programming, a variable is a container (storage area) to hold data. • To indicate the storage area, each variable should be given a unique name . Variable names are just the symbolic representation of a memory location. • Each variable in C has a specific type, which determines the size and layout of the variable's memory; the range of values that can be stored within that memory; and the set of operations that can be applied to the variable. • The name of a variable can be composed of letters, digits, and the underscore character. It must begin with either a letter or an underscore. Upper and lowercase letters are distinct because C is case-sensitive.
  19. 19. RULES OF VARIABLES: • A variable name can only have letters (both uppercase and lowercase letters), digits, dollar sign($) and underscore. • The first letter of a variable should be either a letter or an underscore. • Keywords, ‘&’, Variable name starting with numbers, hyphen(-) ; no special symbols are valid. Note: We should always try to give meaningful names to variables. For example: First Name is a better variable name than fn. **C is a strongly typed language. This means that the variable type cannot be changed once it is declared.**
  20. 20. CONSTANTS: • C Constants are also like normal variables. But, only difference is, their values can not be modified by the program once they are defined. • Constants refer to fixed values. They are also called as literals • Constants may be belonging to any of the data type.
  21. 21. RULES OF CONSTANTS: • By “const” keyword or by “#define” preprocessor directive, a constant is declared in C program. • It can either be positive or negative. If no sign is declared, then the constant is assumed to be positive. • No commas or blanks are allowed within a constant. • Character constant is a single alphabet, a single digit or a single special symbol enclosed within single quotes. • The allowable range for integer constants is -32768 to 32767. • If we try to change constant values after defining in C program, it will show error.
  22. 22. IDENTIFIER: • Identifier refers to name given to entities such as variables, functions, structures etc. Variable and identifiers are almost the same but identifier can be used in a larger scale. Such as- “Array”. • Identifiers must be unique. They are created to give a unique name to an entity to identify it during the execution of the program. For example: int money; double Balance; Here, money and Balance are identifiers. • Also identifier names must be different from keywords. We cannot use `int` as an identifier because int is a keyword.
  23. 23. RULES OF IDENTIFIERS: • A valid identifier can have letters (both uppercase and lowercase letters), digits and underscores. • The first letter of an identifier should be either a letter or an underscore. • Keywords like int, while etc. cannot be used as identifiers. • There is no rule on how long an identifier can be. **Any name can be chosen as an identifier if we follow the above rules. However, giving meaningful names are recommended as identifiers that make sense.**
  24. 24. EXAMPLE OF VARIABLE, CONSTANT & IDENTIFIER: If we use variable_1[5] then it will become an array. Even then it will be consider as an identifier but we cannot declare it as a variable anymore. And this is the difference between identifier & variable.
  25. 25. DATA TYPES: • Data types in c refer to an extensive system used for declaring variables or functions of different types. The type of a variable determines how much space it occupies in storage and how the bit pattern stored is interpreted. • It determines the type and size of data associated with variables. For example: int myVar; Here, myVar is a variable of int (integer) type. The size of int is 4 bytes. • Data types are used to define a variable before to use in a program. • Size of variable, constant and array are determined by data types.
  26. 26. BASIC DATA TYPES:
  27. 27. RANGE AND SIZE OF DIFFERENT DATA TYPES:
  28. 28. EXAMPLE OF DATA TYPE: Input: Output:
  29. 29. Zubayer Farazi
  30. 30. OPERATOR:  An operator is a symbol that tells the computer to perform certain mathematical or logical manipulations.  These operators are used in programs to manipulate data and variables.
  31. 31. TYPES OF OPERATOR: • Arithmetic operators • Relation operators • Logical operators • Assignment operators • Increment and decrement operators • Conditional operators • Bitwise operators • Special operators
  32. 32. ARITHMETIC OPERATORS:  Arithmetic operator are used to perform numeric calculations among the values. Operators Meaning + Addition or unary plus - Subtraction or unary minus * Multiplication / Division % Modulo division
  33. 33. EXAMPLE: main() { int a,b,add,sub,mul,div,mod; printf(“Enter two integer value:”); scanf(“%d%d”,&a,&b); add=a+b; sub=a-b; mul=a*b; div=a/b; mod=a%b; Printf(“Summation=%d”,add); Printf(“subtract=%d”,sub); Printf(“Multiplication=%d”,mul); Printf(“Division=%d”,div); Printf(“Module=%d”,mod); } Enter two integer value:20 10 Summation=30 subtract=10 Multiplication=200 Division=2 Module=0 Output:
  34. 34. RELATION OPERATOR:  Relational operators are used to compare two quantities and take certain decision depending on their relation. • If the relation is true it returns one. • If the relation is false it returns zero. Operator Meaning < is less than <= is less than or equal > is greater then >= is greater then or equal == is equal to != is not equal to
  35. 35. EXAMPLE: main() { int x=12,y=14,z=12; printf("The number of X,Y,Zn"); //is x greater than y printf("x>y=%dn",x>y); //is z less than y printf("x<y=%dn",x<y); //is y greater than or equal z printf("y>=z=%dn",y>z); //is x equal y printf("x==y=%dn",x==y); //is y not equal to z printf("y!=z=%d",y!=z); } The number of X,Y,Z x>y=0 x<y=1 y>=z=1 x==y=0 y!=z=1 Output:
  36. 36. LOGICAL OPERATOR:  Logical operator are used for testing more than one condition and making decisions. Operator Meaning && Logical AND || Logical OR ! Logical NOT
  37. 37. EXAMPLE: main() { int x=12,y=15,z=13,sum; printf("Enter the numbers of X,Y,Zn"); //logical And sum=(x!=z) && (x>y); printf("(x!=z) && (x>y) is %dn",sum); //logical Or sum=(x>=y) || (y<z); printf("(x>=y) || (y<z) is %dn",sum); //Logical Not sum=(x!=y); printf("(x!=y) is %dn",sum); } Enter the numbers of X,Y,Z (x!=z) && (x>y) is 0 (x>=y) || (y<z) is 0 (x!=y) is 1 Output:
  38. 38. ASSIGNMENT OPERATOR: • These operator are used for assigning the result of an expression to a variable. • b=a Statement of simple assignment operator Statement with shorthand operator a =a+1 a + = 1 a=a-1 a-=1 a=a*(n+1) a*=(n+1) a=a/(n+1) a/=(n+1) a=a%b a%=b
  39. 39. EXAMPLE: main() { int a,b,c; printf(“Enter three integer number:n”); scanf(“%d%d%d”,&a,&b,&c); printf(“value=%dn”,c+=b); printf(“value=%dn”,c-=b); printf(“value=%dn”,c*=b); printf(“value=%dn”,c/=b); printf(“value=%dn”,c%=b); } Output: Enter three integer number: 5 10 15 value=25 value=15 value=150 value=15 value=5
  40. 40. INCREMENT AND DECREMENT OPERATORS: C allows two very useful operators. These are the increment and decrement operators: ++ and -- • The operator ++ adds one to the operands. • The operator – subtracts one from the operand. **Both are unary operators and can be used as pre or post increment or decrement.
  41. 41. EXAMPLE: main() { int a,b,c; printf(“Enter three integer number:n”); scanf(“%d%d%d”,&a,&b,&c); printf(“value=%dn”,c=++a); printf(“value=%dn”,c=a++); printf(“value=%dn”,c=--a); printf(“value=%dn”,c=a--); } Output: Enter three integer number: 4 5 6 value=5 value=5 value=5 value=5
  42. 42. CONDITIONAL OPERATORS: Syntax: exp1?exp2:exp3 Where exp1,exp2,exp3 are expressions. Operator: ?: (ternary operator)  These conditional operator are used to construct conditional expressions of the form.
  43. 43. EXAMPLE: main() { int num1,num2,result; printf("Enter two numbers : n"); scanf("%d%d",&num1,&num2); result=(num1>num2) ? num1 : num2; printf("The maximum number between %d and %d is %dn",num1,num2,result); } Enter two numbers : 10 20 The maximum number between 10 and 20 is 20 Output:
  44. 44. BITWISE OPERATORS: • These operator works on bit level • Applied to integer only. operator Meaning & Bitwise AND | Bitwise OR ^ Bitwise exclusive OR << Shift left >> Shift right
  45. 45. SPECIAL OPERATORS: C supports some special operators such as- • comma operator • sizeof operator • pointer operators comma operator sizeof operator pointer operators
  46. 46. COMMA OPERATOR: • The operator is used to combine related expressions. • A comma linked list of expressions are evaluated left to right and the value of right most expression is the value of combined expression. Example: value=(x=10,y=5,x+y);
  47. 47. SIZE OF OPERATOR: Sizeof is an operator used to return the number of bytes the operand occupies. Syntax: m=sizeof(sum); K=sizeof(2351);
  48. 48. DECISION MAKING STATEMENT: • Also known as control structure • Controls the flow of execution • Execute program until a specific control is met • One of the most important parts in programming
  49. 49. TYPES OF DECISION-MAKING STATEMENT: If-else If If-else If-else if Nested if Switch
  50. 50. IF STATEMENT: • The expression must be evaluating to true or false. • The “Statement” can be a group or in braces. • Syntax: If (expression) { statement 1; statement 2; }
  51. 51. EXAMPLE: main() { int n; printf(“Enter any number:”); scanf(“%d”,&n); if(n>25) { printf(“You can marry now”); } } Enter any number: 26 You can marry now Output:
  52. 52. IF-ELSE STATEMENT: • An extension version of if statement. • Generally in the form of if (test expression) • Syntax: If (test expression) { true block statement } else { false block statement }
  53. 53. EXAMPLE: main() { int num1,num2; printf("Enter any two number: n"); scanf("%d%d",&num1,&num2); if(num1==num2) { printf("They are equal"); } else { printf("They are not equal"); } } Enter any two number: 10 11 They are not equal Output
  54. 54. IF-ELSE IF: • It is used to give series of decision. • Syntax: If (condition) { Statement 1; } Else if (condition 2) { Statement 2; } Else { Statement when all condition are false. }
  55. 55. EXAMPLE: main() { int num; printf("Enter integer numn"); scanf("%d",&num); if(num>0) { printf("positive"); } else if(num<0) { printf("Negative"); } else if(num==0) { printf("Zero"); } } Enter integer number 1000000 positive Output:
  56. 56. NESTED IF-ELSE STATEMENT: • New block or if else statement defined in exiting if or else block statement. • Syntax: If(condition1) { if(condition2) { statement1; } else { Statement2; } } else { Statement3; }
  57. 57. SWITCH STATEMENT: • Multi-way decision statement • Tests the value of a given variable against a list of case values. • When a match is found, a block of statements associated with that case is executed. • Syntax: switch(<selector expression>) { Case<value1>: <sequence of statements>; break; Case<value2>: <sequence of the statements>; break; Case<value3>: <sequence of statements>; break; Default: <sequence of statements>;
  58. 58. EXAMPLE: main() { int num; printf("Enter any number :n"); scanf("%d",&num); switch(num % 2) { case 0: printf("This number is even number"); break; case 1: printf("This number is odd number"); break; } } Enter any number: 10 This number is even number Output:
  59. 59. LOOPS: Loops are used in programming to repeat a specific block until some end condition is met.  There are three loops in c programming.  for loop  while loop  do while loop
  60. 60. FOR LOOP: • The syntax of a for loop is: for(initialization ; condition; variable update) { //code to execute while the condition is true statement; }
  61. 61. EXAMPLE: main() { int i; for(i=1;i<=50;i++) printf("%dn",i); } 1234567891011121314151617181920 2122232425262728293031323334353 63738394041424344454647484950 Output:
  62. 62. WHILE LOOP: • The syntax of a while loop is: while(condition) { //body of the loop statement; variable update; }
  63. 63. EXAMPLE: main() { int i; i=1; while(i<=5) { printf(“NDUBn"); i++; } } NDUB NDUB NDUB NDUB NDUB Output:
  64. 64. DO WHILE LOOP: • The syntax of a do while loop is: do { //body of the loop Statement; variable update; } While (condition);
  65. 65. EXAMPLE: main() { int i,s=0; i=1; do { if(i%2!=0) s=s+i; i++; } while(i<=10); printf("Summation of ODD numbers: %dn",s); } Summation of ODD numbers: 25 Output:
  66. 66. BREAK STATEMENT: • The break statement terminates the loop immediately when it is encountered. • The break is used with decision making statement such as if else • Syntax of the break statement: break;
  67. 67. EXAMPLE: int main() { int num; for (num =100; num>=10; num --) { printf(“num: %dn", num); if (num==99) { break; } } printf("Out of for-loop"); } num: 100 num: 99 Out of for-loop Output:
  68. 68. CONTINUE STATEMENT: • The continue statement skips some statements inside loop. • The continue statement is used with decision making statement such as if else. • Syntax of continue statements: continue;
  69. 69. EXAMPLE: int main() { int j=0; do { if (j==7) { j++; continue; } printf("%d ", j); j++; } while(j<10); } 0 1 2 3 4 5 6 8 9 Output:
  70. 70. THE END

×