Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
26 views
23 pages
LLL
Uploaded by
sasikiranworks
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save lll For Later
Download
Save
Save lll For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
26 views
23 pages
LLL
Uploaded by
sasikiranworks
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save lll For Later
Carousel Previous
Carousel Next
Download
Save
Save lll For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 23
Search
Fullscreen
Algorithm is a finite set of instructions in seq Qualities of a good algorithm 1. Input and output should be defined precisely. Fach steps in algorithm should be clear and unambiguous. jorithm should be most effective among many different ways to solve a problem. 4. Analgorithm shouldn't have computer code, FlowChart Flowchart is a diagrammatical or pictorial represe writing program and explaining program to others. Syimbols Used In Flowehart to solve the problem or program, ion of an algorithm. Flowcharts are very helpful in Symbol Purpose Description Flow line Used to indicate the flow of logic by connecting symbols. Terminal(Stop/Start) Used to represent start and end of flowchart. [] InpuvOutput Used for input and output operation. Processing Used for airthmetic operations and data-manipulations. Used to represent the operation in which there are two alternatives, true and false. DesicionStructure of C Program : The sections of a C program are listed below: 1. Documentation section 7 Program Title *7 Preprocessor section Link Section Finchude
3._ Definition section Waetine pi 3.14 4. Global declaration int max=30; 5. Main function main) 6, Local Delearation int a=90 7, Executable satements printf” a= %d , max= %d",amax); } User defined functions void fan Documentation section It includes the statement specified at the b inning of a program, such as a Preprocessor section The preprocessor section contains all the header files used in a program. It informs the system to link the header files to the system libraries. Program's name, date, description, and title. Define section ‘The define section comprises of different constants declared using the define keyword Global declaration ‘The global section comprises of all the global declarations in the program, Main function ‘maip( is the first function to be executed by the It is like any other function availabl any) to a function. ‘computer. It is necessary for a code to include the main(). in the C library. Parenthesis () are used far passing parameters.(if Local declarations ‘The variable that is declared inside a given function or block refers to as local declarations. User defined functions The user defined functions specified the functions specified as per the requirements of the user. Fo example, color(), sum(), division(), ete,Data Types Data Types LZ Empty sets Primary Derived Data User Defined Data Types Types data types 1 | char | _| int Arrays Structures float Strings Unions double pointer Moat | double EnumC Operators ‘An operator is simply a symbol that is used to perform operations. There can be many types of operations ike arithmetic, logical, bitwise, ete There are following types of operators to perform different types of operations in C language. © Arithmetic Operators © Conditional Operators © Logical Operators © Assignment Operators © Bitwise Operators © Special Operators Increment / Decrement operators © Relational Operators. C Arithmetic Operators - ~ An arithmetic operator performs mathematical operations such as addition, subtraction and hultiplication on numerical values (constants and variables) pication on numerical values (constants and variables). Operator | Meaning of Operator + addition or unary plus - subtraetion or unary minus . ‘multiplication 1 division % remainder after division( modulo division) Increment and decrement operators C programming has two operators inerement ++ and decrement ~to change the valu ofan ‘operand (constant or variable) byl Inerement ++ increase the value by 1 whereas decrement ~dereass the vale by 1. These two ‘operator are unary operators, meaning they only operate on a single operandCC Assignment Operators An assignment operator assignment operator is = ble, The most common used for assigning a value to a vi ample Satine as = bo ash = at=b | a=ath . - ab a=ab at=b a=ath amb ana = ab | ama Relational Operators Operator Meaning of Operator Example Equal to 5—=3 retumns 0 > * Greater than 5 >3 returns 1 < Less than 5<5 rus Not equal 10 5 $43 returns | Greater than of equal to $>=3 returns 1 Less than or equal to S<=3rcium0 C Logical Operators ea Son cataining logical operate returns ether 0 oF | depending pon weet
4 sy equals 0 operand i tue Lesko True only ifthe operands p< 5 then, expression | (€ == 5) equals to.Ritwise Operators uring computation, mathematical operations like aldition, subtaction, nition and division ars convetied to bi-level whicl rashes prowess, sie and saves power Wiwise operators used in C pengvantenng to peter Iilevel operations Operators Meaning ot operators Binwise AND Binise on Bluvieenstusive OR Bitoise complement Shite Shut iht ‘Special Operators Comma Oper ‘Conmnm operators are ws to link related expressions together. For example imae= 5,4 The sircot oper The sizeof is an unary operator which retuns the si et). ofdata (constant, vacisbles, tray structure Conditional Operator / Ternary Operator conditonalxpression? expression! : expression? The conditions operator works a fllons +The fist expression condiinalprssion i evalu fs. This expression evaluates 1 fats tne and evaluates to fits fe : = tea I xpression i tus, expessionl is evaluated. eonditonat sression is false. expressinn? evaluatedStorage Classes Keyword | Storage Initial Vatue | Seope Visibility auto Memory Garbage | With in the block With in the block register | CPU register | Garbage _| With in the block With in the block stati Memory Zero Depends on declaration ‘Throughout the program Memory Zero _ Through out the program _ | Throughout the program ifferences between ‘STRUCTURE UNION Keyword | Theseywordstructisusecto define astucure Te Feywotd union 5 used deine anion ‘Sie | Whenavanabieisassouatedwinastudure be | whenavanabie\sassocatodain union he complet Compitralacsies hememerytoreach meres: The | atocslestememarybyconsicemame sect he Sree aceaesgrestertanor equal tome sumot | lagestemery so sizeof umon ws equal to the ire ‘resets meme ttiagest mere. wemory | Eacnmemter win astucureisassanecunaie Nenarystocatedissnareabyngwaamenterset Storage areaotioeaban ‘on ‘Vatue | Atennginevalue ofa membarvitnotatiecomer “Meanghevalueefanyotine member witaer omer ‘Axering | memtusotmestucture mambervaues Inaviduat mare eanbeaccessedatatme ‘niyone membercanbeaceesseaatatme ‘Severatmenbasotastucurecanintahzeatonce, | Oniyetestmenterot aunioncanbeintaized . Different file modes File : Collection of records FILE. *Fp: Fp=fopen("File name”, " mode") Mode Perm Filedoesnot | Cursor position Previous Contents exist Read) Bead only | Returns NULL | Beginning of the file | Will not erase Wie eT Wte ony | Create new Tike | Beginning oF the ile] Will be Erased (New file) ‘Append (a Write Only] Create new file | Ending of the file | Will not erase (Appending) Read? | Bath Read! Write | Returns NULL [ Bepining of he He | Will not erase uiher Tae) | Hah Rend” Write | Create new file | Bezinning ofthe file” | Wil be Erased Append > (ar) | Both Read’ Wane | Create new file] Ending of the fle Will not eraseSm, Structures In C \ A structure is nt data types Defining a structure: To define a structure, defines a new data type, wit structstructure_name { member definit member definitio: ‘ou must use the struct statement, The struct statement more than one member. The format of the struct statement is as follows member definition; ub How to create a structur “struct” Keyword is used to ereate a structure. Following is an example struct address char street{ 100} char city| 50}; char state[20 }: How to declare structure variables? A structure variable can either be declared with structure declaration or as a separate declaration like basic types. struct Point t int x. y: } pls // The variable pl is d 17 variable declaration like basi struct Point int x. ys he int m: red with ‘Point’ c data types n) A .¢ a normal variable struct Point pl; // The variable pl is declared Ii } Hors to initialize structure members? ; ‘Structure members eannot be initialized with declaration. For example the follow te C program fails in compilation struct Point € ed, no memory is allocated for it, Memory above error is simple, wher a datatype is decta when variables are ereated. +. For example, following is a valid alized using curly brstruct Point t 3 imtx.y: int main) . t 1/8 valid initialization, member x gets value 0 and y // gets value 1. The order of declaration is followed. struct Point pl = {0.1}: 3 How to access structure elements? Structure members are accessed using dot (.) op. #include
struct Point ‘ 2 ints. ys int main() ‘ struct Point pl = {0,1}: 11 Accesing members of point pl plx=20; printt ('x = Yd, y = 9%", PLA. PLY) return 0; . }File Handling functions in C: handling functions | Description fopen () fopen ( funetion creates a new file or opens an existing file. {close () felose () funetion closes an opened file. getw () getw () finction reads an integer from file. | putw () putw 0 funet es an integer to file. fgete () fete Q function reads a character from file. pute () fpute () functions write a character to file, [gets () fgets Q function reads string from a file, one Fine at a time. fputs () {puts () function writes string to a file. [printf 0) {printf Q function writes formatted data to a file. fscanf () inf) function reads formatted data from a file. [fell fiell (Q function gives current position of file pointer. Difference between Text File and Binary File Text File 7 Binary File Character data. | Binary data ‘Changes are made easy. Can easily get corrupted ‘Can store only plain text ina file "| Can store different types of data (mage, audio, - a | text in a single file. Both Machine and Human Readable Format Only Machine Readable format Copy data from one file to other file int main() FILE "fptrl, *fptr2: char ¢: fptrl Iptr2 = fopen("C: open("MECHast", " xt" "W")5 do c= fgete(fptrl): fpute(c, fptr2): } while (c != EOF); felose( fpte printft"Sucessf felose(tptr2): ly copied");ifwe want to Function strepy0) Syntax (or) ‘Example strepy(string!. string?) dling Funetions in © include the header file called string.h. Deseript Copies string? value into string! strlen() stelen(string!) returns total number of characters in st streat() streat(string] string2) Appends string? to string] stremp0) stromp(stringl. string2) | Returns 0 if string! and string? are the less than 0 if stringl
sring2 striwrd) stelwr(string!) Converts all the characters of string! to lower case, strupr0) strupr(string!) Comerts all the characters of string! to upper case. gets() gets(stt) It reads a string as sentence puts() puts(str) It prints a string as sentence AC Program to cheek given String is palindrome or not Hinclude
include
imt mainOt ) ‘char string[20|: int ij, Length,flag = 0; printf("Enter a st scanft"%s", stn length = stelen(string); if(Mag==1) else return 0; t print{("Not a palindrome”) printf(*Palindrome” ,We Arrays: a. ; ; An array isa collection of Similar data elements that are stored in a single variable name based on index Syntay data_type arcay_name| ize}: Ex: int marks[ 10} MerkfO] evant — | | Few hey notes: + Arrays have 0 as the first index not 1. In this example, mark{O} + tthe size of an array isn, to access the last element. (me Mow to initiatize an array in C programming? 1S possible to initialize an 1) Indes is used. In this example, mark[] lamty during declaration. For example, int mark[S} = 119,10. 8, 17, 9) ‘Anotbor metho w initialize aray during dee int markl] = $19, 10, 8,17, 04; LOT ered evvear tet) | +2 | a0 5 ATKIST evveartctay l=] 2] mark{O] is equal 10 19 mark[ 1] is equal to 10 smark[2] is equal to 8 mark(3] is equal to 17 mark[4]is equal to 9* PUNCTI nant sments that togetlier perform 2 particular task. Every C program has at east one function, which is maing. A funetion is a gro (OR) Sub Program of Main program is ealled is function You can divide up your code into arate functions, How you divide up your code among. different functions is up to you, but logically the division is such that each funtion performs a spe ntay: ic task. roturntype funetion_name(Arguments list } Statement 1; Statement 25 Statement n; return value, A function definition in © programma consists of a function header and a function body. Here are all the parts of a function ~ © Return Type — A function gray return a value. The return_type is the data type of the value the function returns. Some funetions perform the desired operations without returning a value. In this ease, the returr_t pe is the keyword void.Funetion Name ~ This the actual name of the function. The function name and the parameter list together constitute the funetie (on signature. + Arguments ~ A parameter is Tike a placeholder. When a function is invoked, you pass a value to the parameter, This value is referred to as actual parameter or argument, T parameter refers to the type, order, and number of the parameters of a fumetion. Para that ers are optional: a function may contain no parameters. «Function Body ~ The function body contains a collection of statements that di ye what the funetion doe: We ean define the User defined funetions in multiple ways 1. Argument and Return value 2. Argument and No Return valuc 3. Noargument and with Return value 4. No argument and no Return value2.Function with Arguments and without return #indlude
void adddintnt); main() { intabe: “Enter a,b values"), Fincludesstdioh> imadd0, main) print{(nAddition is %d.c); } int add() { int z,a,b; printf(“Enter a,b values”); seanf(“%edtod”.&2,8b); rath; return 73 } 4.Function without Arguments and without return clude
void add0; main) { add; } void add( ) { int a.b,c; printf(“Enter a,b values”); [Coded a,b); printf(“nAddition is Yd); Activate VRecursion in C Recursion is the process which comes into existence when a funetion calls a copy of itself 10 work on a smaller problem. Any function which calls itself is called recursive function, and such function calls are called recursive calls. Recursion involves several numbers of recursive calls However. it is important to impose 2 termination condition of recursion, Recursion code is shorter than iterative code however itis difficult to understand . but it is more useful For the tasks that can be ‘ample, recursion may be applied to sorting, Recursion cannot be applied (o all the problet defined terms of similar subtasks. For E: scarching, and traversal problems. nt than recursion since function call is always Iso be solved iteratively. However, ion, for example, tower of Hanoi, Generally, iterative solutions are more effi overhead, Any problem that can be solved recursively some problems are best suited to be solved by the recurs Fibonacci series, factorial finding, ete. AC Progeam to caluclate factor #inelude
‘of a given number using recursion void main() printi(*Enter a number: "); seanf("%dl", number): fact = factorial number): printf{"Factorial is %din", fact); return 0; int factorial(int n) return Is else roturn(n # factorial(n-1)); } .AC Program to caluclate GCD of two numbers using recursion Finclude
#include
void main) { int, printf" Enter the fist number: \n"): seanf (" printf (" Enter the second number: \n"}: seant ("%d", &y): res-GCD(xy): print?(” GCD is ’ int GCD (int x. t itty return 8; else return G %» Dig.a toy: um and Maximum in an array A.C Program to find Mini Hinelude
void main) int arr[ 100]: int i, may, min, ns printi(*Enter number of elements to be stored inthe array "| scant" fori=1; sng it) ifarrlil>ma) it(arr|i|
void change(int mi print{("inside function Befor ‘fnum=num+ 100; printi(*inside funct } n) fod \n" num): n After=%d \n”, num); int main, { int x=100;, printt(’Before function call x=96d \n", x}: change(x); (passing value in function printf("After function call x=%d \n", x); inchade
void change(int *num) { print{(“inside funtion Before=%d \n",tnum): *num=*num 100; print{(“inside function After=Md \n, trum); int maing) v int x10; printi("Beiore function call x=Yd \ change(&x);_“/passing address in function printi{"After function call x=%d \n", x); return 0; rewurn } yo Outpote Outputs Before function call x 100 ide function Before 100 inside function Afier 200 After function call x. 100 Before function call x 100 inside function Before 100 inside function After 200 Alter function eall x 200 Call by value in C © In call by value method, the value of the actual parameters is copied irito the formal parameters, © In call by value method, we can not modify the value of the actual parameter by the formal parameter. © Incall by value, different memory is allocated for actual and formal parameters since the value of the actual parameter is copied into the formal parameter. Call by reference in C © Incall by reference, the address of the variable is passed into the function call as the actual parameter. The value of the actual parameters can be modified by changing the formal parameters since the address of the actual parameters is passed. © Incall by reference, the mematy allocation is similar for both formal parameters and actual parametersAC Program to given number prime or not void main’) ‘ int mi.c=05 printf("Enter a number: ") scani("%d", &n);, sisemi4) iflnPai==0) cH ifte= print Number"); else printf" n0t prime number") String Palindrome t char namet{20) , nam, int n; main) gets(namel) strepy(name?,namel sterev(name!): =stremp(name.name2) ifn 0) printi("Palindrome *) ele printf(*not palindrome")Important Points: Pointers Pointer isa variable which store address of jother variable *& is called reference operator is called dereferencing operator the size of pointer is 2 bytes 7e of near pointer 2 bytes size of far pointer 4 bytes datatype of pointer and datatype of variable should be same void pointer js also called as yeneric pointer pointer refer only one variable at a time variable can have any pointer references pointer gets incremented by size of its datatype. Pointers provide direct ace 8 to memory we can return multiple values from the functions using pointers Reduces the storage spa ‘¢ and complexity of the program Reduces the execution time of the program Provides address to functions) alternate way to access array elements (passing ba nnd deallocation, Pointers allows us to perform dynamic memory alloc Pointers helps us to build complex data structures lke linked list stack, queues, trees, graphs ete pK ers allows us to resize the dynamically allocated memory block, Addresses of objects ean be extracted using pointers(cond) { True Statements 1 Normal Statements Wcond) ( True Statements ) else { False Statements ) Normal Statements SS Ey = —_] seCo 1,10" (italaaton oti Utah) ( 1 bey of te fop 1 alent tobe exccuted ) statements outside te oopWhile loop) start Test Condition?, False True cute loop tody| je loep ends) TP L_Exesute Looe ody Fatse
You might also like
lecture 2
PDF
No ratings yet
lecture 2
55 pages
WINSEM2024-25_BCSE102L_TH_VL2024250501471_2024-12-17_Reference-Material-I
PDF
No ratings yet
WINSEM2024-25_BCSE102L_TH_VL2024250501471_2024-12-17_Reference-Material-I
65 pages
PSUC UNIT II
PDF
No ratings yet
PSUC UNIT II
143 pages
Data Types and Operator
PDF
No ratings yet
Data Types and Operator
128 pages
Constants
PDF
No ratings yet
Constants
34 pages
U-1,C-2 and C-3 (Constants, Variables, Data Types, Operators and Expressions)
PDF
No ratings yet
U-1,C-2 and C-3 (Constants, Variables, Data Types, Operators and Expressions)
88 pages
Unit 2
PDF
No ratings yet
Unit 2
41 pages
CP 4
PDF
No ratings yet
CP 4
50 pages
PPS - Unit 1
PDF
No ratings yet
PPS - Unit 1
48 pages
LECTURE 6&7_CONSTANTS_STORAGE CLASSES&OPERATORS
PDF
No ratings yet
LECTURE 6&7_CONSTANTS_STORAGE CLASSES&OPERATORS
26 pages
C Project Work 3rd-Page
PDF
No ratings yet
C Project Work 3rd-Page
40 pages
Lecture1-C-Review
PDF
No ratings yet
Lecture1-C-Review
107 pages
2. lecture Basics of C (2)
PDF
No ratings yet
2. lecture Basics of C (2)
33 pages
Operators in C
PDF
No ratings yet
Operators in C
14 pages
chap2-160308123432
PDF
No ratings yet
chap2-160308123432
48 pages
C Unit-1 PPT
PDF
No ratings yet
C Unit-1 PPT
47 pages
C Chapter 1
PDF
No ratings yet
C Chapter 1
81 pages
CP Notes
PDF
No ratings yet
CP Notes
58 pages
Notes-3
PDF
No ratings yet
Notes-3
20 pages
Introduction
PDF
No ratings yet
Introduction
23 pages
C-Notes Module 2
PDF
No ratings yet
C-Notes Module 2
12 pages
01b Data Types Expressions RSC
PDF
No ratings yet
01b Data Types Expressions RSC
34 pages
OPERATORS IN C (1)
PDF
No ratings yet
OPERATORS IN C (1)
14 pages
Oops
PDF
No ratings yet
Oops
52 pages
FEATURES OF C LANGUAGE
PDF
No ratings yet
FEATURES OF C LANGUAGE
4 pages
Review of C-Language Basics: Types
PDF
No ratings yet
Review of C-Language Basics: Types
26 pages
1_Variable,Datatype&Operator
PDF
No ratings yet
1_Variable,Datatype&Operator
33 pages
Programming in C-Peters Final
PDF
No ratings yet
Programming in C-Peters Final
163 pages
C-Lecture-2 Variables Constant Expression and Operator
PDF
No ratings yet
C-Lecture-2 Variables Constant Expression and Operator
34 pages
Fundamentals of ‘C’
PDF
No ratings yet
Fundamentals of ‘C’
40 pages
1) Lec3 Operators PDF
PDF
No ratings yet
1) Lec3 Operators PDF
23 pages
Dsds
PDF
No ratings yet
Dsds
46 pages
CP 3
PDF
No ratings yet
CP 3
33 pages
lecture 4
PDF
No ratings yet
lecture 4
24 pages
C4 OperatorExp 2012 Eng PDF
PDF
No ratings yet
C4 OperatorExp 2012 Eng PDF
30 pages
C Programming Concepts
PDF
No ratings yet
C Programming Concepts
27 pages
History of Social Media
PDF
No ratings yet
History of Social Media
64 pages
Data Classification (Data Types)
PDF
No ratings yet
Data Classification (Data Types)
34 pages
Operators
PDF
No ratings yet
Operators
41 pages
1 Variable, Datatype&Operator
PDF
No ratings yet
1 Variable, Datatype&Operator
33 pages
Unit - I Algorithm/pseudo Code
PDF
No ratings yet
Unit - I Algorithm/pseudo Code
43 pages
Introduction To C
PDF
No ratings yet
Introduction To C
32 pages
Token, Variables & Datatypes - W1 - 1
PDF
No ratings yet
Token, Variables & Datatypes - W1 - 1
9 pages
C4 Vfsrfa2012 Eng
PDF
No ratings yet
C4 Vfsrfa2012 Eng
30 pages
Algorithm and Programming Week4
PDF
No ratings yet
Algorithm and Programming Week4
35 pages
C Programming Language: C Is Case-Sensitive
PDF
No ratings yet
C Programming Language: C Is Case-Sensitive
27 pages
Data Types and Operators of C
PDF
No ratings yet
Data Types and Operators of C
10 pages
C Language: Step 1: Creating A Source Code
PDF
No ratings yet
C Language: Step 1: Creating A Source Code
14 pages
PPS ch2
PDF
No ratings yet
PPS ch2
34 pages
Basic C Operators
PDF
No ratings yet
Basic C Operators
36 pages
Lecture Note CSC104
PDF
No ratings yet
Lecture Note CSC104
9 pages
1.operators in C - C++
PDF
No ratings yet
1.operators in C - C++
3 pages
Operators and Expressions, Control Structures in C
PDF
No ratings yet
Operators and Expressions, Control Structures in C
134 pages
Class 2
PDF
No ratings yet
Class 2
90 pages
Variables and Data Types - C
PDF
No ratings yet
Variables and Data Types - C
6 pages
Set A PDF
PDF
No ratings yet
Set A PDF
6 pages
C Programming Cheat Sheet
PDF
100% (1)
C Programming Cheat Sheet
11 pages
Chem 1
PDF
No ratings yet
Chem 1
13 pages
The Role of Mathematics in Algorithm Design
PDF
No ratings yet
The Role of Mathematics in Algorithm Design
11 pages
Chem Sylla
PDF
No ratings yet
Chem Sylla
2 pages
Plumbing
PDF
No ratings yet
Plumbing
3 pages
33CHEMM
PDF
No ratings yet
33CHEMM
1 page