C Programming Class I
|
|
- Joan Stewart
- 5 years ago
- Views:
Transcription
1 C Programming Class I
2 Generation of C Language Introduction to C 1. In 1967, Martin Richards developed a language called BCPL (Basic Combined Programming Language) 2. In 1970, Ken Thompson created a language using many features of BCPL and called it simply B. 3. In 1972, C is Introduced by Dennis Ritchie at Bell laboratories and in the UNIX operating system.
3 Why are using C It is a Structured Programming Language High Level Language Machine Independent Language It allows software developers to develop programs without worrying about the hardware platforms where they will be implemented TYPES OF C COMPILER 1. Borland C Compiler 2. Turbo C Compiler 3. Microsoft C Compiler 4. ANSI C Compiler
4 Steps in Learning C Character set Files Data Structures Constants, variable And Data types Structures and Unions Algorithms Control statements Pointers Programs Functions Arrays
5 C S Program Structure Documentation section Preprocessor section Definition section Global declaration section main() Declaration part; Executable part; } Sub program section Body of the subprogram }
6 C Character set C s Character set Source Character set Alphabets A to Z & a to z Digits 0 to 9 Special Characters +,-,<,>,@,&,$,#,! Execution Character set Escape Sequences \a,\b,\t,\n
7 C TOKENS C TOKENS Constants Strings ABC YEAR Identifiers Operators Keywords Grant_total Amount a1 + - * / Special Symbols float while [ ] }
8 C s keyword Basic Building Block of the Program This are the Reserved words This word s cant be changed C keywords auto break case char const continue default do double else enum extern float for goto if int long register return short signed sizeof static struct switch typedef union unsigned void volatile while
9 C s Variables A variable is a data name as well as identifier that may be used to store a data value. Rules for Naming the Variables a) A variable can be of any combination of alphabets, digits and underscore. b) The first character of the variable can t be digits. c) The length of the variable can t be exceeded by 8.(ANSI C 32 Character) d) No commas, blanks or special symbol are allowed within a variable name. e) Uppercase and lowercase are significant. That is, the variable Total is not the same as total or TOTAL. f) It should not be a keyword. g) White space is not allowed.
10 C s Variables cont. Variable Declaration It tells the computer what the variable name and type of the data Syntax data_type a1,a2,a3..an; Description data_type is the type of the data. a1,a2,a3 an are the list of variables Example int number; char alpha; float price;
11 C s Variables cont. Initializing Variables Initialization of variables can be done using assignment operator(=) Syntax a1 = c1 ;(or) data_type a1 = c1; Description a1 is the variable c1 is the constant data_type Example int a1 = 29; float f1 = 34.45; char c1 = d is the type of the data
12 C s constant The item whose values can t be changed during execution of program are called constants C constant Numeric constant Integer constant eg: roll_number = 12345; Real constant eg: pi = 3.14; Character constant Single Character constant eg: ch = c ; ch = 3 ; String constant eg: name = palani
13 C s constant Conti Integer constant eg: roll_number = 12345; Real Constant eg: pi = 3.14; Decimal Constant Eg. 35 Octal constant Eg. 043 Hexadecimal constant Eg. 0x23 Single Precision Constant Double Precision Constant
14 Data Types This are the type of the data that are going to access within the program. C s Data Type Primary User defined Derived Empty Char Int Float Double typedef Arrays Pointers Structures Union Void
15 C s Data types cont. The primary data types are further classified as below. Integers are the whole numbers, both positive and negative. Integer Signed Int (%d) 2 bytes, to Short int (%d) 1 bytes, -128 to 127 Unsigned Long int (%ld) 4 bytes, -2,147,483,648 to 2,147,483,647 Unsigned Int (%d) 2 bytes, 0 TO 65, 535 Unsigned short int (%d) 1 bytes, 0 TO 255 Unsigned Long int (%ld) 4 bytes, 0 TO 4,294,967,295
16 C s Data types cont. Float are the numbers which contain fractional parts, both Positive and Negative. Float Type Float (%f ) 4 bytes, 3.4E -38 to 3.4E +38 Double (%lf) 8 bytes, 1.7E -308 to 1.7E +308 Long Double (%lf) 10 bytes, 3.4E to 1.1E+4932
17 C s Data types cont. Char are the characters which contain alpha-numeric character. Characters are usually stored in 8 bits (one byte) of internal storage Character Type Char (%c) 1 byte, -128 to 127 Signed Char (%c) 1 byte, -128 to 127 Unsigned Char (%c) 1 byte, 0 to 255 The void is the Null Data type.
18 C Delimiters Delimiters are the symbols, which has some syntactic meaning and has got significance. Symbol Name Meaning # Hash Pre-processor directive, comma Variable delimiters (to separate list of variables) : colon Label delimiters ; Semi colon Statement delimiters () parenthesis Used in expressions or in functions } Curly braces Used in blocking C structure [] Square braces Used along with arrays
19 C Statements Statement can be defined as set of declarations (or) sequence of action All statements in C ends with semicolon(;) except condition and control statement Statements Expression Statement Compound Statement Control Statement
20 Expression Statement 1. An Expression is a combination of constant, variables, operators, and function calls written in any form as per the syntax of the C language. 2. The values evaluated in these expressions can be stored in variables and used as a part for evaluating larger expressions. 3. They are evaluated using an assignment statement of the form. 4. For Example, variable = expression; age = 21; result = pow(2,2); simple_interest = (p * n * r) / 100; Algebraic Expression (mnp + qr at) (a+b+c) (x+y+z) abc / x+y 8a 3 + 3a a (a-b)+(x-y) / mn 8.8(a+b-c) + c / pq Equivalent C Expression (m*n* p+q*r-s*t) (a+b+c)*(x+y+z) (a*b*c) / (x+y) 8*a*a*a+3*a*a+2*a ((a-b)+(x-y)) / (m*n) 8.8 * (a+b-c) + (c / (p*q))
21 Compound Statements 1. A group of valid C expression statements placed within an opening flower brace and closing flower brace } is referred as a Compound Statements. 2. For Example, X = (A + (B * 3) C); Y = A + B * 3; Z = A * (B * 3 C); } Control Statements 1. This statement normally executed sequentially as they appear in the program. 2. In some situations where we may have to change the order of execution of statements until some specified conditions are met. 3. The control statement alter the execution of statements depending upon the conditions specified inside the parenthesis. 4. For Example, if (a == b) if ((x < y) && (y > z)) } }
22 Operators An operator is a symbol that specifies an operation to be performed on the operands Some operator needs two operands (binary) Eg: a+b; + is an operator and a and b are the operands Some operator needs one operand (unary) Eg: ++a; ++ is an operator and a is the operand
23 Types of Operators operators Arithmetic operator Relational operators Logical operator Assignment operator Increment and Decrement Operator (Unary Op.) Conditional operator (Ternary operator) Bitwise operator Special operator
24 Arithmetic Operators This operators help us to carryout basic arithmetic operations such addition, subtraction, multiplication, division Operator Meaning Examples + Addition 1+2 = 3 - Subtraction 3-2 = 1 * Multiplication 2*2 = 4 / Division 2/2 = 1 % Modulo division 10/3= 1 Operation Result Examples Int/int int 2/2 = 1 Real/int real 7.0/2 = 3.5 Int/real real 7/2.0 = 3.5 Real/real real 7.0/2.0 = 3.5
25 Relational Operator This are used to compare two or more operands. Operands can be variables, constants or expression. eg: comparison of two marks or two values. Operator Meaning Example Return value < is less than 5<6 1 <= is less than or equal to 4<=4 1 > is greater than 5>7 0 >= is greater than or equal to 7>=5 0 == equal to 6==6 1!= not equal to 5!=5 0
26 Logical Operator This operators are used to combine the results of two or more conditions. Operator Meaning Example Return value && Logical And (9>2) && (6>4) 1 Logical OR (9>2) (3.4) 1! Logical Not 4! 4 0 AND truth table True True True True False False False True False False False False OR truth table True True True True False True False True True False False False
27 Assignment Operator This are used to assign a value or an expression or a variable to another variable eg: a = 10; n1 = 20; Syntax: identifier = expression; a) Compound Assignment This operator are used to assign a value to a variable in order to assign a new value to a variable after performing a specified operation. eg: a+=10,n1-=20; b) Nested Assignment (Multiple) This operator are used to assign a single value to multiple variables eg: a=b=c=d=e=10;
28 List of Shorthand or Compound Assignment Operator Operator Meaning += Assign Sum -= Assign Difference *= Assign Product /= Assign Quotient %= Assign Remainder ~= Assign One s Complement <<= Assign Left Shift >>= Assign Right Shift &= Assign Bitwise AND!= Assign Bitwise OR ^= Assign Bitwise X - OR
29 Increment and Decrement operator C provide two operator for incrementing a value or decrementing a value a) ++ Increment operator (adds one to the variable) b) -- Decrement operator (Minus one to the variable) eg: a++ (if a= 10 then the output would be 11) Operator ++X X++ --X X-- Meaning Pre increment Post increment Pre decrement Post decrement
30 Increment and Decrement operator Conti If the value of the operand x is 3 then the various expressions and their results are Expression Result + + X 4 X X 2 X The pre increment operation (++X) increments x by 1 and then assign the value to x. The post increment operation (X++) assigns the value to x and then increments 1. The pre-decrement operation ( --X) decrements 1 and then assigns to x. The post decrement operation (x--) assigns the value to x and then decrements 1. These operators are usually very efficient, but causes confusion if your try to use too many evaluations in a single statement.
31 Conditional Operator It is used check the condition and execute the statement depending upon the condition Syntax Description Example a= 2; b=3 Condition?exp1:exp2 The? operator act as ternary operator, it first evaluate the condition, if it is true then exp1 is evaluated if the condition is false then exp2 is evaluated ans = a>b?a:b; printf (ans);
32 Bitwise Operator This are used to manipulate the data at bit level It operates only on integers Operator & Meaning Bitwise AND Bitwise OR ^ Bitwise XOR << Shift left >> Shift right ~ One s complement
33 Bitwise Operator cont. The truth table for Bitwise AND,OR and XOR Bitwise AND (both the operand should be high for 1) Bitwise OR (either of the operand should be high for 1) Bitwise XOR (the two operands should be different for 1) Eg: x = 3 = y = 4 = x&y = Eg: x = 3 = y = 4 = x y = Eg: x = 3 = y = 4 = x ^ y =
34 Bitwise One s Complement Bitwise Operator cont. The one s complement operator (~) is a unary operator, which causes the bits of the operand to be inverted (i.e., one s becomes zero s and zero s become one s) For Example, if x = 7 Bitwise Left Shift Operator i.e 8 bit binary digit is The One s Complement is The Left shift operator (<<) shifts each bit of the operand to its Left. The general form or the syntax of Left shift operator is variable << no. of bits positions if x = 7 (i.e., ) the value of y in the expression y = x <<1 is = 14 since it shifts the bit position to its left by one bit. The value stored in x is multiplied by 2 N (where n is the no of bit positions) to get the required value. For example, if x = 7 the result of the expression y = x << 2 is y = x * 2 2 (i.e. 28)
35 Bitwise Right Shift Operator Bitwise Operator cont. The Right shift operator (>>) shifts each bit of the operand to its Right. The general form or the syntax of Right shift operator is variable >> no. of bits positions if x = 7 (i.e., ) the value of y in the expression y = x >> 1 is = 3 since it shifts the bit position to its right by one bit. The value stored in x is divided by 2 N (where n is the no of bit positions) to get the required value. For example, if x = 7 the result of the expression y = x << 2 is y = x / 2 2 (i.e. 1). If you use the left shift operator i.e. x = x << 1 the value of x will be equal to 2 (i.e., ) since the lost bit cannot be taken back.
36 Operator Precedence and Associativity of Operator
37 What is Precedence Rule and Associative Rule 1. Each operator in C has a precedence associated with it. 2. This precedence is used to determine how an expression involving more than one operator is evaluated. 3. These are distinct levels of precedence and an operator may belong to one of these levels. 4. The operators at the higher level of precedence are evaluated first. 5. The operators of the same precedence are evaluated either from left to right or from right to left, depending on the level. 6. That is known as the associativity property of an operator.
38 Arithmetic operators precedence The precedence of an operator gives the order in which operators are applied in expressions: the highest precedence operator is applied first, followed by the next highest, and so on. eg: Arithmetic operator precedence Precedence operator High *,/,% Low +,- The arithmetic expression evaluation is carried out using two phases from left to right through the expressions
39 Example: if (x == && y <10) The precedence rules say that the addition operator has a higher priority than the logical operator (&&) and the relational operators (== and <). Therefore, the addition of 10 and 15 is executed first. This is equivalent to: if (x == 25 && y < 10) The next step is to determine whether x is equal to 25 and y is less than 10, if we assume a value of 20 for x and 5 for y, then x == 25 is FALSE (0) y <10 is TRUE (1) Note that since the operator < enjoys a higher priority compared to ==, y < 10 is tested first and then x ==25 is tested. Finally we get, Relational operators precedence if (FALSE && TRUE) Because one of the conditions is FALSE, the complex condition is FALSE. In the case of &&, it is guaranteed that the second operand will not be evaluated if the first is zero and in the case of, the second operand will not be evaluated if the first is non zero.
40 Precedence and Associativity Table The following table lists all the operators, in order of precedence, with their associativity Operators Operations Associativity priority () Function call Left to Right 1 [] Square brackets -> Structure operator. Dot operator + Unary plus Right to Left 2 - Unary minus ++ Increment -- Decrement! Not
41 Precedence and Associativity Table cont. Operators Operations Associativity priority ~ Complement Right to Left 2 * Pointer operation & Address operator Sizeof Size of operator type Type cast * Multiplication Left to Right 3 / Division % Modulo + Addition Left to Right 4 - Subtraction
42 Precedence and Associativity Table cont. Operators Operations Associativity priority << Left shift Left to Right 5 >> Right shift < is less than Left to Right 6 <= is less than or equal to > is greater than >= is greater than or equal to == equal to!= not equal to & Bitwise AND Left to Right 7 Bitwise OR ^ Bitwise XOR
43 Precedence and Associativity Table cont. Operators Operations Associativity priority && Logical And Left to Right 8 Logical OR?= Conditional Right to Left 9 =,*=,- =,&=,+=,^=,!=, <<=,>>= Assignment Right to Left 10, comma Left to Right 11
44 Sample Expression Exp = a - 2 * a * b + b / 4 Let us have a=10,b=20 exp = 10-2 * 10 * / 4 Phase I exp = 2*10*20, 20/4 will be evaluated. phase II exp = will be evaluated. Result exp = -395.
45 Expression Evaluation Let us see some examples for evaluating expression. Let a = 5, b = 8, c = 2. x = b / c + a * c
46 Expression Evaluation Let us see some examples for evaluating expression. Let a = 5, b = 8, c = 2. y = a + (b * 3) - c
47 TYPE CONVERSION OR TYPE CASTING
48 What is Type Conversion or Type Casting Type Casting means One data type converted into another data type. This is called Type conversion or Type casting. Example: 1. Integer into floating point number 2. Character into integer 3. Floating point number into Integer Number Type conversion is classified into two types. 1. Implicit Type Conversion (Automatic Type Conversion) 2. Explicit Type Conversion (Manual Type Conversion) Type Conversion Implicit Conversion Explicit Conversion Automatic Conversion Casting Operation
49 Type Conversion Hierarchy Implicit Type Conversion double long double float unsigned long int long int unsigned int int short char Explicit Type Conversion
50 Implicit Type Conversion 1. The Implicit Type Conversion is known as Automatic Type Conversion. 2. C automatically converts any intermediate values to the proper type so that the expression can be evaluated without loosing any significance. 3. Implicit type Conversion also known as Converted Lower order data type into Higher order data type. 4. Implicit Type Conversion also known as Widening. Example: int a, b; float c; c = a + b; Print c; float a,b; int c; c = a + b; // This is Wrong Print c;
51 Explicit Type Conversion 1. The Explicit Type Conversion is, there are instances when we want to force a type conversion in a way that is different from the automatic conversion. 2. The Explicit Type Conversion is Converted Higher order data type into Lower order data type. 3. The Explicit type Conversion is also known as borrowing. 4. The Explicit type conversion forces by a casting operator. Disadvantage of Explicit Type Conversion 1. float to int causes truncation of the fractional part. 2. double to float causes rounding of digits. 3. Long int to int causes dropping of the excess higher order bits. The general form of the casting is For Example: (type_name) expression; Where type_name is one of the standard C data type. The expression may be a constant, variables or an expression. float a, b; int c; c = (int) a + (int) b; Print c;
52 Use of Casts Example Action x = (int) is converted to integer by truncation. a = (int) 21.3 / (int) 4.5 Evaluated as 21 / 4 and the result would be 5. b = (double) sum / n Division is done in floating point mode. y = (int) (a + b) The result of a + b is converted to integer. z = (int) a + b a is converted to integer and then added to b. p = cos ((double) x) Converts x to double before using it.
53 Input And Output Functions
54 Ip / Op Statements We have two methods for providing data to the program. a) Assigning the data to the variables in a program. b) By using the input/output statements. c language supports two types of Ip / Op statements This operations are carried out through function calls. Those function are collectively known as standard I / O library
55 Ip / Op Statements cont. Ip / Op Functions Unformatted Ip / Op statements Input Output getc() putc() getch() putch() Gets() puts() Formatted Ip / Op statements Input Output Scanf() printf() fscanf() fprintf()
56 Unformatted Ip / Op statements These statements are used to input / output a single / group of characters from / to the input / output device. Single character Input/output function getch() function putch() function Syntax char variable = getch(); Description char is the data type of the variable; getch() is the function Syntax Description putch (character variable); char variable is the valid c variable of the type of char data type. Example char x = getch(); putch (x); Example char x ; putch (x);
57 Unformatted Ip / Op statements cont. Group of character Input / output function. Gets() and puts are used to read / display the string from / to the standard input / output device. gets() function Syntax Description gets (char type of array variable); valid c variable declared as one dimensional array. puts() function Syntax Description puts (char type of array variable) valid c variable declared as one dimensional array. Example char s[10]; gets (s); Example char s[10]; gets (s); puts (s);
58 Unformatted Ip / Op statements cont. Single character Input / output function with files. Gets() and puts are used to read / display the string from / to the standard input / output device. getc() function Syntax Description getc(char type of variable, file pointer); The getc function returns the next character from the input stream pointed to by stream Example int getc(file *stream ); putc() function Syntax Description Example putc (char type of variable, file pointer) The putc function returns the character written. int putc(int c, FILE *stream );
59 Sample Program #include<stdio.h> Void main() char name[10]; char address[20]; Puts( Enter the name : ); gets(name); puts( Enter the address : ); gets(address); puts( Name = ) puts(name); puts( Address = ); puts(address); }
60 Formatted Ip / Op statements It refers to Input / Output that has been arranged in a particular format. Using this statements, the user must specify the type of data, that is going to be accessed. scanf() (This function is used to enter any combination of input). Syntax scanf ( control strings,var1,var2..var n); Description control strings is the type of data that user going to access via the input statements. var1,var2 are the variables in which the data s are stored. Example int n; scanf ( %d, &n);
61 Formatted Ip / Op statements Control strings i) It is the type of data that user is going to access via the input statement ii) These can be formatted. iii) Always preceded with a % symbol. Format code Variable type Display %c Char Single character %d Int Decimal integer to %s Array of char Print a Strings %f Float or double Float point value without exponent %ld Long int Long integer to %u Int Unsigned decimal integer %e Float or double Float point values in exponent form %h int Short integer
62 Printf() printf() (This function is used to display the result or the output data on to screen) Syntax printf ( control strings,var1,var2..var n); Description Example Control strings can be anyone of the following a) Format code character code b) Execution character set c) Character/strings to be displayed Var1,var2 are the variables in which the data s are stored. printf ( this is computer fundamental class ); printf ( \n Total is %d and average is %f,sum,avg);
63 Control Statements (Decision Making)
64 Control Statements Control statements Selection Statements Iteration statements The if else statement The while loop & Do while loop The switch statements The for loop The break statement Continue statement Goto statement
65 Types of Selection Statement 1. Simple if Selection statement 2. if else Selection statement 3. Nested if else Selection statement 4. else if ladder Selection statement
66 Simple if Selection statement It is used to control the flow of execution of the statements and also to test logically whether the condition is true or false. Syntax: if ( condition ) statement ; } if the condition is true then the statement following the if is executed if it is false then the statement is skipped. Test Condition True Executable X - Statement
67 //Biggest of Two Numbers #include <stdio.h> void main() int a, b; clrscr(); printf( Enter the A and B Value:\n ); scanf( %d, &a); if (a > b) printf( A is Big ); } } getch();
68 The if else statement It is used to execute some statements when the condition is true and execute some other statements when the condition is false depending on the logical test. Syntax: if ( condition ) statement 1 ; } else statement 2 ; } (if the condition is true this statement will be executed) (if the condition is false this statement will be executed) False Test Condition True Executable Y - Statement Executable X - Statement
69 // Biggest of Two Numbers #include <stdio.h> void main() int a, b; clrscr(); printf( Enter the A and B Value:\n ); scanf( %d%d, &a,&b); if (a > b) printf( A is Big ); } else printf( B is Big ); } } getch();
70 // Given Number is ODD or EVEN Number #include <stdio.h> void main() int n; clrscr(); printf( Enter the Number:\n ); scanf( %d, &n); if (n % 2 == 0) printf( Given Number is Even Number ); } else printf( Given Number is Odd Number ); } } getch();
71 Nested if.. else statement when a series of if else statements are occurred in a program, we can write an entire if else statement in another if else statement called nesting Syntax: if ( condition 1) if ( condition 2) statement 1 ; else statement 2 ; } else if (condition 3) statement 3; else statement 4; }
72 FALSE Test Condition_1 TRUE FALSE Test Condition_2 TRUE Executable X2 - Statement Executable X1 - Statement FALSE Test Condition_3 TRUE Executable X4 - Statement Executable X3 - Statement
73 else if Ladder or Multiple if else Statements When a series of decisions are involved we have to use more than one if else statement called as multiple if s. Multiple if else statements are much faster than a series of if else statements, since theif structure is exited when any one of the condition is satisfied. Syntax: if (condition_1) executed statement_1; else if (condition_2) executed statement_2; else if (condition_3) executed statement_3; else if (condition_n) executed statement_n; else executed statement_x;
74 FALSE Test Condition_1 TRUE Exec. Stat_1 FALSE Test Condition_2 TRUE Exec. Stat_2 FALSE Test Condition_3 TRUE Exec. Stat_3 FALSE Test Condition_n TRUE Exec. Stat_X Exec. Stat_n
75 else if Ladder if (result >= 75) printf ( Passed: Grade A\n ) ; else if (result >= 60) printf ( Passed: Grade B\n ) ; else if (result >= 45) printf ( Passed: Grade C\n ) ; else printf ( Failed\n ) ;
76 THE SWITCH STATEMENT The control statements which allow us to make a decision from the number of choices is called switch (or) Switch-case statement. It is a multi way decision statement, it test the given variable (or) expression against a list of case value. switch (expression) case constant 1: simple statement (or) compound statement; case constant 2: simple statement (or) compound statement; case constant 3: simple statement (or) compound statement; } switch (expression) case constant 1: simple statement (or) compound statement; case constant 2: simple statement (or) compound statement; default : simple statement (or) compound statement; }
77 Example Without Break Statement #include<stdio.h> void main () int num1,num2,choice; printf( Enter the Two Numbers:\n ); scanf( %d%d,&num1,&num2); printf( 1 -> Addition\n ); printf( 2->Subtraction\n ); printf( 3->Multiplication\n ); printf( 4->Division\n ); printf( Enter your Choice:\n ); scanf( %d,&choice); switch(choice) case 1: Printf( Sum is %d\n, num1+num2); } case 2: Printf( Diif. is %d\n, num1-num2); case 3: Printf( Product is %d\n, num1*num2); case 4: Printf( Division is %d\n, num1/num2); default: printf ( Invalid Choice..\n ); Example With Break Statement #include<stdio.h> void main () int num1,num2,choice; printf( Enter the Two Numbers:\n ); scanf( %d%d,&num1,&num2); printf( 1 -> Addition\n ); printf( 2->Subtraction\n ); printf( 3->Multiplication\n ); printf( 4->Division\n ); printf( Enter your Choice:\n ); scanf( %d,&choice); switch(choice) case 1: printf( Sum is %d\n, num1+num2); break; case 2: printf( Diif. is %d\n, num1-num2); break; case 3: printf( Product is %d\n, num1*num2); break; case 4: printf( Division is %d\n, num1/num2); break; default: printf ( Invalid Choice..\n ); } } getch(); } getch();
78 Rules for Switch The expression in the switch statement must be an integer or character constant. No real numbers are used in an expression. The default is optional and can be placed anywhere, but usually placed at end. The case keyword must be terminated with colon (:); No two case constant are identical. The values of switch expression is compared with case constant in the order specified i.e from top to bottom. A switch may occur within another switch, but it is rarely done. Such statements are called as nested switch statements. The switch statement is very useful while writing menu driven programs.
79 Iteration Statements 1. Iteration statements is also known as Looping statement. 2. A segment of the program that is executed repeatedly is called as a loop. 3. Some portion of the program has to be specified several number of times or until a particular condition is satisfied. 4. Such repetitive operation is done through a loop structure. 5. The Three methods by which you can repeat a part of a program are, 1. while Loops 2. do.while loops 3. for Loop Loops generally consist of two parts : Control expressions: One or more control expressions which control the execution of the loop, Body : which is the statement or set of statements which is executed over and over
80 Any looping statement, would include the following steps: a) Initialization of a condition variable b) Test the control statement. c) Executing the body of the loop depending on the condition. d) Updating the condition variable.
81 While Loop A while loop has one control expression, and executes as long as that expression is true. The general syntax of a while loop is initialize loop counter; while (condition) statement (s); increment or decrement loop counter } A while loop is an entry controlled loop statement.
82 Start Initialize Test Condition False True Stop Body of Loop Increment or Decrement
83 } Example: // Print the I Values #include <stdio.h> void main() int i; clrscr(); i = 0; while(i<=10) printf( The I Value is :%d\n,i); ++i; } getch(); } // Summation of the series #include <stdio.h> void main() int i, sum; clrscr(); i = 1; sum = 0; while(i<=10) sum = sum + i printf( The Sum Value is:%d\n,i); ++i; } getch();
84 THE do-while LOOP The body of the loop may not be executed if the condition is not satisfied in while loop. Since the test is done at the end of the loop, the statements in the braces will always be executed at least once. The statements in the braces are executed repeatedly as long as the expression in the parentheses is true. initialize loop counter; do statement (s); increment or decrement loop counter } while (condition); Make a note that do while ends in a ; (semicolon) Note that Do While Looping statement is Exit Controlled Looping statement
85 Start Initialize Body of Loop Increment or Decrement True Test Condition Stop False
86 Difference Between While Loop and Do While Loop Sl.No. while loop do-while loop 1. The while loop tests the condition before each iteration. The do while loop tests the condition after the first iteration. 2. If the condition fails initially the loop is Skipped entirely even in the first iteration. Even if the condition fails initially the loop is executed once.
87 Example: // Print the I Values #include <stdio.h> void main() int i; clrscr(); i = 1; while(i<=10) printf( The I Value is :%d\n,i); i++; } getch(); } // Print the I Values #include <stdio.h> void main() int i; clrscr(); i = 1; do printf( The I Value is :%d\n,i); i++; } while(i<=10); getch(); }
88 The three expressions : expr1 - sets up the initial condition, expr2 - tests whether another trip through the loop should be taken, expr3 - increments or updates things after each trip. for Loop The for loop is another repetitive control structure, and is used to execute set of instruction repeatedly until the condition becomes false. To set up an initial condition and then modify some value to perform each succeeding loop as long as some condition is true. The syntax of a for loop is for( expr1; expr2 ;expr3) Body of the loop; }
89 Start Initialize; test_condition; Increment / Decrement Body of Loop Stop
90 Example Given example will print the values from 1 to 10. #include<stdio.h> void main() } for (int i = 1; i <= 10; i++) printf("i is %d\n", i); There is no need of } braces for single line statement and for multiple line it is essential else it will consider only next line of for statement.
91 Additional Features of for Loop Case 1: The statement p = 1; for (n = 0; n < 17; ++ n) can be rewritten as for (p = 1, n = 0; n < 17;++n) Case 2: The second feature is that the test condition may have any compound relation and the testing need not be limited only to the loop control variable. sum = 0; for (i = 1; i < 20 && sum < 100; ++ i) } sum = sum + i; printf( %d %d\n, i, sum);
92 Additional Features of for Loop Conti Case 3: It also permissible to use expressions in the assignment statements of initialization and increments sections. For Example: for (x = (m + n) / 2; x > 0; x = x / 2) Case 4: Another unique aspect of for loop is that one or more sections can be omitted, if necessary. For Example: m = 5; for ( ; m! = 100 ;) printf( %d\n,m); m = m + 5; } Both the initialization and increment sections are omitted in the for statement. The initialization has been done before the for statement and the control variable is incremented inside the loop. In such cases, the sections are left blank. However, the semicolons separating the sections must remain. If the test condition is not present, the for statement sets up an infinite loop. Such loops can be broken using break or goto statements in the loop.
93 Additional Features of for Loop Conti Case 5: We can set up time delay loops using the null statement as follows: for ( j = 1000; j > 0; j = j 1) 1. This is loop is executed 1000 times without producing any output; it simply causes a time delay. 2. Notice that the body of the loop contains only a semicolon, known as a null statement.
94 Nesting of for Loop The One for statement within another for statement is called Nesting for Loop. Syntax: for (initialize; test_condi; incre. / decre.) for (initialize; test_condi; incre. / decre.) } } Inner for Loop Outer for Loop
95 Example // Print the I and J Value #include<stdio.h> #include<conio.h> void main() int I, j; clrscr(); for (i = 1; I < = 10 ; I ++) printf ( The I Value is %d \n", i); } getch(); } for (j = 1; j < = 10; j ++) printf ( The J Value is %d \n", j); }
96 JUMPS IN LOOPS
97 1. Loops perform a set of operations repeatedly until the control variable fails to satisfy the test condition. 2. The number of times a loop is repeated is decided in advance and the test condition is written to achieve this. 3. Sometimes, when executing a loop it becomes desirable to skip a part of the loop or to leave the loop as soon as a certain condition occurs. 4. Jumps out of a Loop is Classified into three types 1. break; 2. continue; 3. goto;
98 The break Statement 1. A break statement is used to terminate of to exit a for, switch, while or do while statements and the execution continues following the break statement. 2. The general form of the break statement is break; 3. The break statement does not have any embedded expression or arguments. 4. The break statement is usually used at the end of each case and before the start of the next case statement. 5. The break statement causes the control to transfer out of the entire switch statement.
99 #include <stdio.h> void main() int i; clrscr(); i = 1; for(i=0;i<5;i++) } if(i==3) break; printf("%d",i); }
100 The continue Statement The continue statement is used to transfer the control to the beginning of the loop, there by terminating the current iteration of the loop and starting again from the next iteration of the same loop. The continue statement can be used within a while or a do while or a for loop. The general form or the syntax of the continue statement is continue; The continue statement does not have any expressions or arguments. Unlike break, the loop does not terminate when a continue statement is encountered, but it terminates the current iteration of the loop by skipping the remaining part of the loop and resumes the control tot the start of the loop for the next iteration.
101 #include <stdio.h> void main() int i; clrscr(); i = 1; for(i=0;i<5;i++) } if(i==3) continue; printf("%d",i); }
102 Differences Between Break and Continue Statement Sl.No. break continue 1. Used to terminate the loops or to exit loop from a switch. Used to transfer the control to the start of loop. 2. The break statement when executed causes immediate termination of loop containing it. Continue statement when executed causes Immediate termination of the current iteration of the loop.
103 The goto Statement The goto statement is used to transfer the control in a loop or a function from one point to any other portion in that program. If misused the goto statement can make a program impossible to understand. The general form or the syntax of goto statement is goto label; label: Statement (s);. statement (s); The goto statement is classified into two types a. Unconditional goto b. Conditional goto
104 Unconditional Goto The Unconditional goto means the control transfer from one block to another block without checking the test condition. Example: #include <stdio.h> void main() } clrscr(); Start: getch(); printf( Welcome\n ); goto Start;
105 Conditional Goto The Conditional goto means the control transfer from one block to another block with checking the test condition. #include <stdio.h> void main() int a, b; clrscr(); printf ( Enter the Two Value:\n ); scanf ( %d, &a, &b); if (a > b) else output_1: output_2: Stop: getch(); } goto output_1; goto output_2; printf ( A is Biggest Number ); goto Stop; printf ( B is Biggest Number ); goto Stop;
106 STORAGE CLASSES A storage class defines the scope (visibility) and life time of variables and/or functions within a C Program. There are following storage classes which can be used in a C Program * auto * register * static * extern
107 auto - Storage Class auto is the default storage class for all local variables. auto int Month; Example 1: main() auto int i=10; printf( %d,i); } Example 2: main() auto int i; printf( %d,i); }
108 register - Storage Class } register is used to define local variables that should be stored in a register instead of RAM. This means that the variable has a maximum size equal to the register size (usually one word) and cant have the unary '&' operator applied to it (as it does not have a memory location). register int Miles;
109 static - Storage Class static is the default storage class for global variables. The two variables below (count and road) both have a static storage class. static int Count;
110 main() add(); add(); } add() static int i=10; printf( \n%d,i); i+=1; } Example
111 Example void func(void); static count=10; main() while (count--) func(); } } void func( void ) static i = 5; i++; printf("i is %d and count is %d\n", i, count); }
112 extern - Storage Class All variables we have seen so far have had limited scope (the block in which they are declared) and limited lifetimes (as for automatic variables). However, in some applications it may be useful to have data which is accessible from within any block and/or which remains in existence for the entire execution of the program. Such variables are called global variables, and the C language provides storage classes which can meet these requirements; namely, the external (extern) and static (static) classes. Declaration for external variable is as follows: extern int var;
113 int i=10; main() int i=2; printf( %d,i); display(); } display() printf( \n%d,i); } Example
114 Thank You!
History of C. Introduction to C. Why are using C
Introduction to C Generation of C Language 1. In 1967, Martin Richards developed a language called BCPL (Basic Combined Programming Language) 2. In 1970, Ken Thompson created a language using many features
More informationUNIT IV 2 MARKS. ( Word to PDF Converter - Unregistered ) FUNDAMENTALS OF COMPUTING & COMPUTER PROGRAMMING
( Word to PDF Converter - Unregistered ) http://www.word-to-pdf-converter.net FUNDAMENTALS OF COMPUTING & COMPUTER PROGRAMMING INTRODUCTION TO C UNIT IV Overview of C Constants, Variables and Data Types
More informationFundamental of Programming (C)
Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi Lecture 3 Constants, Variables, Data Types, And Operations Department of Computer Engineering
More informationUNIT - I. Introduction to C Programming. BY A. Vijay Bharath
UNIT - I Introduction to C Programming Introduction to C C was originally developed in the year 1970s by Dennis Ritchie at Bell Laboratories, Inc. C is a general-purpose programming language. It has been
More informationDEPARTMENT OF MATHS, MJ COLLEGE
T. Y. B.Sc. Mathematics MTH- 356 (A) : Programming in C Unit 1 : Basic Concepts Syllabus : Introduction, Character set, C token, Keywords, Constants, Variables, Data types, Symbolic constants, Over flow,
More informationFundamentals of Programming
Fundamentals of Programming Lecture 3 - Constants, Variables, Data Types, And Operations Lecturer : Ebrahim Jahandar Borrowed from lecturer notes by Omid Jafarinezhad Outline C Program Data types Variables
More informationOperators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur
Operators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur Operators and Expressions 8/24/2012 Dept of CS&E 2 Arithmetic operators Relational operators Logical operators
More informationA complex expression to evaluate we need to reduce it to a series of simple expressions. E.g * 7 =>2+ 35 => 37. E.g.
1.3a Expressions Expressions An Expression is a sequence of operands and operators that reduces to a single value. An operator is a syntactical token that requires an action be taken An operand is an object
More informationOperators and Expressions:
Operators and Expressions: Operators and expression using numeric and relational operators, mixed operands, type conversion, logical operators, bit operations, assignment operator, operator precedence
More informationC: How to Program. Week /Mar/05
1 C: How to Program Week 2 2007/Mar/05 Chapter 2 - Introduction to C Programming 2 Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers
More informationChapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming 2 Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers 2.4 Memory Concepts 2.5 Arithmetic
More informationUNIT IV INTRODUCTION TO C
UNIT IV INTRODUCTION TO C 1. OVERVIEW OF C C is portable, structured programming language. It is robust, fast.extensible. It is used for complex programs. The root of all modern language is ALGOL (1960).
More informationUNIT- 3 Introduction to C++
UNIT- 3 Introduction to C++ C++ Character Sets: Letters A-Z, a-z Digits 0-9 Special Symbols Space + - * / ^ \ ( ) [ ] =!= . $, ; : %! &? _ # = @ White Spaces Blank spaces, horizontal tab, carriage
More informationCharacter Set. The character set of C represents alphabet, digit or any symbol used to represent information. Digits 0, 1, 2, 3, 9
Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Uppercase Alphabets Lowercase Alphabets Character Set A, B, C, Y, Z a, b, c, y, z Digits
More informationC - Basic Introduction
C - Basic Introduction C is a general-purpose high level language that was originally developed by Dennis Ritchie for the UNIX operating system. It was first implemented on the Digital Equipment Corporation
More informationLESSON 1. A C program is constructed as a sequence of characters. Among the characters that can be used in a program are:
LESSON 1 FUNDAMENTALS OF C The purpose of this lesson is to explain the fundamental elements of the C programming language. C like other languages has all alphabet and rules for putting together words
More informationProgramming in C and Data Structures [15PCD13/23] 1. PROGRAMMING IN C AND DATA STRUCTURES [As per Choice Based Credit System (CBCS) scheme]
Programming in C and Data Structures [15PCD13/23] 1 PROGRAMMING IN C AND DATA STRUCTURES [As per Choice Based Credit System (CBCS) scheme] Course objectives: The objectives of this course is to make students
More informationC Language Part 1 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee
C Language Part 1 (Minor modifications by the instructor) References C for Python Programmers, by Carl Burch, 2011. http://www.toves.org/books/cpy/ The C Programming Language. 2nd ed., Kernighan, Brian,
More informationBasics of Programming
Unit 2 Basics of Programming Problem Analysis When we are going to develop any solution to the problem, we must fully understand the nature of the problem and what we want the program to do. Without the
More informationOperators. Java operators are classified into three categories:
Operators Operators are symbols that perform arithmetic and logical operations on operands and provide a meaningful result. Operands are data values (variables or constants) which are involved in operations.
More information4.1. Structured program development Overview of C language
4.1. Structured program development 4.2. Data types 4.3. Operators 4.4. Expressions 4.5. Control flow 4.6. Arrays and Pointers 4.7. Functions 4.8. Input output statements 4.9. storage classes. UNIT IV
More informationComputers Programming Course 5. Iulian Năstac
Computers Programming Course 5 Iulian Năstac Recap from previous course Classification of the programming languages High level (Ada, Pascal, Fortran, etc.) programming languages with strong abstraction
More informationC Programming Multiple. Choice
C Programming Multiple Choice Questions 1.) Developer of C language is. a.) Dennis Richie c.) Bill Gates b.) Ken Thompson d.) Peter Norton 2.) C language developed in. a.) 1970 c.) 1976 b.) 1972 d.) 1980
More informationFeatures of C. Portable Procedural / Modular Structured Language Statically typed Middle level language
1 History C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell Labs. C was originally first implemented on the DEC
More informationData Types and Variables in C language
Data Types and Variables in C language Basic structure of C programming To write a C program, we first create functions and then put them together. A C program may contain one or more sections. They are
More informationFUNDAMENTALS OF COMPUTING & COMPUTER PROGRAMMING UNIT IV INTRODUCTION TO C
FUNDAMENTALS OF COMPUTING & COMPUTER PROGRAMMING UNIT IV INTRODUCTION TO C Overview of C Constants, Variables and Data Types Operators and Expressions Managing Input and Output operators Decision Making
More informationChapter 1 & 2 Introduction to C Language
1 Chapter 1 & 2 Introduction to C Language Copyright 2007 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 1 & 2 - Introduction to C Language 2 Outline 1.1 The History
More informationI BCA[ ] SEMESTER I CORE: C PROGRAMMING - 106A Multiple Choice Questions.
1 of 22 8/4/2018, 4:03 PM Dr.G.R.Damodaran College of Science (Autonomous, affiliated to the Bharathiar University, recognized by the UGC)Reaccredited at the 'A' Grade Level by the NAAC and ISO 9001:2008
More informationIntroduction to C Programming. Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan
Introduction to C Programming Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan Outline Printing texts Adding 2 integers Comparing 2 integers C.E.,
More informationANSI C Programming Simple Programs
ANSI C Programming Simple Programs /* This program computes the distance between two points */ #include #include #include main() { /* Declare and initialize variables */ double
More informationFundamental of C programming. - Ompal Singh
Fundamental of C programming - Ompal Singh HISTORY OF C LANGUAGE IN 1960 ALGOL BY INTERNATIONAL COMMITTEE. IT WAS TOO GENERAL AND ABSTRUCT. IN 1963 CPL(COMBINED PROGRAMMING LANGUAGE) WAS DEVELOPED AT CAMBRIDGE
More informationBCA-105 C Language What is C? History of C
C Language What is C? C is a programming language developed at AT & T s Bell Laboratories of USA in 1972. It was designed and written by a man named Dennis Ritchie. C seems so popular is because it is
More informationMODULE 2: Branching and Looping
MODULE 2: Branching and Looping I. Statements in C are of following types: 1. Simple statements: Statements that ends with semicolon 2. Compound statements: are also called as block. Statements written
More informationThe component base of C language. Nguyễn Dũng Faculty of IT Hue College of Science
The component base of C language Nguyễn Dũng Faculty of IT Hue College of Science Content A brief history of C Standard of C Characteristics of C The C compilation model Character set and keyword Data
More informationFlow Control. CSC215 Lecture
Flow Control CSC215 Lecture Outline Blocks and compound statements Conditional statements if - statement if-else - statement switch - statement? : opertator Nested conditional statements Repetitive statements
More informationPART I. Part II Answer to all the questions 1. What is meant by a token? Name the token available in C++.
Unit - III CHAPTER - 9 INTRODUCTION TO C++ Choose the correct answer. PART I 1. Who developed C++? (a) Charles Babbage (b) Bjarne Stroustrup (c) Bill Gates (d) Sundar Pichai 2. What was the original name
More informationThese are reserved words of the C language. For example int, float, if, else, for, while etc.
Tokens in C Keywords These are reserved words of the C language. For example int, float, if, else, for, while etc. Identifiers An Identifier is a sequence of letters and digits, but must start with a letter.
More informationPresented By : Gaurav Juneja
Presented By : Gaurav Juneja Introduction C is a general purpose language which is very closely associated with UNIX for which it was developed in Bell Laboratories. Most of the programs of UNIX are written
More informationCP FAQS Q-1) Define flowchart and explain Various symbols of flowchart Q-2) Explain basic structure of c language Documentation section :
CP FAQS Q-1) Define flowchart and explain Various symbols of flowchart ANS. Flowchart:- A diagrametic reperesentation of program is known as flowchart Symbols Q-2) Explain basic structure of c language
More information2/29/2016. Definition: Computer Program. A simple model of the computer. Example: Computer Program. Data types, variables, constants
Data types, variables, constants Outline.1 Introduction. Text.3 Memory Concepts.4 Naming Convention of Variables.5 Arithmetic in C.6 Type Conversion Definition: Computer Program A Computer program is a
More informationDepartment of Computer Applications
Sheikh Ul Alam Memorial Degree College Mr. Ovass Shafi. (Assistant Professor) C Language An Overview (History of C) C programming languages is the only programming language which falls under the category
More informationComputers Programming Course 7. Iulian Năstac
Computers Programming Course 7 Iulian Năstac Recap from previous course Operators in C Programming languages typically support a set of operators, which differ in the calling of syntax and/or the argument
More information3. EXPRESSIONS. It is a sequence of operands and operators that reduce to a single value.
3. EXPRESSIONS It is a sequence of operands and operators that reduce to a single value. Operator : It is a symbolic token that represents an action to be taken. Ex: * is an multiplication operator. Operand:
More informationPreview from Notesale.co.uk Page 6 of 52
Binary System: The information, which it is stored or manipulated by the computer memory it will be done in binary mode. RAM: This is also called as real memory, physical memory or simply memory. In order
More informationUnit 3 Decision making, Looping and Arrays
Unit 3 Decision making, Looping and Arrays Decision Making During programming, we have a number of situations where we may have to change the order of execution of statements based on certain conditions.
More informationCSCI 171 Chapter Outlines
Contents CSCI 171 Chapter 1 Overview... 2 CSCI 171 Chapter 2 Programming Components... 3 CSCI 171 Chapter 3 (Sections 1 4) Selection Structures... 5 CSCI 171 Chapter 3 (Sections 5 & 6) Iteration Structures
More informationData types, variables, constants
Data types, variables, constants Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers 2.4 Memory Concepts 2.5 Arithmetic in C 2.6 Decision
More informationComputer System and programming in C
1 Basic Data Types Integral Types Integers are stored in various sizes. They can be signed or unsigned. Example Suppose an integer is represented by a byte (8 bits). Leftmost bit is sign bit. If the sign
More informationUNIT 3 OPERATORS. [Marks- 12]
1 UNIT 3 OPERATORS [Marks- 12] SYLLABUS 2 INTRODUCTION C supports a rich set of operators such as +, -, *,,
More informationData Types and Variables in C language
Data Types and Variables in C language Disclaimer The slides are prepared from various sources. The purpose of the slides is for academic use only Operators in C C supports a rich set of operators. Operators
More informationProgramming and Data Structures
Programming and Data Structures Teacher: Sudeshna Sarkar sudeshna@cse.iitkgp.ernet.in Department of Computer Science and Engineering Indian Institute of Technology Kharagpur #include int main()
More informationB.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University
Unit 1 Programming Language and Overview of C 1. State whether the following statements are true or false. a. Every line in a C program should end with a semicolon. b. In C language lowercase letters are
More informationPESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Basic Science and Humanities
INTERNAL ASSESSMENT TEST 1 SOLUTION PART 1 1 a Define algorithm. Write an algorithm to find sum and average of three numbers. 4 An Algorithm is a step by step procedure to solve a given problem in finite
More informationC OVERVIEW. C Overview. Goals speed portability allow access to features of the architecture speed
C Overview C OVERVIEW Goals speed portability allow access to features of the architecture speed C fast executables allows high-level structure without losing access to machine features many popular languages
More informationLecture 02 C FUNDAMENTALS
Lecture 02 C FUNDAMENTALS 1 Keywords C Fundamentals auto double int struct break else long switch case enum register typedef char extern return union const float short unsigned continue for signed void
More informationA Fast Review of C Essentials Part I
A Fast Review of C Essentials Part I Structural Programming by Z. Cihan TAYSI Outline Program development C Essentials Functions Variables & constants Names Formatting Comments Preprocessor Data types
More informationWork relative to other classes
Work relative to other classes 1 Hours/week on projects 2 C BOOTCAMP DAY 1 CS3600, Northeastern University Slides adapted from Anandha Gopalan s CS132 course at Univ. of Pittsburgh Overview C: A language
More informationExpressions. Arithmetic expressions. Logical expressions. Assignment expression. n Variables and constants linked with operators
Expressions 1 Expressions n Variables and constants linked with operators Arithmetic expressions n Uses arithmetic operators n Can evaluate to any value Logical expressions n Uses relational and logical
More informationP.E.S. INSTITUTE OF TECHNOLOGY BANGALORE SOUTH CAMPUS 1 ST INTERNAL ASSESMENT TEST (SCEME AND SOLUTIONS)
FACULTY: Ms. Saritha P.E.S. INSTITUTE OF TECHNOLOGY BANGALORE SOUTH CAMPUS 1 ST INTERNAL ASSESMENT TEST (SCEME AND SOLUTIONS) SUBJECT / CODE: Programming in C and Data Structures- 15PCD13 What is token?
More informationThere are algorithms, however, that need to execute statements in some other kind of ordering depending on certain conditions.
Introduction In the programs that we have dealt with so far, all statements inside the main function were executed in sequence as they appeared, one after the other. This type of sequencing is adequate
More informationC OVERVIEW BASIC C PROGRAM STRUCTURE. C Overview. Basic C Program Structure
C Overview Basic C Program Structure C OVERVIEW BASIC C PROGRAM STRUCTURE Goals The function main( )is found in every C program and is where every C program begins speed execution portability C uses braces
More informationJava Notes. 10th ICSE. Saravanan Ganesh
Java Notes 10th ICSE Saravanan Ganesh 13 Java Character Set Character set is a set of valid characters that a language can recognise A character represents any letter, digit or any other sign Java uses
More informationIntroduction to C. History of C:
History of C: Introduction to C C is a structured/procedure oriented, high-level and machine independent programming language. The root of all modern languages is ALGOL, introduced in the early 1960. In
More informationINDORE INDIRA SCHOOL OF CAREER STUDIES C LANGUAGE Class B.Sc. - IIND Sem
UNIT- I ALGORITHM: An algorithm is a finite sequence of instructions, a logic and explicit step-by-step procedure for solving a problem starting from a known beginning. OR A sequential solution of any
More informationVariables Data types Variable I/O. C introduction. Variables. Variables 1 / 14
C introduction Variables Variables 1 / 14 Contents Variables Data types Variable I/O Variables 2 / 14 Usage Declaration: t y p e i d e n t i f i e r ; Assignment: i d e n t i f i e r = v a l u e ; Definition
More informationComputers Programming Course 6. Iulian Năstac
Computers Programming Course 6 Iulian Năstac Recap from previous course Data types four basic arithmetic type specifiers: char int float double void optional specifiers: signed, unsigned short long 2 Recap
More informationBasic Elements of C. Staff Incharge: S.Sasirekha
Basic Elements of C Staff Incharge: S.Sasirekha Basic Elements of C Character Set Identifiers & Keywords Constants Variables Data Types Declaration Expressions & Statements C Character Set Letters Uppercase
More informationUnit-II Programming and Problem Solving (BE1/4 CSE-2)
Unit-II Programming and Problem Solving (BE1/4 CSE-2) Problem Solving: Algorithm: It is a part of the plan for the computer program. An algorithm is an effective procedure for solving a problem in a finite
More informationCS6202 - PROGRAMMING & DATA STRUCTURES UNIT I Part - A 1. W hat are Keywords? Keywords are certain reserved words that have standard and pre-defined meaning in C. These keywords can be used only for their
More informationKARMAYOGI ENGINEERING COLLEGE, Shelve Pandharpur
KARMAYOGI ENGINEERING COLLEGE, Shelve Pandharpur Bachelor of Engineering First Year Subject Name: Computer Programming Objective: 1. This course is designed to provide a brief study of the C programming
More informationADARSH VIDYA KENDRA NAGERCOIL COMPUTER SCIENCE. Grade: IX C++ PROGRAMMING. Department of Computer Science 1
NAGERCOIL COMPUTER SCIENCE Grade: IX C++ PROGRAMMING 1 C++ 1. Object Oriented Programming OOP is Object Oriented Programming. It was developed to overcome the flaws of the procedural approach to programming.
More informationModel Viva Questions for Programming in C lab
Model Viva Questions for Programming in C lab Title of the Practical: Assignment to prepare general algorithms and flow chart. Q1: What is a flowchart? A1: A flowchart is a diagram that shows a continuous
More informationObjectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program
Objectives Chapter 2: Basic Elements of C++ In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates
More informationChapter 2: Basic Elements of C++
Chapter 2: Basic Elements of C++ Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates
More informationFundamental Data Types. CSE 130: Introduction to Programming in C Stony Brook University
Fundamental Data Types CSE 130: Introduction to Programming in C Stony Brook University Program Organization in C The C System C consists of several parts: The C language The preprocessor The compiler
More informationPrepared by: Shraddha Modi
Prepared by: Shraddha Modi Introduction Operator: An operator is a symbol that tells the Computer to perform certain mathematical or logical manipulations. Expression: An expression is a sequence of operands
More informationChapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction
Chapter 2: Basic Elements of C++ C++ Programming: From Problem Analysis to Program Design, Fifth Edition 1 Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers
More informationOperators in C. Staff Incharge: S.Sasirekha
Operators in C Staff Incharge: S.Sasirekha Operators An operator is a symbol which helps the user to command the computer to do a certain mathematical or logical manipulations. Operators are used in C
More informationPESIT Bangalore South Campus Hosur Road (1km before Electronic City), Bengaluru Department of Basic Science and Humanities
SOLUTION OF CONTINUOUS INTERNAL EVALUATION TEST -1 Date : 27-02 2018 Marks:60 Subject & Code : Programming in C and Data Structures- 17PCD23 Name of faculty : Dr. J Surya Prasad/Mr. Naushad Basha Saudagar
More informationProgramming Fundamentals (CS 302 ) Dr. Ihsan Ullah. Lecturer Department of Computer Science & IT University of Balochistan
Programming Fundamentals (CS 302 ) Dr. Ihsan Ullah Lecturer Department of Computer Science & IT University of Balochistan 1 Outline p Introduction p Program development p C language and beginning with
More informationOutline. Performing Computations. Outline (cont) Expressions in C. Some Expression Formats. Types for Operands
Performing Computations C provides operators that can be applied to calculate expressions: tax is 8.5% of the total sale expression: tax = 0.085 * totalsale Need to specify what operations are legal, how
More informationCOMPUTER SCIENCE HIGHER SECONDARY FIRST YEAR. VOLUME II - CHAPTER 10 PROBLEM SOLVING TECHNIQUES AND C PROGRAMMING 1,2,3 & 5 MARKS
COMPUTER SCIENCE HIGHER SECONDARY FIRST YEAR VOLUME II - CHAPTER 10 PROBLEM SOLVING TECHNIQUES AND C PROGRAMMING 1,2,3 & 5 MARKS S.LAWRENCE CHRISTOPHER, M.C.A., B.Ed., LECTURER IN COMPUTER SCIENCE PONDICHERRY
More informationUnit 3. Operators. School of Science and Technology INTRODUCTION
INTRODUCTION Operators Unit 3 In the previous units (unit 1 and 2) you have learned about the basics of computer programming, different data types, constants, keywords and basic structure of a C program.
More informationDepartment of Computer Science
Department of Computer Science Definition An operator is a symbol (+,-,*,/) that directs the computer to perform certain mathematical or logical manipulations and is usually used to manipulate data and
More informationMore Programming Constructs -- Introduction
More Programming Constructs -- Introduction We can now examine some additional programming concepts and constructs Chapter 5 focuses on: internal data representation conversions between one data type and
More informationExpressions and Data Types CSC 121 Spring 2015 Howard Rosenthal
Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types
More informationComputer Science & Information Technology (CS) Rank under AIR 100. Examination Oriented Theory, Practice Set Key concepts, Analysis & Summary
GATE- 2016-17 Postal Correspondence 1 C-Programming Computer Science & Information Technology (CS) 20 Rank under AIR 100 Postal Correspondence Examination Oriented Theory, Practice Set Key concepts, Analysis
More informationDETAILED SYLLABUS INTRODUCTION TO C LANGUAGE
COURSE TITLE C LANGUAGE DETAILED SYLLABUS SR.NO NAME OF CHAPTERS & DETAILS HOURS ALLOTTED 1 INTRODUCTION TO C LANGUAGE About C Language Advantages of C Language Disadvantages of C Language A Sample Program
More informationC++ Programming: From Problem Analysis to Program Design, Third Edition
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 2: Basic Elements of C++ Objectives (continued) Become familiar with the use of increment and decrement operators Examine
More informationFull file at C How to Program, 6/e Multiple Choice Test Bank
2.1 Introduction 2.2 A Simple Program: Printing a Line of Text 2.1 Lines beginning with let the computer know that the rest of the line is a comment. (a) /* (b) ** (c) REM (d)
More informationDifferentiate Between Keywords and Identifiers
History of C? Why we use C programming language Martin Richards developed a high-level computer language called BCPL in the year 1967. The intention was to develop a language for writing an operating system(os)
More informationIECD Institute for Entrepreneurship and Career Development Bharathidasan University, Tiruchirappalli 23.
Subject code - CCP01 Chapt Chapter 1 INTRODUCTION TO C 1. A group of software developed for certain purpose are referred as ---- a. Program b. Variable c. Software d. Data 2. Software is classified into
More informationIntroduction. Following are the types of operators: Unary requires a single operand Binary requires two operands Ternary requires three operands
Introduction Operators are the symbols which operates on value or a variable. It tells the compiler to perform certain mathematical or logical manipulations. Can be of following categories: Unary requires
More informationHISTORY OF C LANGUAGE. Facts about C. Why Use C?
1 HISTORY OF C LANGUAGE C is a general-purpose, procedural, imperative computer programming language developed in 1972 by Dennis M. Ritchie at the Bell Telephone Laboratories to develop the UNIX operating
More informationProgramming for Engineers Iteration
Programming for Engineers Iteration ICEN 200 Spring 2018 Prof. Dola Saha 1 Data type conversions Grade average example,-./0 class average = 23450-67 893/0298 Grade and number of students can be integers
More informationSEQUENTIAL STRUCTURE. Erkut ERDEM Hacettepe University October 2010
SEQUENTIAL STRUCTURE Erkut ERDEM Hacettepe University October 2010 History of C C Developed by by Denis M. Ritchie at AT&T Bell Labs from two previous programming languages, BCPL and B Used to develop
More informationThe C++ Language. Arizona State University 1
The C++ Language CSE100 Principles of Programming with C++ (based off Chapter 2 slides by Pearson) Ryan Dougherty Arizona State University http://www.public.asu.edu/~redoughe/ Arizona State University
More informationDecision Making -Branching. Class Incharge: S. Sasirekha
Decision Making -Branching Class Incharge: S. Sasirekha Branching The C language programs presented until now follows a sequential form of execution of statements. Many times it is required to alter the
More informationProblem Solving and 'C' Programming
Problem Solving and 'C' Programming Targeted at: Entry Level Trainees Session 05: Selection and Control Structures 2007, Cognizant Technology Solutions. All Rights Reserved. The information contained herein
More informationPart I Part 1 Expressions
Writing Program in C Expressions and Control Structures (Selection Statements and Loops) Jan Faigl Department of Computer Science Faculty of Electrical Engineering Czech Technical University in Prague
More information