INTRODUCTION TO C
INTRODUCTION TO C <ul><li>C was developed by Dennis  Ritchie at Bell laboratory in 1972  </li></ul><ul><li>It is an upgrad...
Features of C <ul><li>It is a structured programming language. </li></ul><ul><li>It is highly portable. </li></ul><ul><li>...
Steps in learning C Character Set Programs Instructions Tokens
C Character Set C Character Set Execution Character Set Source Character Set Special Characters Digits Alphabets Escape Se...
C Character Set (Cont) <ul><li>Source Character Set </li></ul><ul><ul><li>It is used to construct the statements in the pr...
Source Character Set Letters a to z ,A to Z Digits  0 to 9 Special Characters ! @ # $ % ^ & * ( ) _ - + =  | { } [ ] etc,....
Special characters <ul><li>Comma  ,  </li></ul><ul><li>Period or dot   . </li></ul><ul><li>Semicolon  ; </li></ul><ul><li>...
<ul><li>Ampersand  & </li></ul><ul><li>Caret  ^ </li></ul><ul><li>Asterisk  * </li></ul><ul><li>Minus - </li></ul><ul><li>...
Executable Character Set Characters Escape Sequence Back Space  Horizontal  Space 	 Vertical Space v Newline
C Tokens <ul><li>The smallest element in the C language is the token. </li></ul><ul><li>It may be a single character or a ...
C Tokens (Cont) C Tokens Identifiers Eg:main, avg Keywords Eg: int, for operators Eg: + - Strings Eg: “ab” spI symbol Eg: ...
Executing a C Program Creating the Program Compilation Linking Execution
Executing a C Program (Cont) <ul><li>Enter the program in a C editor. </li></ul><ul><li>Save the program (File    Save) o...
Executing C program using UNIX <ul><li>Enter the program in vi editor. </li></ul><ul><li>Save the file using  :wq   </li><...
Structure of C program DOCUMENTATION SECTION PREPROCESSOR SECTION DEFINITION SECTION GLOBAL DECLARATION SECTION main() { D...
<ul><li>Documentation Section </li></ul><ul><ul><li>It contains the comment lines. </li></ul></ul><ul><li>Preprocessor Sec...
C Programs <ul><li>C program may have many functions. </li></ul><ul><li>One and only one of the functions  MUST BE  named ...
Preprocessor Directives <ul><li>Special instructions to the preprocessor that tells how to prepare the program for compila...
Comments (Program documentation) <ul><li>The compiler simply ignores comments when it translates the program into executab...
Comments (Cont) <ul><li>Comments can appear anywhere in a program. </li></ul><ul><li>Comments are also found wherever it i...
C program <ul><li>/* Example program in C*/  Comments </li></ul><ul><li># include <stdio.h>  P reprocessor Section </li></...
C Tokens <ul><li>Identifiers </li></ul><ul><li>Keywords </li></ul><ul><li>Constants </li></ul><ul><li>Operators </li></ul>...
Identifiers <ul><li>Identifiers are names given to various program elements such as variables, functions and arrays etc,. ...
Rules for naming identifier <ul><li>First character must be alphabetic or underscore. </li></ul><ul><li>Must consist only ...
Examples of Valid and Invalid Names
Variables <ul><li>Variable is an identifier that is used to represent some specified type of information. </li></ul><ul><l...
Keywords <ul><li>It is a reserved words. </li></ul><ul><li>Cannot be used for anything else. </li></ul><ul><li>Examples: <...
Keywords <ul><li>Auto  register  Continue </li></ul><ul><li>Double  typedef  For </li></ul><ul><li>Int  Char  signed </li>...
Constants <ul><li>It is an entity whose value does not changes during the execution. </li></ul><ul><li>Eg: x=3 </li></ul><...
Types <ul><li>Numeric constants </li></ul><ul><li>Character constant </li></ul>
Constants Constants Character Constants Numeric Constants Real Constant Integer Constant String  Constant Single Character...
Numeric constants <ul><li>Integer constants </li></ul><ul><li>It is formed using a sequence of digits. </li></ul><ul><ul><...
Rules for defining Integer Constant <ul><li>It must have atleast one digit. </li></ul><ul><li>Decimal point are not allowe...
Numeric constants <ul><li>Real constants </li></ul><ul><li>It is formed using a sequence of digits but it contain decimal ...
Character constants <ul><li>Single character constant </li></ul><ul><ul><li>A character constant is a single character the...
Character constants <ul><li>String constants </li></ul><ul><li>String constant are sequence of characters enclosed with in...
Operators <ul><li>An operator is a symbol that specifies an operation to be performed on the operands. </li></ul><ul><li>E...
Data Types <ul><li>A  Data type  is the type of data that are going to  access within the program. </li></ul>
Standard   Data Types These Standard type can be used to build more complex data types called  Derived Types  (e.g. pointe...
Data types Data type  Size(bytes)  Range  Format string Char  1  -128 to 127  %c int  2  -32,768 to 32,767  %d Float  4  3...
<ul><li>integer </li></ul><ul><ul><li>A number without a fraction part : integral number. </li></ul></ul><ul><ul><li>C sup...
Floating Point <ul><li>A floating-point type is a number with a fractional part, e.g. 56.78 </li></ul><ul><li>Floating poi...
character  <ul><li>Character are generally stored using 8 bits(1 Byte) of the internal storage. </li></ul>Character   ASCI...
void <ul><ul><li>The void type has no values and no operations. </li></ul></ul><ul><ul><li>Both the set of values and the ...
Variable ’ s Declaration <ul><li>To create a variable, you must specify the  type  and then its  identifier  : </li></ul><...
Entire Data types in c: Data type  Size(bytes)  Range  Format string Char  1  128 to 127  %c Unsigned char  1  0 to 255  %...
Types of Operator <ul><li>Arithmetic operator </li></ul><ul><li>Relational operator </li></ul><ul><li>Logical operator </l...
Arithmetic operator <ul><li>It is used to carry out  arithmetic operations  like addition, subtraction etc, </li></ul><ul>...
Sample program <ul><li>#include<stdio.h>  // Header File </li></ul><ul><li>#include <conio.h> </li></ul><ul><li>int b=10; ...
Division operator on Different  Data Type Operation Result Example int/int int 5/2  =  2 int/real real 5/2.0 =  2.5 real/i...
Sample program <ul><li>#include<stdio.h> </li></ul><ul><li>#include <conio.h> </li></ul><ul><li>void main ( ) </li></ul><u...
Output <ul><li>value a/b is:2 </li></ul><ul><li>value a/d is:3.333333 </li></ul>
Relational operator <ul><li>It is used to  compare  two or more operands. </li></ul><ul><li>Eg :< , > , <= , >=, != etc,. ...
Logical operator <ul><li>It is used to  combine  the result of two or more condition. </li></ul><ul><li>AND(&&) </li></ul>...
Sample program <ul><li>#include<stdio.h> </li></ul><ul><li>#include <conio.h> </li></ul><ul><li>void main ( ) </li></ul><u...
Output <ul><li>a is bigger than b </li></ul><ul><li>a is biggest </li></ul>
Assignment operator <ul><li>It is used to  assign a value or expression  etc to a variable. </li></ul><ul><li>Eg: a =10. <...
Assignment operator(Cont) <ul><li>Compound operator </li></ul><ul><li>It is also used to assign a value to a variable. </l...
Sample program <ul><li>#include<stdio.h>  </li></ul><ul><li>#include <conio.h> </li></ul><ul><li>int b=10; </li></ul><ul><...
Output <ul><li>The sum of the two values:8 </li></ul>
Increment or decrement operator(Unary) <ul><li>It is used to  Increment or decrement  an operand. </li></ul><ul><li>Eg: ++...
Sample Program <ul><li>#include<stdio.h>  </li></ul><ul><li>#include <conio.h> </li></ul><ul><li>void main ( ) </li></ul><...
Output <ul><li>Post increment Value:5 </li></ul><ul><li>Pre increment Value:7 </li></ul><ul><li>Pre decrement Value:6 </li...
Bitwise operator <ul><li>It is used to manipulate data at bit level. </li></ul><ul><li>Eg: a=5 i.e 0000 0101 </li></ul><ul...
Sample program <ul><li>#include<stdio.h> </li></ul><ul><li>#include <conio.h> </li></ul><ul><li>void main ( ) </li></ul><u...
Output <ul><li>value a&b is:4 </li></ul>
Conditional Operator (or) Ternary Operator <ul><li>It is used to checks the condition and execute the statement depending ...
Sample Program <ul><li>#include<stdio.h>  </li></ul><ul><li>#include <conio.h> </li></ul><ul><li>void main ( ) </li></ul><...
Output <ul><li>The Larger Value is 8 </li></ul>
Special Operator <ul><li>comma operator ( , ) </li></ul><ul><li>sizeof  operator </li></ul><ul><li>pointer operator  (& , ...
<ul><li>#include<stdio.h> </li></ul><ul><li>#include <conio.h> </li></ul><ul><li>void main ( ) </li></ul><ul><li>{ </li></...
Output <ul><li>size of int is: 2 </li></ul>
Expression <ul><li>An expression represent data item such as variable, constant are interconnected using operators. </li><...
Operator Precedence & Associativity <ul><li>The arithmetic expressions  evaluation are carried out based on the precedence...
Precedence Operator High * , / , % Low + , -
Example <ul><li>5 - 20/4 + 3*3 – 1 </li></ul><ul><li>= 5 - 5 + 9 – 1 </li></ul><ul><li>= 0 + 9 – 1 </li></ul><ul><li>= 9 –...
Example <ul><li>5 – (20/4) + 3*(3 – 1) </li></ul><ul><li>= 5 - 5 + 3*2 </li></ul><ul><li>= 5 - 5 + 6 </li></ul><ul><li>= 6...
Type Conversion <ul><li>Converting the type of an expression from one type to another type. </li></ul><ul><li>Eg:  x = (in...
Sample Program <ul><li>#include<stdio.h> </li></ul><ul><li>#include <conio.h> </li></ul><ul><li>void main ( ) </li></ul><u...
Input/Output Function Input/Output  Function Unformatted Formatted Output printf() fprintf() Input scanf() fscanf() Input ...
Formatted Input/Output <ul><li>C uses two functions for  formatted input and output. </li></ul><ul><li>Formatted input  : ...
Formatted   Input and Output
Standard Output <ul><li>The standard output file is the monitor. </li></ul><ul><li>Like the keyboard, it is a  text  file....
Format of printf Statement
Formatted Input ( scanf ) <ul><li>The standard formatted input function in C is  scanf  (scan formatted). </li></ul><ul><l...
Format of scanf Statement
Character Test Function <ul><li>It is used to test the character taken from the input. </li></ul><ul><li>isalpha(ch) </li>...
 
Decision Making <ul><li>It is used to change the order of the program based on condition. </li></ul><ul><li>Categories: </...
Decision Making (cont) <ul><li>Sequential structure </li></ul><ul><ul><li>In which instructions are executed in sequence. ...
SELECTION STRUCTURE <ul><li>It allows the program to make a choice from alternative paths.  </li></ul><ul><li>C provide th...
IF Statement <ul><li>Syntax </li></ul><ul><li>IF (condition is true) </li></ul><ul><li>{ </li></ul><ul><li>Statements; </l...
Example <ul><li>#include<stdio.h> </li></ul><ul><li>#include <conio.h> </li></ul><ul><li>void main ( ) </li></ul><ul><li>{...
Output <ul><li>Enter the number: 12 </li></ul><ul><li>a is greater than 10 </li></ul>
IF…ELSE Statement <ul><li>Syntax </li></ul><ul><li>IF (condition)  </li></ul><ul><li>{ </li></ul><ul><li>True statements; ...
<ul><li>#include<stdio.h> </li></ul><ul><li>#include <conio.h> </li></ul><ul><li>void main ( ) </li></ul><ul><li>{ </li></...
NESTED  IF… ELSE If Condition  1 False  Statements True If  Condition  2 True False True statements False statements
NESTED  IF… ELSE <ul><li>Syntax </li></ul><ul><li>IF (condition1)  </li></ul><ul><li>{ </li></ul><ul><li>IF (condition2)  ...
IF…ELSE  LADDER Condition 1  Statements Condition 2  Statements Condition 3 Statements Statements TRUE TRUE TRUE FALSE FAL...
IF…ELSE  LADDER <ul><li>Syntax </li></ul><ul><li>IF (condition1)  </li></ul><ul><li>{ </li></ul><ul><li>statements; </li><...
Example <ul><li>#include<stdio.h> </li></ul><ul><li>#include<conio.h> </li></ul><ul><li>void main() </li></ul><ul><li>{ </...
<ul><li>else if(avg>=50) </li></ul><ul><li>{ </li></ul><ul><li>printf(&quot;Second class&quot;); </li></ul><ul><li>} </li>...
Output <ul><li>Enter the marks:65 </li></ul><ul><li>75 </li></ul><ul><li>70 </li></ul><ul><li>The average is:70.000000 </l...
Looping structure <ul><li>It is used to execute some instructions several time based on some condition. </li></ul><ul><ul>...
WHILE Loop  <ul><li>Syntax </li></ul><ul><li>. </li></ul><ul><li>WHILE (condition) </li></ul><ul><li>{ </li></ul><ul><li>....
Example <ul><li>#include<stdio.h> </li></ul><ul><li>#include<conio.h> </li></ul><ul><li>void main() </li></ul><ul><li>{ </...
Output <ul><li>Enter the Number:3 </li></ul><ul><li>The value of 3! is: 6 </li></ul>
DO…WHILE Loop  <ul><li>Syntax </li></ul><ul><li>do </li></ul><ul><li>{ </li></ul><ul><li>Body of the loop </li></ul><ul><l...
for loop  <ul><li>Syntax </li></ul><ul><li>for (initialization; test condition; Increment/Decrement) </li></ul><ul><li>{ <...
for loop  Initialization condition False Body of the loop Inc / Decrement
Example <ul><li>#include<stdio.h> </li></ul><ul><li>#include<conio.h> </li></ul><ul><li>void main() </li></ul><ul><li>{ </...
Output <ul><li>Enter the Number:3 </li></ul><ul><li>The value of 3! is: 6 </li></ul>
Nested for loop  <ul><li>Syntax </li></ul><ul><li>for (initi; cond; Inc/Dec) </li></ul><ul><li>{ </li></ul><ul><li>for (in...
CASE structure Case 1 Case 2 Default case Switch
CASE structure <ul><li>Syntax </li></ul><ul><li>switch (expression) </li></ul><ul><li>{ </li></ul><ul><li>case constant 1:...
Example <ul><li>#include<stdio.h> </li></ul><ul><li>#include<conio.h> </li></ul><ul><li>void main() </li></ul><ul><li>{ </...
<ul><li>case 2: </li></ul><ul><li>{ </li></ul><ul><li>printf(&quot;
 Its in case 2&quot;); </li></ul><ul><li>break; </li><...
Output <ul><li>Enter the Number:2 </li></ul><ul><li>Its in case 2 </li></ul>
break Statement <ul><li>It is used to terminate the loop </li></ul><ul><li>When a  break  statement is encountered inside ...
Loops with break Statement <ul><li>while(cond) </li></ul><ul><li>{ </li></ul><ul><li>………… </li></ul><ul><li>if(cond) </li>...
<ul><li>do </li></ul><ul><li>{ </li></ul><ul><li>………… </li></ul><ul><li>if(cond) </li></ul><ul><li>break; </li></ul><ul><l...
<ul><li>for (initi; condt; Inc/Dec) </li></ul><ul><li>{ </li></ul><ul><li>………… </li></ul><ul><li>if(cond) </li></ul><ul><l...
Continue Statement <ul><li>When a  continue  statement is encountered inside a loop, the control is transferred to the beg...
Loops with continue Statement <ul><li>while(cond) </li></ul><ul><li>{ </li></ul><ul><li>………… </li></ul><ul><li>if(cond) </...
<ul><li>do </li></ul><ul><li>{ </li></ul><ul><li>………… </li></ul><ul><li>if(cond) </li></ul><ul><li>continue; </li></ul><ul...
<ul><li>for (initi; condt; Inc/Dec) </li></ul><ul><li>{ </li></ul><ul><li>………… </li></ul><ul><li>if(cond) </li></ul><ul><l...
goto Statement <ul><li>When a  goto  statement is encountered inside a loop, the control is transferred to the beginning. ...
Syntax for goto Statement <ul><li>label: </li></ul><ul><li>………… </li></ul><ul><li>………… </li></ul><ul><li>………… </li></ul><u...
<ul><li>goto label;  </li></ul><ul><li>………… </li></ul><ul><li>………… </li></ul><ul><li>………… </li></ul><ul><li>  label: </li>...
 
getchar() Example <ul><li>#include<stdio.h> </li></ul><ul><li>#include<conio.h> </li></ul><ul><li>#include<ctype.h> </li><...
<ul><li>if(islower(x)) </li></ul><ul><li>putchar(toupper(x)); </li></ul><ul><li>else </li></ul><ul><li>putchar(tolower(x))...
getche() Example <ul><li>#include <stdio.h> </li></ul><ul><li>#include <conio.h> </li></ul><ul><li>void main() </li></ul><...
<ul><li>printf(&quot;
string is:&quot;); </li></ul><ul><li>putch(c); </li></ul><ul><li>getch(); </li></ul><ul><li>} </li><...
Getch() Example <ul><li>#include <stdio.h> </li></ul><ul><li>#include <conio.h> </li></ul><ul><li>void main() </li></ul><u...
<ul><li>printf(&quot;
string is:&quot;); </li></ul><ul><li>putch(c); </li></ul><ul><li>getch(); </li></ul><ul><li>} </li><...
getc Example <ul><li>#include<stdio.h> </li></ul><ul><li>#include<conio.h> </li></ul><ul><li>#include<ctype.h> </li></ul><...
<ul><li>if(islower(x)) </li></ul><ul><li>putc(toupper(x),stdout); </li></ul><ul><li>else </li></ul><ul><li>putc(tolower(x)...
gets() Example <ul><li>#include <stdio.h> </li></ul><ul><li>#include<conio.h> </li></ul><ul><li>void main() </li></ul><ul>...
<ul><li>printf(&quot;The string is:&quot;); </li></ul><ul><li>puts(c); </li></ul><ul><li>getch(); </li></ul><ul><li>} </li...
Example <ul><li>#include<stdio.h> </li></ul><ul><li>#include<conio.h> </li></ul><ul><li>void main() </li></ul><ul><li>{ </...
<ul><li>switch(n) </li></ul><ul><li>{ </li></ul><ul><li>  case 1: </li></ul><ul><li>c=a+b; </li></ul><ul><li>printf(&quot;...
<ul><li>case 3: </li></ul><ul><li>c=a*b; </li></ul><ul><li>printf(&quot;
The result of Multiplication is:%d&quot;,c); </li...
Output <ul><li>Enter the value of a,b:5 </li></ul><ul><li>6 </li></ul><ul><li>MENU </li></ul><ul><li>1.ADD </li></ul><ul><...
Finding Armstrong No <ul><li>#include<stdio.h> </li></ul><ul><li>#include<conio.h> </li></ul><ul><li>void main() </li></ul...
<ul><li>if(a==sum) </li></ul><ul><li>{ </li></ul><ul><li>  printf(&quot;
It is an armstrong number&quot;); </li></ul><ul><...
Output <ul><li>Enter the number:153 </li></ul><ul><li>It is an armstrong number </li></ul>
Sum of the Digits <ul><li>#include<stdio.h> </li></ul><ul><li>#include<conio.h> </li></ul><ul><li>void main() </li></ul><u...
<ul><li>sum=sum+r; </li></ul><ul><li>n=n/10; </li></ul><ul><li>} </li></ul><ul><li>printf(&quot;sum of the digits is:%d&qu...
Output <ul><li>Enter the no:156 </li></ul><ul><li>sum of the digits is:12 </li></ul>
Reverse of a number <ul><li>#include<stdio.h> </li></ul><ul><li>#include<conio.h> </li></ul><ul><li>void main() </li></ul>...
<ul><li>{ </li></ul><ul><li>r=n%10; </li></ul><ul><li>sum=sum*10+r; </li></ul><ul><li>n=n/10; </li></ul><ul><li>  } </li><...
Output <ul><li>Enter the no:567 </li></ul><ul><li>Reverse of the number is:765 </li></ul>
Fibonacci Series <ul><li>#include<stdio.h> </li></ul><ul><li>#include<conio.h> </li></ul><ul><li>void main() </li></ul><ul...
<ul><li>while(f<n) </li></ul><ul><li>{ </li></ul><ul><li>  f=f1+f2; </li></ul><ul><li>f1=f2; </li></ul><ul><li>  f2=f; </l...
Output <ul><li>Enter the number:5 </li></ul><ul><li>  0  1  1  2  3  5 </li></ul>
Swapping  <ul><li>#include<stdio.h> </li></ul><ul><li>#include <conio.h> </li></ul><ul><li>void main ( ) </li></ul><ul><li...
<ul><li>printf(&quot; 
The value of a is:%d&quot;,a); </li></ul><ul><li>printf(&quot; 
The value of b is:%d&quot;,b); </li...
Swapping without using third variable <ul><li>#include<stdio.h> </li></ul><ul><li>#include <conio.h> </li></ul><ul><li>voi...
<ul><li>a=a+b; </li></ul><ul><li>b=a-b; </li></ul><ul><li>a=a-b; </li></ul><ul><li>printf(&quot; 
The value of a is:%d&quo...
Quadratic Equation <ul><li>#include<stdio.h> </li></ul><ul><li>#include <conio.h> </li></ul><ul><li>#include<math.h> </li>...
<ul><li>if(d>=0) </li></ul><ul><li>{ </li></ul><ul><li>r1=(-b+sqrt(d))/(2*a); </li></ul><ul><li>r2=(-b-sqrt(d))/(2*a); </l...
Output <ul><li>Enter the value of a:4 </li></ul><ul><li>Enter the value of b:5 </li></ul><ul><li>Enter the value of c:6 </...
Upcoming SlideShare
Loading in …5
×

Unit 4 Foc

4,345 views

Published on

INTRODUCTION TO C

Published in: Technology
1 Comment
1 Like
Statistics
Notes
No Downloads
Views
Total views
4,345
On SlideShare
0
From Embeds
0
Number of Embeds
414
Actions
Shares
0
Downloads
421
Comments
1
Likes
1
Embeds 0
No embeds

No notes for slide

Unit 4 Foc

  1. 1. INTRODUCTION TO C
  2. 2. INTRODUCTION TO C <ul><li>C was developed by Dennis Ritchie at Bell laboratory in 1972 </li></ul><ul><li>It is an upgrade version of languages B and BCPL. </li></ul>
  3. 3. Features of C <ul><li>It is a structured programming language. </li></ul><ul><li>It is highly portable. </li></ul><ul><li>It is a middle level language. </li></ul><ul><li>It is a case sensitive language. </li></ul><ul><li>It uses Top-Down approach. </li></ul><ul><li>It is a Free form language.etc,. </li></ul>
  4. 4. Steps in learning C Character Set Programs Instructions Tokens
  5. 5. C Character Set C Character Set Execution Character Set Source Character Set Special Characters Digits Alphabets Escape Sequence White Spaces
  6. 6. C Character Set (Cont) <ul><li>Source Character Set </li></ul><ul><ul><li>It is used to construct the statements in the program. </li></ul></ul><ul><li>Executable Character Set </li></ul><ul><ul><li>These characters are employed at the time of execution i.e. they have effects only when the program is being executed. </li></ul></ul>
  7. 7. Source Character Set Letters a to z ,A to Z Digits 0 to 9 Special Characters ! @ # $ % ^ & * ( ) _ - + = | { } [ ] etc,. White Spaces Blank Space ,Horizontal tab, New line, Vertical tab etc,.
  8. 8. Special characters <ul><li>Comma , </li></ul><ul><li>Period or dot . </li></ul><ul><li>Semicolon ; </li></ul><ul><li>Colon : </li></ul><ul><li>Apostrophe ‘ </li></ul><ul><li>Quotation mark “ </li></ul><ul><li>Exclamation mark ! </li></ul><ul><li>Vertical bar | </li></ul><ul><li>Back Slash </li></ul><ul><li>Tilde ~ </li></ul><ul><li>Underscore - </li></ul><ul><li>Dollar $ </li></ul><ul><li>Question mark ? </li></ul>
  9. 9. <ul><li>Ampersand & </li></ul><ul><li>Caret ^ </li></ul><ul><li>Asterisk * </li></ul><ul><li>Minus - </li></ul><ul><li>Addition + </li></ul><ul><li>Lesser than < </li></ul><ul><li>Greater than > </li></ul><ul><li>Parenthesis () </li></ul><ul><li>Bracket [] </li></ul><ul><li>Braces {} </li></ul><ul><li>Percentage % </li></ul><ul><li>Hash # </li></ul><ul><li>Equal to = </li></ul><ul><li>At the rate @ </li></ul>
  10. 10. Executable Character Set Characters Escape Sequence Back Space  Horizontal Space Vertical Space v Newline
  11. 11. C Tokens <ul><li>The smallest element in the C language is the token. </li></ul><ul><li>It may be a single character or a sequence of characters. </li></ul>
  12. 12. C Tokens (Cont) C Tokens Identifiers Eg:main, avg Keywords Eg: int, for operators Eg: + - Strings Eg: “ab” spI symbol Eg: # $ % Constants Eg:17, 15.5
  13. 13. Executing a C Program Creating the Program Compilation Linking Execution
  14. 14. Executing a C Program (Cont) <ul><li>Enter the program in a C editor. </li></ul><ul><li>Save the program (File  Save) or F2. Use the extension .c for saving the file. </li></ul><ul><li>Eg: sample .c </li></ul><ul><li>Compile the program(Compile  Compile) or Alt+F9. </li></ul><ul><li>Run the program(Run  Run) or Ctrl+F9. </li></ul>
  15. 15. Executing C program using UNIX <ul><li>Enter the program in vi editor. </li></ul><ul><li>Save the file using :wq </li></ul><ul><li>Use the extension .c for saving the file. </li></ul><ul><li>Eg: sample .c </li></ul><ul><li>Compile the program. </li></ul><ul><li>Eg: cc sample.c (or) gcc sample.c </li></ul><ul><li>Run the program using a.out . </li></ul>
  16. 16. Structure of C program DOCUMENTATION SECTION PREPROCESSOR SECTION DEFINITION SECTION GLOBAL DECLARATION SECTION main() { Declaration part; Executable Part; } sub program section { Body of the subprogram; }
  17. 17. <ul><li>Documentation Section </li></ul><ul><ul><li>It contains the comment lines. </li></ul></ul><ul><li>Preprocessor Section </li></ul><ul><ul><li>It is used to link library files. </li></ul></ul><ul><li>Global Declaration Section </li></ul><ul><ul><li>The Global declaration section comes at the beginning of the program and they are visible to all parts of the program. </li></ul></ul><ul><li>Declaration Section </li></ul><ul><ul><li>It describes the data to be used within the function. </li></ul></ul><ul><li>Executable Part </li></ul><ul><ul><li>It contains the valid statements. </li></ul></ul>
  18. 18. C Programs <ul><li>C program may have many functions. </li></ul><ul><li>One and only one of the functions MUST BE named main . </li></ul><ul><li>main is the starting point for the program. </li></ul><ul><li>main and other functions in a program are divided into two sections, declaration section and statement section. </li></ul>
  19. 19. Preprocessor Directives <ul><li>Special instructions to the preprocessor that tells how to prepare the program for compilation </li></ul><ul><li>E.g: include : tells the processor to include information from selected libraries known as header files e.g. <stdio.h> </li></ul>
  20. 20. Comments (Program documentation) <ul><li>The compiler simply ignores comments when it translates the program into executable code. </li></ul><ul><li>To identify a comments, C uses opening /* and closing */ comment tokens. </li></ul>
  21. 21. Comments (Cont) <ul><li>Comments can appear anywhere in a program. </li></ul><ul><li>Comments are also found wherever it is necessary to explain a point about a code. </li></ul><ul><li>Comments cannot be nested in C i.e. you cannot have comments inside comments. </li></ul>
  22. 22. C program <ul><li>/* Example program in C*/ Comments </li></ul><ul><li># include <stdio.h> P reprocessor Section </li></ul><ul><li>Global Declaration </li></ul><ul><li>void main () </li></ul><ul><li>{ Local declaration </li></ul><ul><li>printf ( “ Hello World! ” ); Statements </li></ul><ul><li>} </li></ul><ul><li>Output : </li></ul><ul><li>Hello World </li></ul>
  23. 23. C Tokens <ul><li>Identifiers </li></ul><ul><li>Keywords </li></ul><ul><li>Constants </li></ul><ul><li>Operators </li></ul><ul><li>Special symbols </li></ul>
  24. 24. Identifiers <ul><li>Identifiers are names given to various program elements such as variables, functions and arrays etc,. </li></ul><ul><li>Eg: #define N 10 </li></ul><ul><ul><li>#define a 15 </li></ul></ul><ul><ul><li>Here N and a are user defined identifiers. </li></ul></ul>
  25. 25. Rules for naming identifier <ul><li>First character must be alphabetic or underscore. </li></ul><ul><li>Must consist only of alphabetic characters, digits, or underscores. </li></ul><ul><li>Only the first 31 characters of an identifier are significant and are recognized by the compiler. </li></ul><ul><li>Cannot use a keywords or reserved word (e.g. main, include, printf & scanf etc.). </li></ul><ul><li>No space are allowed between the identifiers etc,. </li></ul><ul><li>C is case sensitive, e.g. My_name  my_name. </li></ul>
  26. 26. Examples of Valid and Invalid Names
  27. 27. Variables <ul><li>Variable is an identifier that is used to represent some specified type of information. </li></ul><ul><li>Eg: x=3 </li></ul><ul><li>Here x is variable. </li></ul>
  28. 28. Keywords <ul><li>It is a reserved words. </li></ul><ul><li>Cannot be used for anything else. </li></ul><ul><li>Examples: </li></ul><ul><ul><li>int </li></ul></ul><ul><ul><li>while </li></ul></ul><ul><ul><li>for etc,. </li></ul></ul>
  29. 29. Keywords <ul><li>Auto register Continue </li></ul><ul><li>Double typedef For </li></ul><ul><li>Int Char signed </li></ul><ul><li>Struct extern void </li></ul><ul><li>Break return Default </li></ul><ul><li>Else union Goto </li></ul><ul><li>Long Const sizeof </li></ul><ul><li>Switch Float do </li></ul><ul><li>Case short If </li></ul><ul><li>Enum unsigned </li></ul><ul><li>Static While </li></ul>
  30. 30. Constants <ul><li>It is an entity whose value does not changes during the execution. </li></ul><ul><li>Eg: x=3 </li></ul><ul><li>Here 3 is a constant. </li></ul>
  31. 31. Types <ul><li>Numeric constants </li></ul><ul><li>Character constant </li></ul>
  32. 32. Constants Constants Character Constants Numeric Constants Real Constant Integer Constant String Constant Single Character Constant
  33. 33. Numeric constants <ul><li>Integer constants </li></ul><ul><li>It is formed using a sequence of digits. </li></ul><ul><ul><li>Decimal - 0 to 9 . </li></ul></ul><ul><ul><li>Octal - 0 to 7. </li></ul></ul><ul><ul><li>Hexa - 0 to 9 ,A to F </li></ul></ul><ul><li>Eg: 10,75 etc. </li></ul>
  34. 34. Rules for defining Integer Constant <ul><li>It must have atleast one digit. </li></ul><ul><li>Decimal point are not allowed. </li></ul><ul><li>No blank space or commas are allowed. </li></ul><ul><li>It can be either positive or negative. Etc,. </li></ul>
  35. 35. Numeric constants <ul><li>Real constants </li></ul><ul><li>It is formed using a sequence of digits but it contain decimal point. </li></ul><ul><li>length, height, price distance measured in real number </li></ul><ul><li>Eg: 2.5, 5.11, etc. </li></ul>
  36. 36. Character constants <ul><li>Single character constant </li></ul><ul><ul><li>A character constant is a single character they also represented with single digit or a single special symbol which is enclosed in single quotes. </li></ul></ul><ul><ul><li>Eg: ‘a’, ‘8’,’_’etc. </li></ul></ul>
  37. 37. Character constants <ul><li>String constants </li></ul><ul><li>String constant are sequence of characters enclosed with in double quote. </li></ul><ul><li>Eg: “Hello” ,”444”,”a” etc,. </li></ul>
  38. 38. Operators <ul><li>An operator is a symbol that specifies an operation to be performed on the operands. </li></ul><ul><li>Eg: a + b </li></ul><ul><li>+ is an operator. </li></ul><ul><li>a,b are operands. </li></ul>
  39. 39. Data Types <ul><li>A Data type is the type of data that are going to access within the program. </li></ul>
  40. 40. Standard Data Types These Standard type can be used to build more complex data types called Derived Types (e.g. pointers, array, union etc.).
  41. 41. Data types Data type Size(bytes) Range Format string Char 1 -128 to 127 %c int 2 -32,768 to 32,767 %d Float 4 3.4 e-38 to 3.4 e+38 %f Double 8 1.7 e-308 to 1.7 e+308 %lf
  42. 42. <ul><li>integer </li></ul><ul><ul><li>A number without a fraction part : integral number. </li></ul></ul><ul><ul><li>C supports three different sizes of the integer data type : </li></ul></ul><ul><ul><ul><ul><ul><li>short int </li></ul></ul></ul></ul></ul><ul><ul><ul><ul><ul><li>int </li></ul></ul></ul></ul></ul><ul><ul><ul><ul><ul><li>long int </li></ul></ul></ul></ul></ul>
  43. 43. Floating Point <ul><li>A floating-point type is a number with a fractional part, e.g. 56.78 </li></ul><ul><li>Floating point numbers are stored using </li></ul><ul><li>4 Byte. </li></ul><ul><li>Types </li></ul><ul><ul><li>Float </li></ul></ul><ul><ul><li>Double </li></ul></ul><ul><ul><li>long double </li></ul></ul>
  44. 44. character <ul><li>Character are generally stored using 8 bits(1 Byte) of the internal storage. </li></ul>Character ASCII code value a 97(decimal) or 01100001(binary) x 120(decimal) or 01111000(binary)
  45. 45. void <ul><ul><li>The void type has no values and no operations. </li></ul></ul><ul><ul><li>Both the set of values and the set of operations are empty. </li></ul></ul>
  46. 46. Variable ’ s Declaration <ul><li>To create a variable, you must specify the type and then its identifier : </li></ul><ul><li>float price; </li></ul><ul><li>int a,b; </li></ul><ul><li>char code; </li></ul>
  47. 47. Entire Data types in c: Data type Size(bytes) Range Format string Char 1 128 to 127 %c Unsigned char 1 0 to 255 %c Short or int 2 -32,768 to 32,767 %i or %d Unsigned int 2 0 to 65535 %u Long 4 -2147483648 to 2147483647 %ld Unsigned long 4 0 to 4294967295 %lu Float 4 3.4 e-38 to 3.4 e+38 %f or %g Double 8 1.7 e-308 to 1.7 e+308 %lf Long Double 10 3.4 e-4932 to 1.1 e+4932 %lf
  48. 48. Types of Operator <ul><li>Arithmetic operator </li></ul><ul><li>Relational operator </li></ul><ul><li>Logical operator </li></ul><ul><li>Assignment operator </li></ul><ul><li>Increment or decrement operator(unary) </li></ul><ul><li>Bitwise operator </li></ul><ul><li>Conditional operator </li></ul>
  49. 49. Arithmetic operator <ul><li>It is used to carry out arithmetic operations like addition, subtraction etc, </li></ul><ul><li>Eg: + , - , * , / etc, </li></ul>
  50. 50. Sample program <ul><li>#include<stdio.h> // Header File </li></ul><ul><li>#include <conio.h> </li></ul><ul><li>int b=10; //Global Declaration </li></ul><ul><li>void main ( ) /* main is the starting of every c program */ </li></ul><ul><li>{ </li></ul><ul><li>int a,c; //Local Declaration </li></ul><ul><li>clrscr( ); </li></ul><ul><li>scanf(“%d”,&a); </li></ul><ul><li>printf(“ The sum of the two values:”); </li></ul><ul><li>c = a+b; </li></ul><ul><li>printf(“%d”,c); </li></ul><ul><li>getch( ); </li></ul><ul><li>} </li></ul>
  51. 51. Division operator on Different Data Type Operation Result Example int/int int 5/2 = 2 int/real real 5/2.0 = 2.5 real/int real 5.0/2 = 2.5 real/real real 5.0/2.0 = 2.5
  52. 52. Sample program <ul><li>#include<stdio.h> </li></ul><ul><li>#include <conio.h> </li></ul><ul><li>void main ( ) </li></ul><ul><li>{ </li></ul><ul><li>int a=10,b=4,c; </li></ul><ul><li>float d=3,e; </li></ul><ul><li>clrscr( ); </li></ul><ul><li>c = a/b; </li></ul><ul><li>printf(&quot; value a/b is:%d&quot;,c); </li></ul><ul><li>e = a/d; </li></ul><ul><li>printf(&quot; value a/d is:%f&quot;,e); </li></ul><ul><li>getch( ); </li></ul><ul><li>} </li></ul>
  53. 53. Output <ul><li>value a/b is:2 </li></ul><ul><li>value a/d is:3.333333 </li></ul>
  54. 54. Relational operator <ul><li>It is used to compare two or more operands. </li></ul><ul><li>Eg :< , > , <= , >=, != etc,. </li></ul><ul><li>5 < 9 which will return 1 </li></ul>
  55. 55. Logical operator <ul><li>It is used to combine the result of two or more condition. </li></ul><ul><li>AND(&&) </li></ul><ul><li>OR (||) </li></ul><ul><li>NOT (!) are Logical operators. </li></ul><ul><li>Eg: (i>10)&&(j>5). </li></ul><ul><li> (i>10)||(j>5) etc,. </li></ul>
  56. 56. Sample program <ul><li>#include<stdio.h> </li></ul><ul><li>#include <conio.h> </li></ul><ul><li>void main ( ) </li></ul><ul><li>{ </li></ul><ul><li>int a=10,b=3,c=5,e; </li></ul><ul><li>clrscr( ); </li></ul><ul><li>if(a>b) // relational operator </li></ul><ul><li>{ </li></ul><ul><li>printf(&quot; a is bigger than b&quot;); </li></ul><ul><li>} </li></ul><ul><li>if((a>b)&&(a>c)) //Logical operator </li></ul><ul><li>{ </li></ul><ul><li>printf(&quot; a is biggest&quot;); </li></ul><ul><li>} </li></ul><ul><li>getch( ); </li></ul><ul><li>} </li></ul>
  57. 57. Output <ul><li>a is bigger than b </li></ul><ul><li>a is biggest </li></ul>
  58. 58. Assignment operator <ul><li>It is used to assign a value or expression etc to a variable. </li></ul><ul><li>Eg: a =10. </li></ul><ul><li> a = b </li></ul><ul><li> a = b + c etc,. </li></ul>
  59. 59. Assignment operator(Cont) <ul><li>Compound operator </li></ul><ul><li>It is also used to assign a value to a variable. </li></ul><ul><li>Eg: x + = y means x = x + y </li></ul><ul><li>Nested operator </li></ul><ul><li>It is used for multiple assignment. </li></ul><ul><li>Eg: i = j = k = 0; </li></ul>
  60. 60. Sample program <ul><li>#include<stdio.h> </li></ul><ul><li>#include <conio.h> </li></ul><ul><li>int b=10; </li></ul><ul><li>void main ( ) </li></ul><ul><li>{ </li></ul><ul><li>int a=3,b=5; </li></ul><ul><li>clrscr( ); </li></ul><ul><li>a+=b; // a= a+b </li></ul><ul><li>printf(&quot; The sum of the two values:%d&quot;,a); </li></ul><ul><li>getch( ); </li></ul><ul><li>} </li></ul>
  61. 61. Output <ul><li>The sum of the two values:8 </li></ul>
  62. 62. Increment or decrement operator(Unary) <ul><li>It is used to Increment or decrement an operand. </li></ul><ul><li>Eg: ++x (Pre Increment), </li></ul><ul><li> x++ (Post Increment), </li></ul><ul><li> --x (Pre Decrement), </li></ul><ul><li>x-- (Post Decrement). </li></ul>
  63. 63. Sample Program <ul><li>#include<stdio.h> </li></ul><ul><li>#include <conio.h> </li></ul><ul><li>void main ( ) </li></ul><ul><li>{ </li></ul><ul><li>int a=5; </li></ul><ul><li>clrscr( ); </li></ul><ul><li>printf(&quot; Post increment Value:%d&quot;,a++); </li></ul><ul><li>printf(&quot; Pre increment Value:%d&quot;,++a); </li></ul><ul><li>printf(&quot; Pre decrement Value:%d&quot;,--a); </li></ul><ul><li>printf(&quot; Post decrement Value:%d&quot;,a--); </li></ul><ul><li>getch( ); </li></ul><ul><li>} </li></ul>
  64. 64. Output <ul><li>Post increment Value:5 </li></ul><ul><li>Pre increment Value:7 </li></ul><ul><li>Pre decrement Value:6 </li></ul><ul><li>Post decrement Value:6 </li></ul>
  65. 65. Bitwise operator <ul><li>It is used to manipulate data at bit level. </li></ul><ul><li>Eg: a=5 i.e 0000 0101 </li></ul><ul><ul><li> b=4 i.e 0000 0100 </li></ul></ul><ul><ul><li>Then a & b = 0000 0100 </li></ul></ul><ul><ul><li> a | b = 0000 0101 etc,. </li></ul></ul>
  66. 66. Sample program <ul><li>#include<stdio.h> </li></ul><ul><li>#include <conio.h> </li></ul><ul><li>void main ( ) </li></ul><ul><li>{ </li></ul><ul><li>int a=5,b=4,c; </li></ul><ul><li>//char a=5,b=4,c; </li></ul><ul><li>clrscr( ); </li></ul><ul><li>c = a&b; </li></ul><ul><li>printf(&quot; value a&b is:%d&quot;,c); </li></ul><ul><li>getch( ); </li></ul><ul><li>} </li></ul>
  67. 67. Output <ul><li>value a&b is:4 </li></ul>
  68. 68. Conditional Operator (or) Ternary Operator <ul><li>It is used to checks the condition and execute the statement depending on the condition. </li></ul><ul><li>Eg: C = a > b ? a:b </li></ul>
  69. 69. Sample Program <ul><li>#include<stdio.h> </li></ul><ul><li>#include <conio.h> </li></ul><ul><li>void main ( ) </li></ul><ul><li>{ </li></ul><ul><li>int a=5,b=8,c; </li></ul><ul><li>clrscr( ); </li></ul><ul><li>c = a>b?a:b; //Conditional operator </li></ul><ul><li>printf(&quot; The Larger Value is%d&quot;,c); </li></ul><ul><li>getch( ); </li></ul><ul><li>} </li></ul>
  70. 70. Output <ul><li>The Larger Value is 8 </li></ul>
  71. 71. Special Operator <ul><li>comma operator ( , ) </li></ul><ul><li>sizeof operator </li></ul><ul><li>pointer operator (& , *) etc,. </li></ul>
  72. 72. <ul><li>#include<stdio.h> </li></ul><ul><li>#include <conio.h> </li></ul><ul><li>void main ( ) </li></ul><ul><li>{ </li></ul><ul><li>int c; </li></ul><ul><li>clrscr( ); </li></ul><ul><li>printf(&quot; size of int is:%d&quot;,sizeof c); </li></ul><ul><li>getch( ); </li></ul><ul><li>} </li></ul>
  73. 73. Output <ul><li>size of int is: 2 </li></ul>
  74. 74. Expression <ul><li>An expression represent data item such as variable, constant are interconnected using operators. </li></ul><ul><li>Eg: </li></ul>Expression C Expression a + b + c a + b + c a 2 +b 2 a*a + b*b
  75. 75. Operator Precedence & Associativity <ul><li>The arithmetic expressions evaluation are carried out based on the precedence and associativity. </li></ul><ul><li>The evaluation are carried in two phases. </li></ul><ul><ul><li>First Phase: High Priority operators are evaluated. </li></ul></ul><ul><ul><li>Second Phase: Low Priority operators are evaluated. </li></ul></ul>
  76. 76. Precedence Operator High * , / , % Low + , -
  77. 77. Example <ul><li>5 - 20/4 + 3*3 – 1 </li></ul><ul><li>= 5 - 5 + 9 – 1 </li></ul><ul><li>= 0 + 9 – 1 </li></ul><ul><li>= 9 – 1 </li></ul><ul><li>= 8 </li></ul>
  78. 78. Example <ul><li>5 – (20/4) + 3*(3 – 1) </li></ul><ul><li>= 5 - 5 + 3*2 </li></ul><ul><li>= 5 - 5 + 6 </li></ul><ul><li>= 6 </li></ul>
  79. 79. Type Conversion <ul><li>Converting the type of an expression from one type to another type. </li></ul><ul><li>Eg: x = (int)10.45 </li></ul>
  80. 80. Sample Program <ul><li>#include<stdio.h> </li></ul><ul><li>#include <conio.h> </li></ul><ul><li>void main ( ) </li></ul><ul><li>{ </li></ul><ul><li>int c; </li></ul><ul><li>clrscr( ); </li></ul><ul><li>c=(int)10.45; </li></ul><ul><li>printf(&quot; Output is:%d&quot;,c); </li></ul><ul><li>getch( ); </li></ul><ul><li>} </li></ul><ul><li>OUTPUT </li></ul><ul><li>Output is:10 </li></ul>
  81. 81. Input/Output Function Input/Output Function Unformatted Formatted Output printf() fprintf() Input scanf() fscanf() Input getc() gets() getchar() Output putc() puts() putchar()
  82. 82. Formatted Input/Output <ul><li>C uses two functions for formatted input and output. </li></ul><ul><li>Formatted input : reads formatted data from the keyboard. </li></ul><ul><li>Formatted output : writes formatted data to the monitor. </li></ul>
  83. 83. Formatted Input and Output
  84. 84. Standard Output <ul><li>The standard output file is the monitor. </li></ul><ul><li>Like the keyboard, it is a text file. </li></ul><ul><li>When you need to display data that is not text, it must be converted into to the text before it is written to the screen. </li></ul>
  85. 85. Format of printf Statement
  86. 86. Formatted Input ( scanf ) <ul><li>The standard formatted input function in C is scanf (scan formatted). </li></ul><ul><li>scanf consists of : </li></ul><ul><ul><li>a format string . </li></ul></ul><ul><ul><li>an address list that identifies where data are to be placed in memory. </li></ul></ul><ul><li> scanf ( format string, address list ); </li></ul><ul><li> ( “ %c … .%d … ..%f … .. ” , &a, … .&i, … ..,&x … ..) </li></ul>
  87. 87. Format of scanf Statement
  88. 88. Character Test Function <ul><li>It is used to test the character taken from the input. </li></ul><ul><li>isalpha(ch) </li></ul><ul><li>isdigit(ch) </li></ul><ul><li>islower(ch) </li></ul><ul><li>isupper(ch) </li></ul><ul><li>tolower(ch) </li></ul><ul><li>toupper(ch) etc,. </li></ul>
  89. 90. Decision Making <ul><li>It is used to change the order of the program based on condition. </li></ul><ul><li>Categories: </li></ul><ul><ul><li>Sequential structure </li></ul></ul><ul><ul><li>Selection structure </li></ul></ul><ul><ul><li>Iteration structure </li></ul></ul><ul><ul><li>Encapsulation structure </li></ul></ul>
  90. 91. Decision Making (cont) <ul><li>Sequential structure </li></ul><ul><ul><li>In which instructions are executed in sequence. </li></ul></ul><ul><li>Selection structure </li></ul><ul><ul><li>In which instruction are executed based on the result of some condition. </li></ul></ul><ul><li>Iteration structure </li></ul><ul><ul><li>In which instruction are executed repeatedly. </li></ul></ul><ul><li>Encapsulation structure </li></ul><ul><ul><li>In which some compound structure are used. </li></ul></ul>
  91. 92. SELECTION STRUCTURE <ul><li>It allows the program to make a choice from alternative paths. </li></ul><ul><li>C provide the following selection structures </li></ul><ul><ul><li>IF statement </li></ul></ul><ul><ul><li>IF … ELSE statement </li></ul></ul><ul><ul><li>Nested IF … ELSE statement </li></ul></ul><ul><ul><li>IF … ELSE ladder </li></ul></ul>
  92. 93. IF Statement <ul><li>Syntax </li></ul><ul><li>IF (condition is true) </li></ul><ul><li>{ </li></ul><ul><li>Statements; </li></ul><ul><li>} </li></ul>If condition False True Statements
  93. 94. Example <ul><li>#include<stdio.h> </li></ul><ul><li>#include <conio.h> </li></ul><ul><li>void main ( ) </li></ul><ul><li>{ </li></ul><ul><li>int a; </li></ul><ul><li>clrscr( ); </li></ul><ul><li>printf(&quot; Enter the number:&quot;); </li></ul><ul><li>scanf(&quot;%d&quot;,&a); </li></ul><ul><li>if(a>10) </li></ul><ul><li>{ </li></ul><ul><li>printf(&quot; a is greater than 10&quot;); </li></ul><ul><li>} </li></ul><ul><li>getch( ); </li></ul><ul><li>} </li></ul>
  94. 95. Output <ul><li>Enter the number: 12 </li></ul><ul><li>a is greater than 10 </li></ul>
  95. 96. IF…ELSE Statement <ul><li>Syntax </li></ul><ul><li>IF (condition) </li></ul><ul><li>{ </li></ul><ul><li>True statements; </li></ul><ul><li>} </li></ul><ul><li>ELSE </li></ul><ul><li>{ </li></ul><ul><li>False statements; </li></ul><ul><li>} </li></ul>If Condition True False True statements False statements
  96. 97. <ul><li>#include<stdio.h> </li></ul><ul><li>#include <conio.h> </li></ul><ul><li>void main ( ) </li></ul><ul><li>{ </li></ul><ul><li>int a; </li></ul><ul><li>clrscr( ); </li></ul><ul><li>printf(&quot; Enter the number:&quot;); </li></ul><ul><li>scanf(&quot;%d&quot;,&a); </li></ul><ul><li>if(a>10) </li></ul><ul><li>{ </li></ul><ul><li>printf(&quot; a is greater than 10&quot;); </li></ul><ul><li>} </li></ul><ul><li>else </li></ul><ul><li>{ </li></ul><ul><li>printf(&quot; a is less than 10&quot;); </li></ul><ul><li>} </li></ul><ul><li>getch( ); </li></ul><ul><li>} </li></ul>
  97. 98. NESTED IF… ELSE If Condition 1 False Statements True If Condition 2 True False True statements False statements
  98. 99. NESTED IF… ELSE <ul><li>Syntax </li></ul><ul><li>IF (condition1) </li></ul><ul><li>{ </li></ul><ul><li>IF (condition2) </li></ul><ul><ul><ul><li>{ </li></ul></ul></ul><ul><ul><ul><li>True statements; </li></ul></ul></ul><ul><ul><ul><li>} </li></ul></ul></ul><ul><ul><ul><li>ELSE </li></ul></ul></ul><ul><ul><ul><li>{ </li></ul></ul></ul><ul><ul><ul><li>False statements; </li></ul></ul></ul><ul><ul><ul><li>} </li></ul></ul></ul><ul><li>} </li></ul><ul><li>ELSE </li></ul><ul><li>{ </li></ul><ul><li>False statements; </li></ul><ul><li>} </li></ul>
  99. 100. IF…ELSE LADDER Condition 1 Statements Condition 2 Statements Condition 3 Statements Statements TRUE TRUE TRUE FALSE FALSE FALSE
  100. 101. IF…ELSE LADDER <ul><li>Syntax </li></ul><ul><li>IF (condition1) </li></ul><ul><li>{ </li></ul><ul><li>statements; </li></ul><ul><li>} </li></ul><ul><li>else if (condition2) </li></ul><ul><li>{ </li></ul><ul><li>statements; </li></ul><ul><li>} </li></ul><ul><li>else if (condition3) </li></ul><ul><li>{ </li></ul><ul><li>statements; </li></ul><ul><li>} </li></ul><ul><li>else </li></ul><ul><li>{ </li></ul><ul><li>statements; </li></ul><ul><li>} </li></ul>
  101. 102. Example <ul><li>#include<stdio.h> </li></ul><ul><li>#include<conio.h> </li></ul><ul><li>void main() </li></ul><ul><li>{ </li></ul><ul><li>int m1,m2,m3; </li></ul><ul><li>float avg; </li></ul><ul><li>printf(&quot; Enter the marks:&quot;); </li></ul><ul><li>scanf(&quot;%d%d%d&quot;,&m1,&m2,&m3); </li></ul><ul><li>avg=(m1+m2+m3)/3; </li></ul><ul><li>printf(&quot; The average is:%f&quot;,avg); </li></ul><ul><li>printf(&quot; The Grade is:&quot;); </li></ul><ul><li>if(avg>=60) </li></ul><ul><li>{ </li></ul><ul><li>printf(&quot;First class&quot;); </li></ul><ul><li>} </li></ul>
  102. 103. <ul><li>else if(avg>=50) </li></ul><ul><li>{ </li></ul><ul><li>printf(&quot;Second class&quot;); </li></ul><ul><li>} </li></ul><ul><li>else if(avg>=35) </li></ul><ul><li>{ </li></ul><ul><li>printf(&quot;Thrid class&quot;); </li></ul><ul><li>} </li></ul><ul><li>else </li></ul><ul><li>{ </li></ul><ul><li>printf(&quot;Fail&quot;); </li></ul><ul><li> } </li></ul><ul><li>getch(); </li></ul><ul><li>} </li></ul>
  103. 104. Output <ul><li>Enter the marks:65 </li></ul><ul><li>75 </li></ul><ul><li>70 </li></ul><ul><li>The average is:70.000000 </li></ul><ul><li>The Grade is: First class </li></ul>
  104. 105. Looping structure <ul><li>It is used to execute some instructions several time based on some condition. </li></ul><ul><ul><li>WHILE </li></ul></ul><ul><ul><li>Do…WHILE </li></ul></ul><ul><ul><li>For </li></ul></ul>
  105. 106. WHILE Loop <ul><li>Syntax </li></ul><ul><li>. </li></ul><ul><li>WHILE (condition) </li></ul><ul><li>{ </li></ul><ul><li>. </li></ul><ul><li>Body of the loop; </li></ul><ul><li>. </li></ul><ul><li>} </li></ul>Body of The loop condition False True
  106. 107. Example <ul><li>#include<stdio.h> </li></ul><ul><li>#include<conio.h> </li></ul><ul><li>void main() </li></ul><ul><li>{ </li></ul><ul><li>int i=1,fact=1,n; </li></ul><ul><li>printf(&quot; Enter the Number:&quot;); </li></ul><ul><li>scanf(&quot;%d&quot;,&n); </li></ul><ul><li>while(i<=n) </li></ul><ul><li>{ </li></ul><ul><li> fact =fact *i; </li></ul><ul><li> i++; // i=i+1 </li></ul><ul><li>} </li></ul><ul><li>printf(&quot; The value of %d! is:%d&quot;,n,fact); </li></ul><ul><li>getch(); </li></ul><ul><li>} </li></ul>
  107. 108. Output <ul><li>Enter the Number:3 </li></ul><ul><li>The value of 3! is: 6 </li></ul>
  108. 109. DO…WHILE Loop <ul><li>Syntax </li></ul><ul><li>do </li></ul><ul><li>{ </li></ul><ul><li>Body of the loop </li></ul><ul><li>}while (condition); </li></ul>Body of The loop condition False True
  109. 110. for loop <ul><li>Syntax </li></ul><ul><li>for (initialization; test condition; Increment/Decrement) </li></ul><ul><li>{ </li></ul><ul><li>Body of the loop </li></ul><ul><li>} </li></ul>
  110. 111. for loop Initialization condition False Body of the loop Inc / Decrement
  111. 112. Example <ul><li>#include<stdio.h> </li></ul><ul><li>#include<conio.h> </li></ul><ul><li>void main() </li></ul><ul><li>{ </li></ul><ul><li>int i,fact=1,n; </li></ul><ul><li>printf(&quot; Enter the Number:&quot;); </li></ul><ul><li>scanf(&quot;%d&quot;,&n); </li></ul><ul><li>for(i=1;i<=n;i++) </li></ul><ul><li>{ </li></ul><ul><li> fact =fact *i; </li></ul><ul><li>} </li></ul><ul><li>printf(&quot; The value of %d! is:%d&quot;,n,fact); </li></ul><ul><li>getch(); </li></ul><ul><li>} </li></ul>
  112. 113. Output <ul><li>Enter the Number:3 </li></ul><ul><li>The value of 3! is: 6 </li></ul>
  113. 114. Nested for loop <ul><li>Syntax </li></ul><ul><li>for (initi; cond; Inc/Dec) </li></ul><ul><li>{ </li></ul><ul><li>for (initi; cond; Inc/Dec) </li></ul><ul><li>{ </li></ul><ul><li>Body of the loop </li></ul><ul><li>} </li></ul><ul><li>} </li></ul>
  114. 115. CASE structure Case 1 Case 2 Default case Switch
  115. 116. CASE structure <ul><li>Syntax </li></ul><ul><li>switch (expression) </li></ul><ul><li>{ </li></ul><ul><li>case constant 1: </li></ul><ul><li>block1; </li></ul><ul><li>break; </li></ul><ul><li>case constant 2: </li></ul><ul><li>block2; </li></ul><ul><li>break; </li></ul><ul><li>. </li></ul><ul><li>. </li></ul><ul><li>default : </li></ul><ul><li>default block; </li></ul><ul><li>break; </li></ul><ul><li>} </li></ul>
  116. 117. Example <ul><li>#include<stdio.h> </li></ul><ul><li>#include<conio.h> </li></ul><ul><li>void main() </li></ul><ul><li>{ </li></ul><ul><li>int i,n; </li></ul><ul><li>printf(&quot; Enter the Number:&quot;); </li></ul><ul><li>scanf(&quot;%d&quot;,&n); </li></ul><ul><li>switch(n) </li></ul><ul><li>{ </li></ul><ul><li> case 1: </li></ul><ul><li>{ </li></ul><ul><li>printf(&quot; Its in case 1&quot;); </li></ul><ul><li>break; </li></ul><ul><li>} </li></ul>
  117. 118. <ul><li>case 2: </li></ul><ul><li>{ </li></ul><ul><li>printf(&quot; Its in case 2&quot;); </li></ul><ul><li>break; </li></ul><ul><li>} </li></ul><ul><li> default: </li></ul><ul><li>{ </li></ul><ul><li>printf(&quot; Its in default&quot;); </li></ul><ul><li>break; </li></ul><ul><li>} </li></ul><ul><li>} </li></ul><ul><li>getch(); </li></ul><ul><li>} </li></ul>
  118. 119. Output <ul><li>Enter the Number:2 </li></ul><ul><li>Its in case 2 </li></ul>
  119. 120. break Statement <ul><li>It is used to terminate the loop </li></ul><ul><li>When a break statement is encountered inside a loop, then the loop is terminated. </li></ul>
  120. 121. Loops with break Statement <ul><li>while(cond) </li></ul><ul><li>{ </li></ul><ul><li>………… </li></ul><ul><li>if(cond) </li></ul><ul><li>break; </li></ul><ul><li>………… </li></ul><ul><li>} </li></ul>
  121. 122. <ul><li>do </li></ul><ul><li>{ </li></ul><ul><li>………… </li></ul><ul><li>if(cond) </li></ul><ul><li>break; </li></ul><ul><li>………… </li></ul><ul><li>} while(cond); </li></ul>
  122. 123. <ul><li>for (initi; condt; Inc/Dec) </li></ul><ul><li>{ </li></ul><ul><li>………… </li></ul><ul><li>if(cond) </li></ul><ul><li>break; </li></ul><ul><li>………… </li></ul><ul><li>} </li></ul>
  123. 124. Continue Statement <ul><li>When a continue statement is encountered inside a loop, the control is transferred to the beginning. </li></ul>
  124. 125. Loops with continue Statement <ul><li>while(cond) </li></ul><ul><li>{ </li></ul><ul><li>………… </li></ul><ul><li>if(cond) </li></ul><ul><li>continue; </li></ul><ul><li>………… </li></ul><ul><li>} </li></ul>
  125. 126. <ul><li>do </li></ul><ul><li>{ </li></ul><ul><li>………… </li></ul><ul><li>if(cond) </li></ul><ul><li>continue; </li></ul><ul><li>………… </li></ul><ul><li>} while(cond); </li></ul>
  126. 127. <ul><li>for (initi; condt; Inc/Dec) </li></ul><ul><li>{ </li></ul><ul><li>………… </li></ul><ul><li>if(cond) </li></ul><ul><li>continue; </li></ul><ul><li>………… </li></ul><ul><li>} </li></ul>
  127. 128. goto Statement <ul><li>When a goto statement is encountered inside a loop, the control is transferred to the beginning. </li></ul>
  128. 129. Syntax for goto Statement <ul><li>label: </li></ul><ul><li>………… </li></ul><ul><li>………… </li></ul><ul><li>………… </li></ul><ul><li>goto label; </li></ul><ul><li>………… </li></ul>
  129. 130. <ul><li>goto label; </li></ul><ul><li>………… </li></ul><ul><li>………… </li></ul><ul><li>………… </li></ul><ul><li> label: </li></ul><ul><li>………… </li></ul>
  130. 132. getchar() Example <ul><li>#include<stdio.h> </li></ul><ul><li>#include<conio.h> </li></ul><ul><li>#include<ctype.h> </li></ul><ul><li>void main() </li></ul><ul><li>{ </li></ul><ul><li>char x; </li></ul><ul><li>printf(&quot;enter the character:&quot;); </li></ul><ul><li>x=getchar(); </li></ul>
  131. 133. <ul><li>if(islower(x)) </li></ul><ul><li>putchar(toupper(x)); </li></ul><ul><li>else </li></ul><ul><li>putchar(tolower(x)); </li></ul><ul><li>getch(); </li></ul><ul><li>} </li></ul><ul><li>Output: </li></ul><ul><li>enter the character:ABC </li></ul><ul><li>a </li></ul>
  132. 134. getche() Example <ul><li>#include <stdio.h> </li></ul><ul><li>#include <conio.h> </li></ul><ul><li>void main() </li></ul><ul><li>{ </li></ul><ul><li>char c ; </li></ul><ul><li>clrscr(); </li></ul><ul><li>printf(&quot; Input a string:&quot;); </li></ul><ul><li>c = getche(); </li></ul>
  133. 135. <ul><li>printf(&quot; string is:&quot;); </li></ul><ul><li>putch(c); </li></ul><ul><li>getch(); </li></ul><ul><li>} </li></ul><ul><li>Output: </li></ul><ul><li>Input a string:k </li></ul><ul><li>string is:k </li></ul>
  134. 136. Getch() Example <ul><li>#include <stdio.h> </li></ul><ul><li>#include <conio.h> </li></ul><ul><li>void main() </li></ul><ul><li>{ </li></ul><ul><li>char c; </li></ul><ul><li>clrscr(); </li></ul><ul><li>printf(&quot; Input a string:&quot;); </li></ul><ul><li>c = getch(); </li></ul>
  135. 137. <ul><li>printf(&quot; string is:&quot;); </li></ul><ul><li>putch(c); </li></ul><ul><li>getch(); </li></ul><ul><li>} </li></ul><ul><li>Output: </li></ul><ul><li>Input a string: </li></ul><ul><li>string is:h </li></ul>
  136. 138. getc Example <ul><li>#include<stdio.h> </li></ul><ul><li>#include<conio.h> </li></ul><ul><li>#include<ctype.h> </li></ul><ul><li>void main() </li></ul><ul><li>{ </li></ul><ul><li>char x; </li></ul><ul><li>printf(&quot;enter the character:&quot;); </li></ul><ul><li>x=getc(stdin); </li></ul>
  137. 139. <ul><li>if(islower(x)) </li></ul><ul><li>putc(toupper(x),stdout); </li></ul><ul><li>else </li></ul><ul><li>putc(tolower(x),stdout); </li></ul><ul><li>getch(); </li></ul><ul><li>} </li></ul><ul><li>Output: </li></ul><ul><li>enter the character:abc </li></ul><ul><li>A </li></ul>
  138. 140. gets() Example <ul><li>#include <stdio.h> </li></ul><ul><li>#include<conio.h> </li></ul><ul><li>void main() </li></ul><ul><li>{ </li></ul><ul><li>char c[80]; </li></ul><ul><li>clrscr(); </li></ul><ul><li>printf(&quot;Input a string:&quot;); </li></ul><ul><li>gets(c); </li></ul>
  139. 141. <ul><li>printf(&quot;The string is:&quot;); </li></ul><ul><li>puts(c); </li></ul><ul><li>getch(); </li></ul><ul><li>} </li></ul><ul><li>Output: </li></ul><ul><li>Input a string:qwerty </li></ul><ul><li>The string is:qwerty </li></ul>
  140. 142. Example <ul><li>#include<stdio.h> </li></ul><ul><li>#include<conio.h> </li></ul><ul><li>void main() </li></ul><ul><li>{ </li></ul><ul><li>int a,b,c,n; </li></ul><ul><li>clrscr(); </li></ul><ul><li>printf(&quot; Enter the value of a,b:&quot;); </li></ul><ul><li>scanf(&quot;%d%d&quot;,&a,&b); </li></ul><ul><li>printf(&quot; MENU&quot;); </li></ul><ul><li>printf(&quot; 1.ADD 2.SUB 3.MULTIPLY 0.EXIT&quot;); </li></ul><ul><li>printf(&quot; Enter the choice:&quot;); </li></ul><ul><li>scanf(&quot;%d&quot;,&n); </li></ul>
  141. 143. <ul><li>switch(n) </li></ul><ul><li>{ </li></ul><ul><li> case 1: </li></ul><ul><li>c=a+b; </li></ul><ul><li>printf(&quot; The result of Addition is:%d&quot;,c); </li></ul><ul><li>break; </li></ul><ul><li>case 2: </li></ul><ul><li>c=a-b; </li></ul><ul><li>printf(&quot; The result of Subtraction is:%d&quot;,c); </li></ul><ul><li>break; </li></ul>
  142. 144. <ul><li>case 3: </li></ul><ul><li>c=a*b; </li></ul><ul><li>printf(&quot; The result of Multiplication is:%d&quot;,c); </li></ul><ul><li>break; </li></ul><ul><li> case 0: </li></ul><ul><li>exit(0); </li></ul><ul><li>break; </li></ul><ul><li>} </li></ul><ul><li>getch(); </li></ul><ul><li>} </li></ul>
  143. 145. Output <ul><li>Enter the value of a,b:5 </li></ul><ul><li>6 </li></ul><ul><li>MENU </li></ul><ul><li>1.ADD </li></ul><ul><li>2.SUB </li></ul><ul><li>3.MULTIPLY </li></ul><ul><li>0.EXIT </li></ul><ul><li>Enter the choice:1 </li></ul><ul><li>The result of Addition is:11 </li></ul>
  144. 146. Finding Armstrong No <ul><li>#include<stdio.h> </li></ul><ul><li>#include<conio.h> </li></ul><ul><li>void main() </li></ul><ul><li>{ </li></ul><ul><li>int r=0,sum=0,n,a; </li></ul><ul><li>printf(&quot; Enter the number:&quot;); </li></ul><ul><li>scanf(&quot;%d&quot;,&n); </li></ul><ul><li>a=n; </li></ul><ul><li>while(n>0) </li></ul><ul><li>{ </li></ul><ul><li>r=n%10; </li></ul><ul><li>sum=sum+r*r*r; </li></ul><ul><li>n=n/10; </li></ul><ul><li>} </li></ul>
  145. 147. <ul><li>if(a==sum) </li></ul><ul><li>{ </li></ul><ul><li> printf(&quot; It is an armstrong number&quot;); </li></ul><ul><li>} </li></ul><ul><li>else </li></ul><ul><li>{ </li></ul><ul><li> printf(&quot; It is not an armstrong number&quot;); </li></ul><ul><li>} </li></ul><ul><li>getch(); </li></ul><ul><li>} </li></ul>
  146. 148. Output <ul><li>Enter the number:153 </li></ul><ul><li>It is an armstrong number </li></ul>
  147. 149. Sum of the Digits <ul><li>#include<stdio.h> </li></ul><ul><li>#include<conio.h> </li></ul><ul><li>void main() </li></ul><ul><li>{ </li></ul><ul><li>int r=0,sum=0,n; </li></ul><ul><li>printf(&quot; Enter the no:&quot;); </li></ul><ul><li>scanf(&quot;%d&quot;,&n); </li></ul><ul><li>while(n>0) </li></ul><ul><li>{ </li></ul><ul><li>r=n%10; </li></ul>
  148. 150. <ul><li>sum=sum+r; </li></ul><ul><li>n=n/10; </li></ul><ul><li>} </li></ul><ul><li>printf(&quot;sum of the digits is:%d&quot;,sum); </li></ul><ul><li>} </li></ul>
  149. 151. Output <ul><li>Enter the no:156 </li></ul><ul><li>sum of the digits is:12 </li></ul>
  150. 152. Reverse of a number <ul><li>#include<stdio.h> </li></ul><ul><li>#include<conio.h> </li></ul><ul><li>void main() </li></ul><ul><li>{ </li></ul><ul><li>int r=0,sum=0,n; </li></ul><ul><li>printf(&quot; Enter the no:&quot;); </li></ul><ul><li>scanf(&quot;%d&quot;,&n); </li></ul><ul><li>while(n>0) </li></ul>
  151. 153. <ul><li>{ </li></ul><ul><li>r=n%10; </li></ul><ul><li>sum=sum*10+r; </li></ul><ul><li>n=n/10; </li></ul><ul><li> } </li></ul><ul><li>printf(&quot;Reverse of the number is:%d&quot;,sum); </li></ul><ul><li>getch(); </li></ul><ul><li>} </li></ul>
  152. 154. Output <ul><li>Enter the no:567 </li></ul><ul><li>Reverse of the number is:765 </li></ul>
  153. 155. Fibonacci Series <ul><li>#include<stdio.h> </li></ul><ul><li>#include<conio.h> </li></ul><ul><li>void main() </li></ul><ul><li>{ </li></ul><ul><li>int f=0,f1=-1,f2=1,n,i; </li></ul><ul><li>printf(&quot; Enter the number:&quot;); </li></ul><ul><li>scanf(&quot;%d&quot;,&n); </li></ul>
  154. 156. <ul><li>while(f<n) </li></ul><ul><li>{ </li></ul><ul><li> f=f1+f2; </li></ul><ul><li>f1=f2; </li></ul><ul><li> f2=f; </li></ul><ul><li>printf(&quot; %d&quot;,f); </li></ul><ul><li>} </li></ul><ul><li>getch(); </li></ul><ul><li>} </li></ul>
  155. 157. Output <ul><li>Enter the number:5 </li></ul><ul><li> 0 1 1 2 3 5 </li></ul>
  156. 158. Swapping <ul><li>#include<stdio.h> </li></ul><ul><li>#include <conio.h> </li></ul><ul><li>void main ( ) </li></ul><ul><li>{ </li></ul><ul><li>int a,b,c; </li></ul><ul><li>clrscr( ); </li></ul><ul><li>printf(&quot; Enter the value of a:&quot;); </li></ul><ul><li>scanf(&quot;%d&quot;,&a); </li></ul><ul><li>printf(&quot; Enter the value of b:&quot;); </li></ul><ul><li>scanf(&quot;%d&quot;,&b); </li></ul><ul><li>c=a; </li></ul><ul><li>a=b; </li></ul><ul><li>b=c; </li></ul>
  157. 159. <ul><li>printf(&quot; The value of a is:%d&quot;,a); </li></ul><ul><li>printf(&quot; The value of b is:%d&quot;,b); </li></ul><ul><li>getch( ); </li></ul><ul><li>} </li></ul><ul><li>Output: </li></ul><ul><li>Enter the value of a:5 </li></ul><ul><li>Enter the value of b:4 </li></ul><ul><li>The value of a is:4 </li></ul><ul><li>The value of b is:5 </li></ul>
  158. 160. Swapping without using third variable <ul><li>#include<stdio.h> </li></ul><ul><li>#include <conio.h> </li></ul><ul><li>void main ( ) </li></ul><ul><li>{ </li></ul><ul><li>int a,b; </li></ul><ul><li>clrscr( ); </li></ul><ul><li>printf(&quot; Enter the value of a:&quot;); </li></ul><ul><li>scanf(&quot;%d&quot;,&a); </li></ul><ul><li>printf(&quot; Enter the value of b:&quot;); </li></ul><ul><li>scanf(&quot;%d&quot;,&b); </li></ul>
  159. 161. <ul><li>a=a+b; </li></ul><ul><li>b=a-b; </li></ul><ul><li>a=a-b; </li></ul><ul><li>printf(&quot; The value of a is:%d&quot;,a); </li></ul><ul><li>printf(&quot; The value of b is:%d&quot;,b); </li></ul><ul><li>getch( ); </li></ul><ul><li>} </li></ul><ul><li>Output: </li></ul><ul><li>Enter the value of a:5 </li></ul><ul><li>Enter the value of b:6 </li></ul><ul><li>The value of a is:6 </li></ul><ul><li>The value of b is:5 </li></ul>
  160. 162. Quadratic Equation <ul><li>#include<stdio.h> </li></ul><ul><li>#include <conio.h> </li></ul><ul><li>#include<math.h> </li></ul><ul><li>void main ( ) </li></ul><ul><li>{ </li></ul><ul><li>int a,b,c,d,r1,r2; </li></ul><ul><li>clrscr( ); </li></ul><ul><li>printf(&quot; Enter the value of a:&quot;); </li></ul><ul><li>scanf(&quot;%d&quot;,&a); </li></ul><ul><li>printf(&quot; Enter the value of b:&quot;); </li></ul><ul><li>scanf(&quot;%d&quot;,&b); </li></ul><ul><li>printf(&quot; Enter the value of c:&quot;); </li></ul><ul><li>scanf(&quot;%d&quot;,&c); </li></ul><ul><li>d=b*b-4*a*c; </li></ul>
  161. 163. <ul><li>if(d>=0) </li></ul><ul><li>{ </li></ul><ul><li>r1=(-b+sqrt(d))/(2*a); </li></ul><ul><li>r2=(-b-sqrt(d))/(2*a); </li></ul><ul><li>printf(&quot; The roots are %d,%d&quot;,r1,r2); </li></ul><ul><li>} </li></ul><ul><li>else </li></ul><ul><li>{ </li></ul><ul><li>printf(&quot; The roots are imaginary&quot;); </li></ul><ul><li>} </li></ul><ul><li>getch( ); </li></ul><ul><li>} </li></ul>
  162. 164. Output <ul><li>Enter the value of a:4 </li></ul><ul><li>Enter the value of b:5 </li></ul><ul><li>Enter the value of c:6 </li></ul><ul><li>The roots are imaginary </li></ul>

×