C Language ppt create by Anand & Sager.pptx

kumaranand07297 49 views 30 slides Sep 09, 2024
Slide 1
Slide 1 of 30
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30

About This Presentation

c language ppt


Slide Content

Respected Principal sir, HOD sir and our all teachers from our Branch, we Heartily welcome to watch our presentation on “Summer internship training”. welcome

CANDIDATE DECLARATION We are the student of 2nd year (CSE) declare that we own full responsible for the information result etc. provided in project title “C-Programming”, Submitted to DEPARTMENT OF COMPUTER SCIENCE GOVT. POLYTECNIC COLLEGE (KOTA) RAJASTHAN for THE DIPLOMA IN COMPUTER SCIENCE. In all respect we have taken care of the intellectual Proprietary right & copyright. Our project in-charge and institute should not Be held responsible for full or partial violation of copyright if found any stage of my diploma. DATE: 23/09/2023 Place-KOTA

Submitted by : PRACTICAL TRAINING REPORT PPT MCM COMPUTER EDUCATION INSTITUTE ON ( C- language ) Taken On SUBMITTED IN PARTIAL FULFILLMENTN OF THE REQUIREMENT FOR THE AWARD OF THE DIPLOMA OF ENGINEERING ANAND KUAMR VERMA & SAGAR KUMAR DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING Session : 2023 - 2024 GOVERNMENT POLYTECHNIC COLLEGE, D.C.M. ROAD, KOTA-324007

Topic Name Slide number Introduction of C : 5 to 6 Basic structure of c-language : 7 Role of main() function : 8 to 9 C-Tokens & variables : 10 Constant & keyword : 11 Types of keyword in “c”- language : 12 Data types in “c”-language : 13 Types of operators in “c”-language : 14 Branching in “c”-language : 15 to 20 Decision making and looping : 21 to 23 Array : 24 to 25 String : 26 to 27 Function : 28 Recursion : 29 Table of Contents

Introduction:- ‘C’ is a Structure Programming Language and mostly used for software developing purpose. It was an offspring of the BCPL ‘Basic Combined Programming Language’, called B, developed in 1970’s. ‘B’ Language was modified by Dennis Ritchie and was implemented at Bell Laboratories in 1972. the new language was named ‘C’. It was developed along with the UNIX operating system, but it is running under a number of Operating Systems including MS-DOS. Introduction of The “C’ Language

Importance of ‘C’:- It is robust language whose rich set of built-in functions and operators can be used to write any complex program. The ‘C’ compiler combines the capabilities of an assembly language with the features of a high-level language. It is well suited for writing both system software and business packages. Programs written in ‘C’ are efficient an fast. This is due to its variety of data types and powerful operators. It is many times faster than BASIC. There are 32 types o f Keywords and its strength lines in its built-in functions. ‘C’ is highly portable. This means that ‘C’ programs written for one computer can be run on another with little or no modifications.

Documentation Section Link Section Definition Section Global Declaration Section Main() function section { Declaration part Executable part } Subprograme Section Function-1 Function-2 {used defined function} Function-n {An over of drive a “C” Language} Basic Structure of “C” Language ‘ C’ language is well suited for structured programming language, thus requiring the user to think of a problem in terms of function modules or blocks. A proper collection of these modules would make a complete program. This modular structure makes program debugging, testing and maintenance easier. Another important feature of ‘C’ is its ability to extend itself. A ‘C’ program is basically a collection of functions that are supported by the ‘C’ library. Example of B.S // sexplain the simple program// #include< stdio.h > #include< conio.h > void main() { int a; printf (“enter the a value:”); scanf (“% d”,&a ); printf (“\n value of a=% d”,a ); }

Main():- The Main() is a special function, used by the ‘C’ system to tell the computer where the program starts. Every program must have exactly one main function. If we use more than one main function, the compiler cannot tell which one marks the beginning of the program. The empty pair of parentheses immediately following main indicates that the function main has no arguments (or parameters). The opening brace ‘{‘ in the second line marks the beginning of the function main and the closing brace ‘}’ in the last line indicates the end of the function. The closing brace also marks the end of the program. All the statements between these two braces form the function body . It contains a set of instructions to perform the given task. Role of Main() Function

Every ‘C’ program must have one main() section. This section contains two parts, declaration part and executable part. The declaration part declares all the variables used in the executable part. There is at least one statement in the executable part. These two parts must appear between the opening and the closing braces. The program execution begins at the opening brace and ends at the closing brace. The closing brace of the main function section is the logical end of the program. All statements in the declaration and executable parts end with a semicolon. main() function name { start of program -------- program statements -------- } end of program

C-TOKENS Keywords : int , float, while Identifiers : value, amount Constant : -15.5 , 100 Strings : “ abc ”, “ABC”, “ x+y ”, ”5”, “d” Special Symbols : [ ] , { } Operators : + , - , * , / , % Variable “Variables are data name, which is used to store any kind of value, constant or expression. Or Variables are data names, which value change during the execution of ‘C’ program” Type of Variable :- Integer Variable : x=169 Float Variable : x=169.79 Character Variable : x=‘k’/”ram” Long integer Variable : {-32768 to 32767}

CONSTANT “Constants are fixed values, which does not change during the execution of ‘C’ program” Type of Constant :- Integer Constant : x=169 Float/ Real Constant : x=169.79 Character Constant : x=‘k’ String Constant : x=“ram” Back Slash Character Constant: : ‘\n’, ‘\t’, ‘\v’ etc. KEYWORD Keywords are those words whose meaning is already defined know to the compiler. It is also know as Reserved words. Keywords are not used as variable name. Keywords are not used as constant name. There are 32 Key-words in “C” Language

Types of Keywords In “C” Language 1.auto 2.break 3.case 4.char 5.const 6.continue 7.default 8.do 9.double 10.else 11.enum 12.extern 13.float 14.for 15.goto 16.if 17. int 18.long 19.register 20.return 21.short 22.signed 23.sizeof 24.static 25.struct 26.switch 27.typedof 28.union 29.unsigned 30.void 31.volatile 32.while

Data Types in “C” Language “C language is rich in its data types. There are four classes of data types:” 1. Primary or Fundamental data types:- All C compilers support four fundamental data types, namely integer ( int ), character (char), floating point (float), and double-precision floating point (double). 2. User-defined data types:- typedef , enum are the user-defined data type. 3. Derived data types:- Arrays, functions, structures and pointers are derived data types. 4. Empty data set:- void main()

Types of Operators In “C” Language “Operators are used in programs to manipulate data and Variables” There are 8 types of operators in ‘C’ Language- Arithmetic Operators Relational Operators Logical Operators Assignment Operators Increment and decrement Operators Bitwise Operators Conditional Operators Special Operators

Branching in “C” Language “C language possesses such decision making capabilities and supports for the following statements known as Control or Decision Making Statements.” If statement Switch Statement Conditional Operator Statement GOTO Statement A. If Statement:- Simple If statement If ….. Else Statement Nested If … else Statement Else If Ladder Statement

A-1. Simple If A-2. If….else Syntax: If (Test Condition) { Statement Block; } Statement-x; Next Statement; Example: #include< s tdio.h > # include< c onio.h > v oid main() { i nt a,b ; p rintf (“\n Enter A and B Value:”); s canf (“% d,%d ”, &a, &b); i f (a>b) { printf (“\n A is Greater=% d”,a ); } } Syntax : If (Test Condition) { True Block Statement; } Else { False Block Statement; } Statement-x ; Next Statement; Example: #include< stdio.h > #include< conio.h > void main() { int a,b ; printf (“\n Enter A and B Value:”); scanf (“% d,%d ”, &a, &b); If (a>b) { printf (“\n A is Greater=% d”,a ); } else { printf (“\n B is Greater=% d”,b ); }}

A-3. Nested If …. Else Syntax: If (Test Condition-1) { If (Test Condition-2) { Statement Block-1; } Else { Statement Block-2; }} Else { Statement Block-3; } Statement-x; Next Statement; Example : #include< s tdio.h > # include< c onio.h > v oid main() { i nt a,b,c ; p rintf (“\n Enter A, B and C Value:”); s canf (“% d,%d,%d ”, &a, &b, &c); i f ((a>b)&& (a>c)) { i f (b>c) { printf (“\n A is Greater=% d”,a ); } e lse { printf (“\n B is Greater=% d ”,b ); }} e lse { printf (“\n C is Greater=% d ”,c ); }} A-4 . Else if Ladder Syntax : If (Test Condition-1) Statemetn-1; Else If (Test Condition-2) Statement-2; Else If (Test Condition-3) Statement-3; …………………… Else if (Test Condition-n) Statement-n; Else Default Statement; Statement-x; Next Statement; Example: #include< stdio.h > #include< conio.h > void main() { int code; printf (“\n 1. Hi \n 2. Hello \n 3. How are you?”); printf (“\n Enter your Choice :”); scanf (“%d”, &code); if (code==1) printf (“\n Hi”); else if (code==2) printf (“\n Hello”); else if (code==3) printf (“\n How are you?”); else printf (“\n All the Best”); }

B. Switch Statement Syntax: Switch (Test expression) { Case value-1: Block-1; Break; Case value-2: Block-2; Break; ………………… Default: Default block; Break; } Statement-x; Next Statement; Example: #include< s tdio.h > # include< c onio.h > v oid main() { i nt code; p rintf (“\n 1. Hi \n 2. Hello \n 3. How are you?”); p rintf (“\n Enter your Choice :”); s canf (“%d”, &code); s witch(code) { c ase 1: p rintf (“\n Hi”); b reak; c ase 2: p rintf (“\n Hello”); b reak ; c ase 3: p rintf (“\n How are you?”); b reak ; d efault: p rintf (“\n All the Best”); b reak; }}

C. Conditional Operator Statement Syntax: Exp1 ? Exp-2 : Exp-3 ; Example: #include< s tdio.h > # include< conio.h > v oid main() { int a,b ; p rintf (“\n Enter A and B Value:”); s canf (“% d,%d ”, &a, &b); (a>b) ? printf (“\n A is Greater”) : printf (“\n B is Greater”); } “It is also known as Ternary Operator. It has three operands”

D. GOTO Statement Syntax-1: Forward Jump Goto Label; ………….. ………….. ………….. Label: Statement; Example : #include< s tdio.h > # include< c onio.h > v oid main() { int a,x ; b: p rintf (“\n Enter A Value :”); s canf (“% d”, & a); if(a<0) { printf (“\n Entire value id either Zero or Negative !! Please try again…”); goto b; } e lse { p rintf (“\n Good Input:”); x =a*a; p rintf (“\n Result is =% d”,x ); }} Syntax-2: Backward Jump Label: Statement; ………….. ………….. ………….. Goto Label;

DECISION MAKING AND LOOPING

Types of loop in “C” Language Three types of loop in “C” Language. “A sequence of Statements are executed until some conditions for termination of the loop are satisfied” 1. While Loop – Entry Controlled Loop . 2. Do Loop - Exit Controlled Loop . 3. For Loop - Entry Controlled Loop .

While loop:- Syntax:- While (Test Condition) { Body of the Loop; } Example :- #include< stdio.h > # include< c onio.h > v oid main() { i nt i=0; while(i<=10) { i=i+1; printf (“\n Result is=% d”,i ); }} Do loop:- syntax:- Do { Body of the Loop; } while (Test Condition); } Example: #include< stdio.h > #include< conio.h > void main() { int i=0; do { i=i+1; printf (“\n Result is=% d”,i ); } while(i<=10); } For loop:- Syntax:- For (Initialization; Test Condition; Increment/Decrement) { Body of the Loop; } Example:- #include< stdio.h > #include< conio.h > void main() { int i; for (i=1; i<=10; i++) { printf (“\n Result is=% d”,i ); } }

An Array is defined as collection of related items and all the items are as similar data types. Array are the collection of finite number of similar type data element. Array handle a large amount of data in terms of reading, processing and printing. Array Types of array in “C” Language One Dimensional Array. Two Dimensional Array. Multi Dimensional Array . Three types of array in “C” Language.

Array examples:- 1. One Dimensional Array Example: #include< stdio.h > void main() { int i , a[5]; p rintf (“\n Enter 5 elements :”); f or ( i =0; i <5; i ++) { s canf (“% d”,&a [ i ]); } p rintf (“\n Output of array elements :”); f or ( i =0; i <5; i ++) { printf (“\n % d ”,a [ i ]); }} 2. Two Dimensional Array Example: #include< stdio.h > void main() { int i,j , a[3][3]; p rintf (“\n Enter 3 x 3 elements :”); f or ( i =0; i <3; i ++) { f or (j=0 ; j<3 ; j++) { s canf (“% d”,&a [ i ][j]); }} p rintf (“\n Output of array elements :”); f or ( i =0; i <3; i ++) { p rintf (“\n”); f or(j=0;j<3;j++) { printf (“\t % d ”,a [ i ][j]); }}} 3. Multi Dimensional Array Example : #include< stdio.h > void main() { int i,j,k a[2][3][2]; p rintf (“\n Enter 2 x 3 x 2 elements :”); f or ( i =0; i <2; i ++) { f or (j=0 ; j<3 ; j++) { f or (k=0 ; k<2 ; k++) { scanf (“% d”,&a [ i ][j][k]); }} p rintf (“\n Output of array elements :”); f or ( i =0; i <2; i ++) { f or(j=0;j<3;j++) { f or (k=0 ; k<2 ; k++) { printf (“\ n % d”,a [ i ][j][k]); }}}

STRING “ In C language, Array of Characters are called “String”. Any string is the sequential collection of Characters, which used any single data item. String size denotes the maximum number of characters can hold. String value will terminate with an additional null ‘\0’ terminator. Hence, at the time of string declaration, one extra element space will define for the null character. Syntax : <data type> <Array Name> [size]; Example Char n[10]; Character string :- ‘w’ ‘e’ ‘l’ ‘l’ ‘ ‘ ‘d’ ‘o’ ‘n’ ‘e’ ‘\0’ N[0] N[1] N[2] N[3] N[4] N[5] N[6] N[7] N[8] N[9]

Example of string : #include< stdio.h > void main() { char x[50]; printf (“\n enter any string”); gets(x); puts(x); }

Category of Functions:- Function with No Argument and No Return Value Function with No Argument and Return Value Function with Argument and No Return Value Function with Argument and Return Value Function Function Parameter Passing:- Syntax : Function(a1,a2, a3 .... an) { ---------- ---------- } Function(f,f2,f3, …. Fn ) { ---------- ---------- } Example : #include< stdio.h > void main() { int ram( int,int ), a,b ; printf (“\n Enter A and B value :”); scanf (“% d,%d”,&a,&b ); printf (“\n Result is=% d”,ram ( a,b ); } int ram( int x, int y) { int z; z= x+y ; return (z); }

RECURSION Definition: When a function calls a copy of itself then the process is known as Recursion . Or When a function calls itself then this technique is known as Recursion Example : #include< s tdio.h > void main() { i nt n, fact( int ); p rintf (“\n Enter any Number :”); s canf (“% d”,& n ); printf (“\n Factorial value is=% d”,fact (n)); } i nt fact( int n) { i f(n==0) r eturn(1); e lse r eturn (n*fact(n-1)); }

Thank you…
Tags