Location via proxy:
[ UP ]
[Report a bug]
[Manage cookies]
No cookies
No scripts
No ads
No referrer
Show this form
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)
59 views
50 Programming in C and Algorithms
Uploaded by
nguyen hoang ngan
AI-enhanced title
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save 50_Programming_in_C_And_Algorithms For Later
Download
Save
Save 50_Programming_in_C_And_Algorithms For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
59 views
50 Programming in C and Algorithms
Uploaded by
nguyen hoang ngan
AI-enhanced title
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save 50_Programming_in_C_And_Algorithms For Later
Carousel Previous
Carousel Next
Save
Save 50_Programming_in_C_And_Algorithms For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 165
Search
Fullscreen
PREFACE This study material deals with the concepts of c programming and algorithms. C is a general- Purpose high level language that was originally developed by Dennis Ritchie for the Unix operating system. Tt was first implemented on the Digital Equipment Corporation PDP-11 computer in 1972. C was initially "used for system development work, in particular the programs that make-up the operating system. C was adopted as a system development language because it produces code that runs nearly as fast as code written in assembly language. All the C programs are written into text files with extension ".c’. When you write any program in C language to be executed then, that program need to be compiled by aC Compiler. The compiler converts the program into object code which can be read by a computer. This is called machine language (i.e. binary format). So before proceeding, make sure you have C Compiler available in your computer. Analgorithm refers to the concept of data structures in detail. efore introducing data structures we should understand that, computer is to store, retrieve, and process « large amount of data. Ifthe data is stored in well organized way on a storage medium and in computer's memory then it can be accessed quickly for processing. This can further reduce the latency and the user is provided fast response. Data Structure isa way of collecting and organizing data in such a way that we can perform operations on these data in an effective way. Data Structures is about rendering data elemeats in terms of some relationship, for better organization and storage. A data structure should be seen as a logical concept that must address two fundamental concerns. First, how the data will be stored, and second, what operations will be performed on it? As data structure isa scheme for data organization so the functional definition of a data structure should be independent of its implementation. The functional definition ofa data structure is known as ADT (Abstract Data Type) which is independent of implementation. The implementation partis left on developers who decide which technology better suits to their project needs. Ms. Uma Shankari HoD Department of Computer Application Dr. M.G.R. Janaki Arts & Science College for WomenDEGREE OF BACHELOR OF COMPUTER APPLICATIONS & LAW (B.C.A.LLB,) Title of the Programming in Cand Algorithms(HDAH) Course/ Paper Core - 1 1 Year & Second Semester Credit: 4 Objective of | This course introduces the basic programming concepts and fundamentals of the course Programming Language C and Algorithm Unit 1: C fundamentals Character set — Identifier and keywords — data types — constants ~ Variables — Declarations ~ Expressions ~ Statements - Operators ~ Library functions- Data input output functions - Simple C programs — Flow of control - if, if-else, while, do-while, for loop, Nested control structures ~ Switch, break and continue, go to statements - Comma operato- Unit-2: Functions -Definition ~ proto-types — Passing a:guments- Recursions- Storage Classes ~ Arrays ~ Defining and Processing ~ Passing arrays to functions = Multi-dimension arrays — Arrays and String. Structures ~ User defined data types ~ Passing structures to functions — Self-referential structures - Unions — Bit Course outline | wise operations. Unit 3: Fundamentals of algorithms - Notion of an algorithm- Pseudo-code conventions like assign ment statements and basic controi structures ~ Analysis of algorithms - Running t me of an algorithm - worst and average case analysis. Unit-4: Sorting Algorithms - Bubble, Selection- Insertion and Merge sort- Efficiency of algorithms -Implement using C- Searching Algorithms-Linear Search and Binary Search - Graph Algorithms- BFS, DFS, shortest paths - single source and all pairs. Unit-5 : Pointers ~ Decla-ations — Passing pointers to Functions — Operation in Pointers - Pointer and Arrays ~ Arrays of Pointers ~ Structures and Pointers — Files- Creating, Processing, Opening and Closing a data file. Recommended Texts () — E.Balagursamy, 2010, Programming in ANSI G, Fifth Edition, TMH. New Delhi. (ii) Horowitz, S. Sahni, and S. Rajasekaran, Computer Algorithms, Galgotia Pub, Pvt. LTs., 1998. Reference Books (i) B. W. Kernighan and D. M. Ritchie, 1990, The C Programming Language, Second Edition, PHI, New Delhi. (ii) J.R. Hanly and E. B. Koffman, 2005, Problem solving and program design in C, Fourth Edition, Pearson Education India. (iii) H.Schildt, C: The Complete Reference, 4” Edition, TMH Edition, 2000.PROGRAMMING IN C AND ALGORITHMS S.No. CHAPTER DETAIL PAGE No. 1. INTRODUCTION TO C 1 2. C FUNDAMENTALS 5 3. OPERATORS AND EXPRESSIONS 11 4, DATA INPUT AND OUTPUT FUNCTIONS 16 5. CONTROL STRUCTURES 20 6. FUNCTIONS 28 7. STORAGE CLASSES 34 8. ARRAYS AND STRINGS 36 9. STRUCTURES AND UNIONS 42 10. ALGORITHMS 49 11. SORTING ALGORITHMS 72 12. SEARCHING ALGORITHMS 86 13. POINTERS, 100 14. DATA FILES. 104 SIMPLE C PROGRAMS 110CHAPTER 1 INTRODUCTION Computer Basically it is a fast calculating machine which is nowadays used for variety of uses ranging from house hold works to space technology. The credit of invention of this machine goes to the English Mathematician Charles Babbage. Types of Computers: Based on nature, computers are classified into Analog computers and Digital computers. The former one deals with measuring physical quantities (concerned with continuous variables) which are of late rarely used. The digital computer operates by counting and it deals with the discrete variables. There isa combined form called Hybrid computer, which has both features. Based on application comput2rs are classified as special purpose computers and general computers. As the name tells special computers are designed to perform certain specific tasks where as the other category is designed to cater the needs of variety of users. Basic structure of a digital computer The main components of a computer are 1) Inputunit (IU), 2) — Central Processing unit (CPU) and 3) Output unit (OU). The information like data, programs etc are passed to the computer through input devices. The Keyboard, mouse, floppy disk, CD, DVD, joystick etc are certain input dev ices. The output device is to get information from a computer after processing. VDU (Visual Display Unu'), Printer, Floppy disk, CD etc are output devices. The brain ofa computer is CPU. It has three components- Memory unit, Control unit and Arithmetic and Logical unit (ALU)- Memory unit also called storage device is to store information. Two types memory are there in a computer. They are RAM (random access memory) and ROM (read only memory). When é program is alld, itis loaded and processed in RAM. When the computer is switched off, what ever stored in RAM will be deleted. So it is atemporary memory. Where KOM isa permanent memory, where data, program etc are stored for future use. Inside a computer there is storage device called Hard disk, where data are stored and can be accessed at any time. The contro} unit is for controlling the execution and interpreting of instructions stored in the memory. ALU is the unit where the arithmetic and Logical operations are performed. The information toa computer is transformed to groups of binary digits, called bit. The length of bit varies from computer to computer, from 8 to 64. A group of 8 bits is called a Byte and a byte generally represents one alphanumeric (Alphabets and Numerals) character. The Physical components of a computer are called hardwares. But for the machine to work it requires certain programs (A set of instructions is called a program). They are called softwares. There are two types of softwares ~ System software and Application software ~ System software includes Operating systems, Utility programs and Language processors.ASCII Codes: American Standard Code for Information Interchange. These are binary codes for alpha numeric data and are used for printers and terminals that are connected to a computer systems for alphabetizing and sorting. Operating Systems The set of instructions which resides in the computer and governs the system are called operating systems, without which the machine will never function. They are the medium of communication between a computer and the user. DOS, Windows, Linux, Unix etc are Operating Systems. Utility Programs ‘These programs are developed by the manufacturer for the users to do various tasks. Word, Excel, Photoshop, Paint etc are some of them. Languages These programs facilitate the users to make their own programs. User's programs are converted to machine oriented and the computer does the rest of works. Application Programs These programs are written by users for specific purposes. Computer Languages They are of three types — 1 Machine Language (Low level language) 2 Assembly language (Middle level language) 3 User Oriented languages (High level language) Machine language depends on the hardware and comprises of 0 and 1 . his is tough to write as one must. know the internal structure of the computer. At the same time assembly language makes use of English like wordsand symbols. With the help of special programs called Assembler, assembly language is converted to machine oriented language. Here also a programmer faces practical difficulties. To overcome this hurdles user depends on high level languages, which are far easier to learn and use. To write programs in high level language, programmer need not know the characteristics of a computer. Here he uses English alphabets, numerals and some special characters. Some of the High level languages are FORTRAN, BASIC, COBOL, PASCAL, C, C++, ADA etc. We use C to write programs. Note that High level languages cannot directly be followed by a computer. It requires the help of certain software's to convert it into machine coded instructions. This software's are called Compiler, Interpreter, and Assembler. The major difference between a compiler and an interpreter is that compiler compiles the user's program into machine coded by reading the whole program at a stretch where as Interpreter translates the program by reading it line by line. C and BASIC are an Interpreter where as FORTRAN is aPROGRAMMING METHODOLOGY A computer is used to solve a problem. The steps involved are : 1. Analyze the problem Identify the variables involved Design the solution Write the program Enterit into a computer Compile the program and correct errors Correct the logical errors if any Test the program with data pena een Document the program Algorithms Step by step procedure for solving a problem is called algorithm. Example To make a coffee Stepl: Take proper quantity of water in a cooking pan Step2: Place the pan on a gas stove and light it Step3: Add Coffee powder when it boils Step4: Put out the light and add sufficient quantity of sugar and milk Step5: Pour into cup and have it. Toadd two numbers Step1: Input the numbers asx, y Step2: sum=x+y Step3: print sum Fora better understanding of an algorithm, it is represented pictorially. The pictorial representation of an algorithm is called a Flow Chart. For this certain pictures are used. Consider a problem of multiplying two numbers Algorithm Step1: Input the numbers asa and b Step2: find the product axbStep3: Print the result Consider the following problem to find the highest of three numbers Algorithm Step 1: read the numbers as x,y and z Step 2: compare xand y Step 3: ifx > y then compare x with z and find the greater Step 4: Otherwise compare y with z and find the greater Review Questions 1. Define computers? 2. Enlist the features of C. 3. How will you classify computer systems? 4. Whatare the basic operations of Computer? 5. Whatare the characteristics of computers? 6. Whatare the steps to solve the problem in a computer system? Exercise: Write Algorithm and flow chart for the solution to the problems: 1. Tofind the sum ofr, say 10, numbers. To find the factorial of n, say 10. To find the sum of the series 1+x+x2+x3+... To find the sum of two matrices. To find the scalar product of two vectors To find the Fibonacci series up ton. yoy es op To find ged of two numbersCHAPTER 2 C FUNDAMENTALS A BRIEF HISTORY OF C evolved from a language called B, written by Ken Thompson at Bell Labs in1970. Ken used B to write one of the first implementations of UNIX. Bin turn was descendant of the language BCPL (developed at Cambridge (UK) in 1967), with most of its instructions removed. So many instructions were removed in going from BCP]. to B, that Dennis Ritchie of Bell Labs put some back in (1972), and called the language C. The famous book The C Programming Language was written by Kernighan and Ritchie in 1978, and was the definitive reference book on C for almost a decade. The original C was still too limiting, and not standardized, and so in 1983 an ANSI committee was established. to formalise the language definition. It has taken until now (ten years later) for the ANSI (American National Standard Institute) standa-d to become well accepted and almost universally supported by compilers STRUCTURE OF A PROGRAM AC program basically consists of the following parts: © Preprocessor Commands . Functions * Variables © Statements & Expressions © Comments Let us look ata simple code that would print the words “Heilo World”: #includecstdio.h> Intmain() { /*my first program in C*/ Printf(“Hello, World! \n"); Return 0; } Let us look various parts of the above program: 1. Thefirstline ofthe program #include
is a preprocessor command, which tells a C compiler to include stdio.h file before going to actual compilation 2. Thenext ine int main()is the main function where program execution begins. 3. Thenextline/*.../ will be ignored by the compiler and it has been put to add additional comments in the program. So such lines are called comments in the program. 4, Thenext line printf{...)is another function available in C which causes the message “Hello, World!” to be displayed on the screen. 5. The next line return 0; terminates main()function and returns the value 0. 5THE CHARACTER SET The character set is the fundamental raw material of any language and they are used to represent information. Like natural languages, computer language will also have well defined character set, which is useful to build the programs. Types Character Set Lowercase Letters az Uppercase Letters AtoZ Digits 0-9 Special Characters 1@#S%"K* White Spaces ‘Tab Or New line Or Space IDENTIFIER AND KEYWORDS Identifier are names given to various program elements like variables, arrays and functions. () The name should begin with a letter and other characters can be letters and digits and also can contain underscore character ( _)Example: area, average, x12, name_of_place etc.. (ii) Keywords are reserved words in C language. They have predicted meanings and are used for the intended purpose. Standard keywords are auto,break, case, char, const, continue, default, do, double, else enum, extern, float, for, goto, if, int, long, register, return, short, signed, sizeof, static, struct, switch, typedef, union, unsigned, void, volatile, while. (Note that these words should not be used as. identities.) DATA TYPE © The variables and arrays are classified based on two aspects first is the data type it stores and the second is the type of storage. © The basic datatypes in C language are int, char, float and double. © They are respectively concerned with integer quantity, single character, numbers, with decimal point or exponent number and double precision floating point numbers (ie; of larger magnitude ). © These basic data types can be augmented by using quantities like short, long, signed and unsigned. ( ie; long int, short int, long double etc.....) CONSTANTS There are 4 basic types of constants. They are integer constants, floating-point constants, character constants and string constants (a) Integer constants: It is an integer valued numbers, written in three different number system, decimal (base 10) , octal(base8), and hexadecimal(base 16). A decimal integer constant consists of 0,1,.. Example : 75 6,0,32, etc..... 5,784, 39,98, 2-5, 09 etc are not integer constants. 6‘An octal integer constant consists of digits 0,1,....7. with Ist digit 0 to indicate that it is an octal integer. Example : 0, 01, 0756, 032, etc..... 32, 083, 07.6 etc..... are not valid octal integers. A hexadecimal integer constant consists of 0,1, ....9,A, B.C, D, E, F. It begins with Ox. Example: 0x7AA2, OxAB, etc...... 0x8.3, OAF2, OxG etc are not valid hexadecimal constants. Usually negative integer constant begin with (-) sign. An unsigned integer constant is identified by appending U to the end of the constant like 673U, 098U, 0xACLFUetc. Note that 1234560789LU is an unsigned integer constant. (b) floating point constants : It is a decimal number (ie: base 10) with a decimal point or an expor ent or both. Ex; 32.65, 0.654, 0.2E-3, 2.65E10 etc. These numbers have greater range than integer constants. (©) Character constants : It is a single character enclosed in single quotes like ‘a’. ‘3', ”, ‘A’ etc. each character has an ASCII to identify. For example ‘A’ has the ASCII code 65, '3' has the code 51 and soon. (@) escape sequences: An escape sequence is used to express non printing character like a new line, tab etc. it begin with the backslash (\) followed by letter like a. n, b, t, v,r, etc. the commonly used escape sequence are \a: for alert \n: newline \0: null \b: backspace \F: form feed \?: question mark \f:horizontal tab \r: carriage return _\’: single quote \v: vertical tab —_\": quotation mark (©) string constants: it consists of any number of consecutive characters enclosed in double quotes .Ex C program” , “mathematics” etc...... VARIABLES AND ARRAYS A variable is an identifier thar is used to represent some specified type of information. Only a single data can be stored in a variable. The data stored in the variable is accessed by its name. before using a variable ina program, the data type it has to store is to be declared. Example : int a, b, c, a=3; c=atb; Note: A statement to declare the data types of the identifier is called declaration statement. An array isan identifier which is used to store a collection of data of the same type with the same name. the data stored isan array are distinguished by the subscript. The maximum size of the array represented by the identifier must be mentioned. Example : int mark(100] . With this declaration n, mark is an array of size 100, they are identified by mark{0},mark{1}...........mark[99].Note : along with the declaration of variable, it can be initialized too, For example int x=10; with this the integer variable x is assigned the value 10, before it is used. Also note that Cis a case sensitive language. i.e. the variables d and D are different. DECLARATIONS This is for specifying data type. All the variables, functions etc must be declared before they are used. A declaration tells the compiler the name and type of a variable you'll be using in your program. nits simplest form, a declaration consists of the type, the name of the variable, and a terminating semicolon: Example : inta,bc; Float mark, x{100], average: char name(30); char e; inti; float f; You may wonder why variables must be declared before use. There are two reasons: 1. It makes things somewhat easier on the compiler; it knows right away what kind of storage to allocate and what code to emit to store and manipulate each variable; it doesn’t have to try to intuit the programmer's intentions. 2, It forces a bit of useful discipline on the programmer: you cannot introduce variables willy-nilly; you must think about them enough to pick appropriate types for them. (The compiler’s error messages to you, telling you that you apparently forgot to declare a variable, are as often helpful as they are a nuisance: they're helpful when they tell you that you misspelled a variable, or forgot to think about exactly how you were going to use it.) EXPRESSION This consists of a single entity like a constant, a variable, an array or a function name. it also consists of some combinations of such entities interconnected by operators. Example : a, a+b, xey, caatb, xcay ete. STATEMENTS Statements are the “steps” ofa program. Most statements compute and assign values or call functions, but we will eventually meet several other kinds of statements as well. By default, statements are executed in sequence, one after another ‘A statement causes the compiler to carry out some action. There are 3 different types of statements ~ expression statements compound statements and control statements. Every statement ends with a semicolon.Example: (1) e=a +b; QE a=3; (3) if (a
(greater than ), >= ( greater than or equal to), equal to) and = (not equal to ) are relational operators. A logical expression is expression connected with a relational operator. For example ‘b'b — 4°a'c< 0 is a logical expression. Its value is either true or false. inti, jks k>4 has the value true k<=3 has the value false. LOGICAL OERATORS The relational operators work with arbitrary numbers and generate true/false values. You can also combine true/false values by using the Boolean operators, which take true/false values as operands and compute new true/false values The three Boolean operators ate: © &&and © flor © tnot (takes one operand; “ unary”) 12The && (“and”) operator takes two true/false values and produces a true (1) result f both cperandsare true (that is, ifthe lefthand side is true and the right-hand side is true). The || ("or” operator takes two true/false values and produces a true (1) result ifeither operand is true. The 1(“not”) operator takes a single true/false value and negates it, turning false to true and true to false (0 to 1 and nonzero to 0). && (and ) and || (or) are logical operators which are used to connect logical expressions. ‘Where as ! ( not) is unary operator, acts on a single logical expression. For example, 1. (a<5) && (a>-2) 2. (ac=3) || (b>2) In the first example if a= -3 or a=6 the logical expression returns true. ASSIGNMENT OPERATORS ‘These operators are used for assigning a value of expression tw another identifier. a+ /z and %= are assignment operators. a= bic results in storing the value of bec in ‘a’. a+=5 results in increasing the value of a by 5 a /=3 results in storing the value a/3 in a and it is equivalent a: a/3 Note : 1. ifa floating point number is assigned to a integer type data variable, the value will be ‘truncated. Example : float =5.36; int; bea It results in storing 5 to b. Similarly if an integer value is a assigned to a float type like float x=3 the value of x stored is 3.0. CONDITIONAL OPERATOR The operator ?: is the conditional operator. It is used as variable 1 = expression 1 ? expression 2 : expression 3. Here expression 1 isa logical expression and expression 2 and expression 3 are expressions having numerical values. If expression 1 is true, value of expression 2 is assigned to variable | and otherwise expression3 is assigned. Example : inta,b,c,d,e de(acb)?a: e=(b>c) 2b; ‘Then d=3 and e=8 13LIBRARY FUNCTIONS They are built in programs readily available with the C compiler. These functions perform certain operations or calculations. Some of these functions return values when they are accessed and some carry out certain operations like input, output. A library function accessed in a used written program by referring its name with values assigned to necessary arguments. Some of these library functions are : abs(i),ceil(d), cos(d), cosh(d), exp(d),_fabs(d),floor(d), —getchar(_—_), 1og(4),pow(d,d’),printf( ), putchar(c), rand( ), sin(d), sqrt(d), scanf( ), tan(d), toascii(c),toupper(c), tolower(c). Note: the arguments i, c, d are respectively integer, char and double type. Example: #includecmath.h> #includecstdio.h> #include
main() { float x, s; printf(“\n input the values of x:"); scanf(“F", 8%); sesqrt(x)s printf(“\n the square root is 96f”,s); J Review Questions 1. Distinguish between binary minus and unary minus. List out the different operators involve for comparision and logical decision making in C. List out the five arithmetic operators in C. What are the rules to use period(.) operator. What is an expression? How is an expression different from the variables? What is mean by conditional expression? Noyes wn What is mean by the comparision and logical operator? How are they different from the arithmetic and assignment operator? 8. What is mean by the equality operator? How do these differ from an assignment operator. 14‘What is modulus operator and how does it operate in C. “What is the associtivity rules involve in this operator. What is unary operator? List out the different operator involve in the unary operator. Can multiple assignments be written in C. In what order will the assignment be carried out. Describe arithmetic operator? Differentiate between relational and logical operators used in C? Discuss Precedence order and associativity of operators Discuss the conditional operator with the help ofa program. Explain * operator and & operator with example. Explain conditional operator with example. Explain logical operators and expressions used in C? Explain sizeof operator with example. Explain the difference between ‘=’ and ‘==’ operator explain with example? Explain with example ++i and i++. ‘What are Operators? Mention their types in C. What do you understand by operators? Explain the use of the following operators : “What is an expression? How is an expression differing from variables? ‘What is the modulus operator and how does it works explain it with example ‘What is the purpose of comma operator within which statement does the comma operator usually appear. ‘What is unary operator? ‘Write a short note precedence & order of ‘evaluation?CHAPTER 4 DATA INPUT & OUTPUT For inputting and outputting data we use library function. The important of these functions are getch( ), Putchar( ), scanf{ ), printf(), gets( ), puts( ). For using these functions in a C-program there should be a Preprocessor statement #include
. {A preprocessor statement is a statement before the main program, which begins with # symbol.) stdio.h isaheader file that contains the builtin program of these standard input output function. getchar function - It is used to read a single character (char type) from keyboard. The syntax is char variable name = getchar( ); Example: chary, c= getchar( ); For reading an array of characters or a string we can use getchar() function. Example: #include
main() { char place(80); int i; for(i = 0;( place [i] = getchar( ))! = “\n’, ++i); } This program reads line of text. putchar function - Itis used to display single character. The syntax is putchar(char ¢); Example: char; cma; putchar(c); Using these two functions, we can write very basic program to copy the input, a character ata time, tothe output: #include
/" copy input to output */ main() i inte; c=getchar();while(c != EOF) { putchar(c); c= getchar(); } return 0; } scan function - This function is generally used to read any data type: int, char, double, float, string, The syntax is scanf (control string, list of arguments); The control string consists of group of characters, each 8roup beginning % sign and a conversion character indicating the data type of the data item, The conversion eharacen are c,d,e,f.0,s,u,x indicating the type resp, char decimal integer, floating point value in exponent form, Aloating point value with decimal point, octal integer, string, unsigned integer, hexadecimal integer. ie "Se" "Oia etcare such group of characters, An example of reading a data: #includecstdio.h> main() ( char name{30), line; int x; float y; scanf(“%bs%d%F", name, &x, &y); scanf(“%c",}ine); } NOTE: 1)In the list of arguments, every argument is followed by & (ampersand symbol) except string variable. 2) s-type conversion applied to a string is terminated by a blank space character. So string having blank space like “Govt, Victoria College” cannot be read in this manner Fae reading such a string constant we use the conversion string as “%[*\n]" in place of “96g”, Example: char place{80}; scanf("%[\n)", place); with these statements. line: of text (until carriage return) can be input the variable ‘place’, 17printf function Thisis the most commonly used function for outputting data of any tyPe- The syntax is printf(control string, list of arguments) Here also control string consists of group of characters, each group having % symbol and conversion characters like ¢, d, 0, f, xete. Example: #includecstdio.h> ‘main() t intx; scanf("%6d” Sx); xox printf(“The square of the number is %d".*) } Note that in this list of arguments the variable names are without &symbol unlike in the case of scanf{ ) fametion. Inthe conversion string one can include the message to ‘be displayed. In the above example “The square of the number is” is displayed and is Followed by the value of x. For writing a line of text (which isctude blank spaces)the conversion string is “és” unlike in scanf function. (There itis “{*\n)")- More about printf statement There are quite a number of format specifiers for printf, Here are the basic ones: print an int argument in decimal print along int argument in decimal printa character printa string print a float or double argument same as %f, but use exponential notation use %e or %f, whichever is better print an int argument in octal (base 8) princan int argument in hexadecimal (base 16) geegeeerge print a single % To illustrate with a few more examples: the call printf(‘%c ed 96£%e 96s %649694\n”, ‘1’ 2.3.14, 56000000.,"eight”, 9); would print 123.140000 5.600000e+07 eight 9% The call printf(“96d %o %x\n”, 100, 100, 100); 18would print 100 144 64 Successive calls to printf just build up the output a piece at a time, so the calls printf(“Hello, *); printf(‘world!\n”); ‘would also print Hello, world! (on one line of output). While inputting or outputting data field width can also be specified. This is included in the conversion. string.(if we want to display a floating point number convert to3 decimal places the conversion string is “9.3f") For assigning field width, width is placed before the conversion character like"9%10f’,"%8d"."%12e” and so on... Also we can display data making correct toa fixed no of decimal places. For example if we want to display x-30.2356 as 30.24 specification may be “9%5.2f" or simply “%.2f". Review Questions 1. _ Distinguish between i)fprintf()ii)fscanf() 2. Distinguish between getch and getc 3. Distinguish between putch and pute 4. Explain i)fprintf()ii)fscanf() 5. Explain putc and getc in brief 6. Whatare the format codes used along with the scanf(). Display the various data types in C. 7. Whatare the salient features of standard input and output file 8 Whatis the printf() and compare with putchar(). 9. What is the scanf{) and how does it differ from the getchar‘).. 10. Difference between formatted & unformatted statement? 11. Explain - a) getc() b) pute’) 12. Explain Getw() & Putw() function 13, Explain printf() function with an example 14. Explain the following functions i)getch() and ii) clrscr()CHAPTER 5 CONTROL STATEMENTS When we run a program, the statements are executed in the order in which they appear in the program. Also each statement is executed only once. But in many cases we may need a statement or a set of statements to be executed a fixed no of times or until a condition is satisfied. Also we may want to skip some statements based on testinga condition. For all these we use control statements. Control statements are of two types ~ branching and looping. BRANCHING Itis to execute one of several possible options depending on the outcome of a logical test, which is carried at some particular point within a program. LOOPING It is to execute a group of instructions repeatedly, a fixed number of times or until a specified condition is. satisfied. BRANCHING 1. if else statement Itis used to carry out one of the two possible actions depending on the outcome ofa logical test. The else portion is optional. The syntax is If (expression) statement! [if there is no else part] Or If (expression) Statement 1 else Statement 2 Here expression isa logical expression enclosed in parenthesis. If expression is true, statement 1 or statement 2 is a group of statements, they are written as a block using the braces {} Example: 1. if(x<0) printf(“\n xis negative”); 2. iffx<0) printf("\n xis negative”); else printf(“\n xis non negative”); B:iflax<0) { XeX; s=sqrt(x); 20} else s=sqrt(x); 2. nested if statement Within an if block or else block another if-- else statement can come. Such statements are called nested if statements. The syntax is If (el) s1 if (e2) s2 else 83 wise st 3. Ladder if statement Inorder to create a situation in which one of several courses of action is executed we use ladder if statements. The syntax is If (el) s1 else if (e2) s2 else if (e3) 83 else sn Example: if(mark>=90) printf(‘\n excellent”); else if(mark>=80) printf(“\n very good”); else if{mark>=70) printf(“\n good”); else if(mark>=60) printf(“\n average”); else printf(“\n to be improved”); SWITCH STATEMENT It is used to execute a particular group of statements to be chosen from several available options. The selection is based on the current value of an expression with the switch statement. The syntax is: switch(expression) { 21case value]: sl breal case value 2: s2 break; default: sn All the option are embedded in the two braces { }. Within the block each group is written after the label case followed by the value of the expression and a colon. Each group ends with ‘break’ statement. The last. may be labelled ‘default’, This is to avoid error and to execute the group of statements in default if the value of the expression does not match valuel, value2,....... LOOPING 1, The while statement This is to carry out a set of statements to be executed repeatedly until some condition is satisfied. The syntax is: While (expression) statement The statement is executed so long as the expression is true. Statement can be simple or compound. Example 1: #includecstdio.h> while(n > 0) i printf(“\n"); nen-1; } Example 2: #include
main() C int while(x<=10) 22{ printf(“%d",i); tis } J 2. do while statement This is also to carry out a set of statements to be executed repeatedly so long as a condition is true. The syntax is: do statement while(expression) Example: #include
main() { intiel; do { Prinef(“%6d",i); +i; Jwhile(ic=10); J THE DIFFERENCE BETWEEN while loop AND do ~ while Joop 1) Inthe while loop the condition is tested in the beginning whereas in the other case itis ‘done at the end. 2)In while loop the statements in the loop are executed only if the condition is true. whereas in do- while loop even if the condition is not true the ‘statements are executed atleast once. 3. for loop Itis the most commonly used looping statement in C. The general form is For(expression expression2;expression3)statement Here expression! is to initialize some parameter that controls the looping action. expression2 is a condition and it must be true to carry out the action. expression3 isa unary expression er an assignment expression. Example: #includecstdio.h> main() { int & for(i=1sic=10;+4i) 23printf(“%d”,i); } Here the program prints istarting from 1 to 10-First iis assigned the value ? and then it checks whether iex10 If iis printed and then jis increased by one. Itcontinues until ic=10. An example for finding the average of 10 numbers. #include
main() { int i: float x.avg-0; for(i=1si<=10:++i) ( scanf(“%f”,&x); avg +=X%: } avg /= 10; printfi"\a averave 94" avg); The break statement ‘The break statements used to terminate the loop or to exit from a switch. It is used in for. while, do-while and switch statement. The syntax is break; Example 1: A program to read the sum of positive numbers only #includecstdioh> main() { int x, sum=0; intn=1; while(n<=10) { scanf("%6d” 8x); if(x<0) break;sums=x; } printf("%6d” sum); } Example 2 :A program for printing prime numbers between 1 and 100: #include
#include
main() { inti, j printf(“9d\n”, 2); 1 <= 100; i= i+ 1) for(i ( for(j = 2: j < i; { iff % j ==0) break; if(j > sqrt(i)) { printf(“%d\n”, i); break; } j } return 0; J Here while loop breaks if the mput for x is ~ve. The continue statement {tis used to bypass the remainder of the current pass through a loop. The loop does not terminate when Continue statement is encountered, but statements after continue are skipped and proceeds to the next pass through the loop. j+1) Inthe above example of summing up the non negative numbers when a negative valu input, it breaks and the execution of the loop ends. Incase if we want to sum 10 nonnegative numbers, we ean use contin instead of break 25Example : #include
main() { int x, sum=0, n=0; while(n<10) { scanf("%ed"); if(x<0) continue; sum+=x; +45 } prinef(‘9ed” sum); J GO TO statement Itisused to alter the normal sequence of program execution by transferring control o some other part of the program . The syntax is goto label ; Example : #include
main() { intn=1,x,sum=0; while(n<=10) { scanf(‘%d" ,&x); if(x<0)goto error; sum+=x; aan; } error: printf(“\n the number is non negative”): } 26Review Questions 1. penny es wn Compare while loop and for loop with example. Whaat is looping in C? What are the advantages of looping? Whaat is the role played by the break statement within the switch statement. Explain with example. Whaat is use of continue in C. Differentiate between if-else-if and switch statement. Explain for loop? Explain nested for loop with an example Explain nested if - else with example. Explain switch statement with its syntax and example. Explain syntax and use of Do__While statement How does Switch statement differ from Nested if? What are the different decision control structure availablv in C. Explain with examples. Whaat are the various loop constructs available in C. Distinguish between while and do- while loops. Whaat is Nested if else explain with an example? Whaat is use of if statement? ‘What the term ‘Nesting’ refers to? Explain with the help of an example. Why do we avoid the use of goto statements in programs? write a syntax of while loop? Write disadvantages of goto statement. 27CHAPTER 6 FUNCTIONS Functions are programs .There are two types of functions- library functions and programmer written functions. We are familiarised with library functions and how they are accessed in a C program. ‘The advantages of function programs are many 1) A large program can be broken into a number of smaller modules. 2) Ifa set of instruction is frequently used in program and written as function program, it can be used in any programas library function. Defining 2 function Generally a function is an independent program that carries out some specific well defined task. It is written after or before the main function. A function has two components-definition of the function and body of the function. Generally it looks like datatype function name(list of arguments with type) { statements return; } Ifthe function does not return any value to the calling point (where the function is accessed) . The syntax looks like function name(list of arguments with type) { statements return; J Ifa value is returned to the calling point, usually the return statement looks like return(value).In that case data type of the function is executed. Note that ifa function returns no value the keyword void can be used before the function name Example: a writecaption(char x{] ); { prinef(‘%s",x); return; 3 28(2) int maximum(int x, int y) maximum( int x,int y) C int; ze(xoay)?x: printf(‘\n maximum =%d”,z); return; } Note: In example (1) and (2) the function does not return anythir g. Advantages of functions 1. Itappeared in the main program several times, such that by making it a function, it can be written just once, and the several places where it used to appear can be replaced with calls to the new function. 2. The main program was getting too big, so it could be made (presumably) smaller and more manageable by lopping part of it off and making it a function. 3. It does just one well-defined task, and does it well. 4, Its interface to the rest of the program is clean and narrow 5. Compilation of the program can be made easier. Accessing a function ‘A function is accessed in the program (known as calling program)by specifying its name with optional list of arguments enclosed in parenthesis. If arguments are not required :hen only with empty parenthesis. The arguments should be of the same data type defined in the function definition. Example: 1)inta, y-maximum(a.b); 2) char name{50) ; writecaption(name); 3) arrange(); Ifa function is to be accessed in the main program it is to be defined and written before the main function after the preprocessor statements. 29Example: #includecstdio.h> int maximum (int x,int y) { intz; ze(x>ey) 2x5 return (2); } main() f inta,b,c; scanf("%d%d" &a,&b); c-maximum(a,b); printf(“\n maximum number=%d",¢); } FUNCTION PROTOTYPE Teisa common practice that all the function programs are written after the main() function. When they are accessed in the main program, an error of prototype function is shown by the compiler. It means the computer has no reference about the programmer defined functions, as they are accessed before the definition To overcome this, i.e to make the compiler aware that the declarations of the function referred at the calling point follow, a declaration is done in the beginning of the program immediately after the preprocessor statements, Such a declaration of function is called prototype declaration and the corresponding functions are called function prototypes. Example 1: #includecstdio.h> int maximum(int x,int y); main() { intabic; scanf(“%d%d” 8&a,&b); c=maximum(a,b); printf(“\n maximum number is : %d",c); } int maximum(int x, int y) { int 2; 302(x>=y) 2x :y; return(z); J Example 2: #includecstdio.h> void int factorial(int m); main() C intn; scanf{"%d”,&n); factorial(n); J Void int factorial(int m) { Printf(“\n factorial of Md is %d “.m,p); return( ); J Note: In the prototype decleration of function, ifit return no value, in the place: Of data-type we use void, Eg: void maximum(int x,int ys Passing arguments to a function ‘he values are passed tothe function pireram through the arguments. When a Value is passed toa function 8an argumentin the calling Statement, the value is copied into the formal argument ofthe function (may have the same name of the a-eus] mnbtment ofthe calling function) This Procedure of passing the value ie called passing by value. Even 'fformal argument changes in the fanction program, the value ofthe actual argument does not change, Example: #includecstdio,hs Void square (int x); main() { intx; scanf(“%d”, 8x); square(x): 313 void square(int x) { xox printf(*\n the square is 90d".»)s return; 3 In his program the value of xin the program is unaltered. RECURSION It is the process of calling a function by itself, until some specified condition is satisfied. It is used for repetitive computation (like nding factorial of anumbe) in ‘which each action isstated in term of previous result Example: #include
Jong int factorial(int n): main() { int; Jongint ms scanf("4od” 8); mefactorial(n); printf(“\n factorial is 9d", m); 3 Jong int factorial(int m) { if(n<=l) return(1); else return(n'factorial(n-1)): } Inthe program when nis passed the function it repeatedly execures calling the same function form, n-1,7- oe A. 32Review Questions List out the advantages of function. List out the rules used in return statement ‘What is mean by call by reference & call by value. ‘What is the function and list out advantages and disadvantages of functions Whats the purpose of return statement What is the recursive function. List out their merits and demerits. Explain function with argument and return type. Explain recursion? Explain the difference between calling function and called function? Explain void function? State three advantages of function? What is call by value? What is function how function is defined. What is function? Whaat is recursion explain with suitable example. ‘What is the difference between call by value and call by reference ‘What is the purpose of the library function fflush()? ‘What is user defined functions and built-in functions. Enlist them. 33CHAPTER 7 STORAGE CLASS Earlier we mentioned that variables are characterized by their data type like integer, floating point type, character type etc. Another characteristic of variables or arrays is done by storage class. It refers to the permanence and scope of variables or arrays within a program. There are 4 different storage class specifications in C * automatic, © external, © static, and © register. They are identifiedby the key words auto, external, static, and register respectively. AUTOMATIC VARIABLES They are declared in a function. It is local and its scope is restricted to that function. They are called so because such variables are created inside a function and destroyed automatically when the function is exited. Any variable declared in a function is interpreted as an automatic variable unless specified otherwise. So the keyword auto is not required at the beginning of each declaration. EXTERNAL VARIABLE (GLOBAL VARIABLE) The variables which are alive and active throughout the entire program are called external variables. Itis not centered toa single function alone, but its scope extends to any function having its reference. The value of a global variable can be accessed in any program which uses it. For moving values forth and back between the functions, the variables and arrays are declared globally ie, before the main program. The keyword external is not necessary for such declaration, but they should be mentioned before the main program. STATIC VARIABLES Itis, like automatic variable, local to functions is which it is defined. Unlike automatic variables static variable retains values throughout the life of the program, ie. ifa function is exited and then re-entered at a later time the static variables defined within the function will retain their former values. Thus this feature of static variables allows functions to retain information permanently throughout the execution of the program. Static variable is declared by using the keyword static. Example: static float a; Static int x; Consider the function program: #includecstdio.h> long int Fibonacci (int count) main() 34{ int i, m=20; for (i=1 ;i< m; ++i) printf( “Q6ld\t",fibonacci(i)); 3 Jong int Fibonacci (int) count ) { static long int fl=1, f2=1 ; long int f; f= (count <3)?1:f1+£2; Q=fl fl=f; return (f);} In this program during the first entry to the function fl and {2 are assigned 1, later they are replaced by successive values of fl and fas 1 and {2 are declared static storage class. When the function is exited the latest values stored infl and £2 will be retained and used when the function is re-entered. Review Questions pen ane Yn FS 12. How are the data elements initialized in the case of static type variable How can data be initialized in the automatic variable ‘What is mean by register variable and what the scope of it? What is the automatic variable and what is the use of it. “What is the storage class used in recursive function What is the use of external data type in C Differentiate between local variable and global variable? Explain Automatic storage class specifier Explain Extern storage class Explain Register storage class. Explain Static storage classs Explain the various storage classes in C. How static variable are define and initialized? What are register variables? What are the advantage of using register variables? ‘What is mean by storage class of variable? 35CHAPTER 8 ARRAYS ARRAYS An array is an identifier to store a set of data with common name. Note that a variable can store onlya single data. Arrays may be one dimensional or multi dimensional. Defining an array one dimensional arrays Definition: Arrays are defined like the variables with an exception that each array name must be accompanied by the size (ie. the max number of data it can store).For a one dimensional array the size s specified in a square bracket immediately after the name of the array. The syntax is data-type array name(size); So far, we've been declaring simple variables: the declaration inti; declares a single variable, named i, of type int. It is also possible to declare an array of several elements, The declaration inta{10); declares an array, named a, consisting of ten elements, each of type int. Simply speaking, an array isa variable that can hold more than one value. You specify which ofthe several values you're referring to at any given time by using a numeric subscript. (Arrays in programming are similar to vectors or matrices in mathematics.) We can represent the array a above with a picture like this: eg: int x{100]; float mark(50}; char name(30}; Note: With the declaration int x{100].computer creates 100 memory cells with name MO)-«{1]2(2)......-.x{99] Here the same identifier x is used but various data are distinguished by the subscripts inside the square bracket. Array Initialization Although it is not possible to assign to all elements of an array at once using an assignment expression, it is possible to initialize some or all elements of an array when the array is defined. The syntax looks like this: int a[10] = {0, 1, 2,3, 4,5, 6, 7,8, 9}; The list of values, enclosed in braces {}, separated by commas, provides the initial values for successive elements of the array. {there are fewer intializers than elements inthe array, the remaining elements are automatically initialized to 0. For example, 36int a[10] = {0, 1, 2,3, 4, 5,6}; would initialize a[7} (8), and a[9} to. When an array definition includes an initializer, the array dimension ‘may be omitted, and the compiler will infer the dimension from che number of initialisers, For example, int b{] = (10, 11, 12, 13, 14}; Example : int x{ ] =(0,1,2,3,4,5}; or int x(6] (0,1,2,3,4,5}; Even ifthe size is not ‘mentioned (former case) the values 0,1,2,3,4 are stored in x(0).x{ 1}.x{2}x(3],x[4].xf5].(F the statement is like int x[3]-{0,1,2,3,4,5}; then. x{0).x[1],x{2] are assigned the values 0,1,2. Note: If the statement is like int x{6]=(0,1,2}; then the values are stored like x(0]=0, x{1]=1, x(2]=2, x{3}=0, x|4]=0 and x(5]=0, Processing one dimensional array 1) Reading arrays: For this normally we use for- loop. Tf we want to read n values to an array name called ‘mark’ the statements look like int mark{200},i,n; for(i= scanf(“%d”,&x{i)); Note: Here the size of array declared should be more than the number of values that. are intended to store. nj++i) 2) Storing array in another: To store an array toanother array. Suppose a and b are two arrays and we want to store that values of array a to array b, The statements look like, float a[100},b{100}; intl; for(i=1;i<=100;++i) bli}=ali); Problem: To find the average of a set of values. #includecstdio.h> main() C intx,i; float x{100],avg=0; 37printf(“\n the no: of values “); scanf(‘%d”,8n); prinef(‘\n Input the numbers’); for(i=1; { scanf(‘%of” Sofi); avg=avgtx{i}s } avgzavg/ni printf(“\n Average=%6f" avg); } PASSING ARRAYS TO FUNCTION Remember to passa value to a function we include the name ofthe variable asan argument of the function. Similarly an aray can be passed toa function by including army ‘name (without brackets) and size of the array as arguments. In the function defined the array name together with empty square brackets is an argument. =n;++i) Example: (calling function)-avg= average (n, x)s where nis the size of the data stored in the array x(]. (function defined)- float average (int n, float x{)s Now let us see to use a function program to calculate the average of aset of values. #includecstdio.h> float average(int n,float y{))s main() C intn; float x{100].avg: printf(“\n Input the no: of values"); scanf(“%d",&n); printf(‘\n Input the values”): for(i: scanf(“%6F" 8x{i)); avgeaverage(n.x)s jcens++i) print{("\n The average is %6f" ave): 38J float average(int n, float y(); { float sum=0; inti; for(i=l;ic=n;++i) sum=sum+yfi}; sum=sum/n; return(sum); J Note: #include
void arrange(int n float x{}); arrange(n,x); J arrange(int n,float x{}); { return; } Problem: Write a program to arrange a set of numbers in ascending order by using a function Program with global declaration, 39MULTI-DIMENSIONAL ARRAYS Multi-dimensional arrays are defined in the same manner one dimensional arrays except that aseparate pair of square brackets is required to each subscript. Example: float matrix{20][20] (two dimensional) Int x{10}[10]{5] (@-dimensional) Initiating a wo dimensional array we doas int x int x(3)[4)= ((1.2,3.4}5 5.6.7.8); {89,10,11,1233 NOTE: The size of the subscripts is not essential for initialization. For reading a two dimensional array we use two for-loop. Example: for(j=1j<=3it+i) scanf(“96F" 8A Li}E))s NOTE: If x{2][3] is a two dimensional array, the memory cells are identified with name 0} {013} x 01(2} x 10}. x(210) ana L112) ARRAYS AND STRINGS. [Astring is represented asa one dimensional array of character type. Example : char name(20}; Here name is an array that can store a string of size 20. If we want to store many strings(like many names oF places) two dimensional array isused. Suppose e want to store names of 25 persons, then declare name charname(25]{ J. Note that the second square racket is kept empty ifthe length of string snot specified. Ifthe declaration is char name{25}[30],25 names of maximum size: 30 can be stored. The various names are identified by name[0], name{1},name[2],. name{24). ‘These namesare read by the command. For( i+0; i<25,+4i) Scanf(“96{*\n]", name(i))s PROBLEM: Write a program to store the names and places of students in your class. 40Review Questions 1. 2, 3. 4. 5. 6. 7. 8. 9. 10. ll. 12. 13. 14, 15. 16. 17, 18. 19, 20. 21. 22. 23. Distinguish between character array and string array Explain applications of array Summarise the purpose of string h function, What isan array indexing explain with an example What is character array how it differs from other data ty pes. What is an array and how array variable differs from ordinary variable, Can an array be used as an argument to a function? Ifyes, explain with examples, Define array and how two-dimensional array is initialize? Explain one dimensional array with an example explain- a) strlen() b) streat() Explain any 4 string functions with suitable example? Explain any two string functions? Explain applications of array Explain the concepts of multidimensional arrays in‘C’ Lan, guage. Explain the functions ofthe following: (a)Strepy () (b)Strlen () (c)Streat () Explain Two dimensional array with an example For what purpose \0’is used in string operations explain with suitable example. In what ways does an array differ from an ordinary variable? What advantage is there in defining an array size in terms of symbolic constant rather than a fixed snteger constant? ‘What are the rules to declare one dimensional array? What are the rules used to declare a multi dimensional arrav What are the rules used to declare a one dimensional array ‘What are the rules used to declare a two dimensional array ‘What do you understand by multi dimensional arrays. What do you understand by strings? How do you declare astring? What isan array? Explain the features ofan array and their uses. ‘What is null string ? What is it’s length? 41CHAPTER 9 STRUCTURES AND UNIONS We know an array is used to store a collection of data of the same type. But if we want to deal with a collection of data of various type such as integer, string, float etc we use structures in C language. It is a rethod of packing data of different types. bisa convenient ‘ool for handling logically related data items of bio- data people comprising of name, place, date etc. salary details of staff comprising of name, pay da. hraete. Defining a structure In general itis defined with the syntax name struct as follows Struct structure_name { Data type variable]; Data type variable2; J For example Struct account { Intaccountno Char name(50}; Float balance; Jeustomer[20] Note : Here accountno, name and balance are called members of the structure Struct date { Intmonth; Intday; Intyears }dateofbirth; Inthese examples customer isa structure array of tyPe account and date of birth isa structural type of date, ‘Within a structure members’ can be structures. In the following example ‘of biodata structure date which is a structure is a member. For example struct date { 42Intday; Int month; Intyear; 3 Struct biodata { Name char(30}; Intage; Date birthdate; Jstaff[30]; Here staffis an array of structure of type biodata Note: we can declare other variables also of biodata type structure as follows. Struct biodata customer [20]; Struct biodata students ete Processing a structure “The members ofa structure are themselves not variable. They shuld be linked tothe structure variable to make them meaningful members. The linking is done by period .) If safi]is structure array then the details of first staff say stat[1] is got by stafi[1] name, staff[].age, staffl1},birthdate day, staff[1] birthdate.month, staff] birthdate vear we can assign name, age and birthdate of staff{1} by Staff[1].name="Jayachandran” stafil]}.age=26 stafi[!].birthdate.day=11 stafif1] birthdate.month=6 stafil1) birthdate.year=1980 Ifemployee' isa structure variable of type biodata as mentioned above then the details of ‘employee’ is got by declaring ‘employee as biodata type by the statement biodata employee; The details of employee are got by employee name, employee.age, employee-birthdate.year etc, Note: Structure initialisation Like any other variable or array a structure variable can also be initalised. by using syntax static Struct record { Char name(30]; Intages Int weight; 3 43Static struct record student]=f“rajan”, 18, 62} Here student! is of record structure and the name, age and weight are initialised as “rajan”, 18 and 62 respectively. 1. Write ac program to read biodata of students showing name, place, pin, phone and grade #includecstdio.h> main() { Struct biodata { Char name(30}; Char Place[40}] Intpin; Long Int phone; Char grade; k Struct biodata student{50}; Intn; Prinf(“\n no of students”); Scanf("%d".n); For(i= { Scanf{‘%s” student{i].name); Scanf(“%s" student{i).place); Scanf(‘%d" student{i.pin); Scanf{"9ld’ student{i].phone); Scanf{"%c"’student{i).grade); } } USER DEFINED DATA TYPE Thisis to define new data type equivalent to existing datatypes. Once defined a user-defined data type then new variables can be declared in terms ofthis new data type. For defining new data type we use the syntax typedef as follows Typedef type new-type Here type refers to existing data type ni++i) 44For example Example 1: ‘Typedef int integer; Now integer is a new type and using this type variable, array etc can be defined as Integer x; Integer mark(100]; Example 2: Typedef struct i Intaccno; Char name(30}; Float balance; record; Now record is structure type using this type declare customer, staffs record type Record customer; Record staff{100]; Passing structures to functions Mainly there are two methods by which structures can be transferced to and from a function. 1 . Transfer structure members individually 2.. Passing structures as pointers (ie by reference) Example 1 #includecstdio.h> Typedef struct { Int accno; Char name(30}; Float balance; Jrecord; main() { Record customer; 453 Float adjust(char name|], int accnumber, float bal) i Float x; Return(x); J Example 2 #includecstdio.h> Typedef struct { Intaccno; Char name{30}; Float balance; record; main() f Record customer; Void adjust(record “cust) Adjust(& customer); Printf("\n %s\t%f",coustomer.name,customer.balance) } Void adjust(record *cust) [ Float x; Cust->balance=... 46Im the first example structure members are passed individually where as in the second case customer is Passed entirely as a pointer named cust. The values of structure membersare accessed by using -> symbol like cust->name, cust->balance etc. UNIONS Union is a concept similar to a structure with the major difference in terms of storage. In the case of Structures each member has its own storage location, but a union may contain many members of different types but can handle only one ata time. Union is also defined as a structure is done bar using the syntax union, Union var f Intm; Charc; Float a; J Union var x; Now xisa union containing three members m.c.a But only one value can be stored eitherinx.m,xcorxa BITWISE OPEATIONS Bitwise operators operate on individual bits of integer (int and long) values. Thisis useful for writing low- level hardware or OS code where the ordinary abstractions of numbers, characters, pointers, and so on, are Biwise operators are: ~ Bitwise Negation one’s complement (unary) & Bitwise And | Bitwise Or \ Bitwise Exclusive Or > Right Shift by right hand side (RHS) (divide by power of 2) << __ Left Shift by RHS (multiply by power of 2) Definition of bitwise logical operators: Bita Bitb a&b ab arb [ “a 0 0 0 0 0 1 0 1 0 1 1 1 1 0 0 t 1 1 0 1 1 1 1 0 0 47Example: Birwise Negation a=00000011 ~a=11111100 BitwiseAnd a = 00000011 b = 00010110 a&b=00000010 Binwise 0 a = 00000011 b =00010110 alb=00010111 twise Exclus a = 00000011 b = 00010110 a%b=00010101 Review Questions Explain the salient features of typedef? How structure different from array What is the difference between structure declaration and structure initialization What is the structure and what are the uses of it. Differentiate structure and array Distinguish structure data type with other data type variables.» Explain array of structure with example Explain Nested structure with example. Explain pointer to structure. Explain the use of Typedef What are the similarities and difference between structure and union, “What is mean by member or field of structure weer avr ene BRES What is structure?explain with suitable example What is the advantage of UNION in C? What is union? Explain with example. ae 48CHAPTER 10 ALGORITHM ‘Analgorithm, named for the ninth century Persian Mathematician al-Khowarizmi, is simply aset of rules used to perform some calculations, either by hand or more usually on a machine. In this subject we will refer algorithm as a method that can be used by the computer for solution of a problem. For instance performing the addition, multiplication, division or subtraction is an algorithm. Use of algorithm for some computations is a common practice. Even ancient Greek has used an algorithm which is popularly known as Euclid’s algorithm for calculating the greatest common divisor of two numbers. Basically algorithm isa finites set of instructions that can be used to perform certain task. In this chapter we will learn some basic concepts of algorithm. And for understanding how to write an algorithm we will discuss some examples. ALGORITHM ‘An Algorithm sa set of rules for carrying out calculation either by hand or on a machine. An Algorithm is a sequence of unambiguous instructions for solving a problem, i.., for obtaining a required output for any legitimate input in a finite amount of time. Problem | Algorithm Input» Processor ——» Output Every algorithm must satisfy the following criteria Input : Zero or more quantities are externally supplied. Output Atleast one quantity is produced. Definiteness: Each instruction is clear and unambiguous. Finiteness _: If we trace out the instructions of an algorithm, then for all cases, the algorithm terminate after a finite number of steps. Effectiveness : Every instruction must be very basic so that it can be carried out, in principle, by a person using only pencil & paper. CHARACTERISTICS OF ALGORITHM * _ Itisnotdepended on programming language, machine. © Algorithm design isall about the mathematical theory behind the design of good programs. 49ISSUES OR STUDY OF ALGORITHM: * How to device or design an algorithm a creating and algorithm. * — Howto express an algorithm a definiteness. * How to analysis an algorithm a time and space complexity. © How to validate an algorithm a fitness. © Testing the algorithm a checking for error. Algorithm Analysis Framework Algorithm analysis framework involves finding out the time taken by a program and the memory space it requires to execute. It also determines how the input size of a program influences the running time of the program, COMPLEXITY OF ALGORITHM We can determine the efficiency of an algorithm by calculating its performance. The two factors that help us to determine the efficiency of an algorithm are: © Amount of time required by an algorithm to execute * Amount of space required by an algorithm to execute These are generally known as time complexity and space complexity of an algorithm. Time complexity 1. Time complexity of an algorithm is the amount of time required for it to execute. 2. The time taken by an algorithm is given as the sum of the compile time and the execution time. The compile time does not depend on the instance characteristics as a program once complied can be run many times without recompiling. So only the run time of the program matters while calculating time complexity and it is denoted by tp (instance characteristics). 3. Itis difficult to calculate the time complexity in terms of physically clocked time. For example in multi-user operating system, it depends on various factors such as: * System load © Number of programs running on the system ° Instruction set used * Speed ofthe hardware 4. The time complexity ofan algorithm is given in terms of frequency counts. Frequency count is the count that indicates the number of times the statement is executed. 5. The Time complexity of an algorithm is the amount of computer time required by an algorithm to run tocompletion. ~ The time T(P) taken by a program P is the sum of the compute time and run time. The compile time does not depend on the instant characteristics. The run time is denoted by Tp Tp(n)=Ca Add(n) + Cs Sub(n) +Cm Mul(n) + addition, subtraction... and soon. vhere Ca, Cm ..... denotes the time needed for an 50SPACE COMPLEXITY Space complexity of an algorithm is the amount of storage required for it to execute. The space required by an algorithm to execute is given as the sum of the followin, components: 1) A fixed part that is independent of the characteristics of inputs and outputs. This part includes instruction space (for example space for the code), space for simple variables and fixed size component variables and space for constants. 2) Avariable part that consists of the space needed by the component variables whose size is dependent ona particular problem instance being solved and the space needed by the referenced variable. Therefore to calculate the space complexity of an algorithm we have to consider two factors: © Constant characteristic ‘© Instance characteristic The following equation depicts the space requirement S(p) of an algorithm. Where S(p)=C+Sp * Cis the constant part and indicates the space required for inputs and cutputs which includes instructions, variables and identifiers. ‘* Sp defines the space required for an instance characteristic. This is a variable part whose space requirement depends on a particular problem. Measuring input size The time required to execute an algorithm depends on the input size of the algorithm. If the input size is longer, then the time taken to execute it is more. Therefore we can calculate the efficiency ofan algorithm asa function to which the input size is passed as a parameter. Sometimes to implement an algorithm we need prior information of the input size. Example when performing multiplication of two matrices we should know the order of these matrices, only then we can enter the elements of the matrices. Measuring running time The time measured for analyzing an algorithm is generally called as running time. For measuring the running time of an algorithm we consider the following: 1. First recognise the basic operation (the operation contributing the most to total run time) of an algorithm. 2. Identifying the basic operation of an algorithm is not that difficult. It is generally the most time consuming operation in the algorithm. Normally such operations are located in the inner loop of an algorithm. For example, the basic operation of sorting algorithms is to compare the elements and place them in appropriate position. 51The table gives an example of the concept of basic operation. Basic Operations for Input Size Problem statement Inputsize Basic operation Computing GCD (greatest Two numbers Division common divisor) of two numbers. Searching a key element List of n elements. Comparison of key elementwith fromthe listofn elements. | every element of the list. Performing matrix The two matrices with ‘Multiplication of the multiplication. ordernxn elements in the matrices. ‘Then calculate the total time taken by the basic operation using the following formula: T(n) = Cop Cin) ‘Where T(n) is the running time of basic operation Copis the time taken by the basic operation to execute C(n) is the number of time the operation needs to be executed Using this formula we can obtain the approximate computing time. Best case, worst case and average case analysis Best Case: If an algorithm takes the least amount of time to execute a specific set of input, then it is called best case time complexity. Worst Case: If an algorithm takes maximum amount of time to execute a specific set of input, then it is called the worst case time complexity. Average Case: Ifthe time complexity of an algorithm for certain sets of inputs is on an average same then such a time complexity is called average case time complexity. The average case time complexity is not the just the average of best case and worst case time complexities. Let us now consider the algorithm for sequential search and find its best, worst and average case time complexities. Algorithm for sequential search Algorithm Seq_search(H [0...n-1], key) f //Problem description: This algorithm searches the key elements for an /array H{0...n-1} sequentially. //Input: An array H [0...n-1] and search the key element 52//Output: Returns the index of H where the key elementis present forp=Oton-1 { if (H [p] = key) Algorithm tracing for sequential search algorithm 1. Let us consider n=4, H[ ] = {10, 14, 18, 20}, 2. key=14 for p=0to 4 -i do/ this loop iterates from p= to 4-1 3. _ if {H [0]=key} then/ the loop continues to iterate as H[0] is not the search element 4, return 1//finally the array retutns] which is the position of the key elemer t. Best case time complexity ‘The above searching algorithm searches the element key from the list of n elements of the array H [0...n- 1). Ifthe element key is present at the first location of the list (H {0. ..n-1}) then the time taken toexecute the algorithm is the least .The time complexity depends on the number of times the basic operation is executed. Thus we get the best case time complexity when the number of basic serations is minimum. If the element to be searched is found at the first position, then the basic operation is only one and the best case complexity is achieved. The following equation denotes the best case time complexity as: Chese =1 Worst case time complexity In the above searching algorithm if the search element key is present at the nth position (the last position) of the list then the basic operations and time required to execute the algorithm is more and thus it gives the ‘worst case time complexity. The following equation gives the worst case time complexity as: Cworst=n Average case time complexity The Average complexity gives information a2out an algorithm on specific input. For instance in the sequential search algorithm: Let the probability of getting successful search be P. The total number of elements in the list is n. If we find the first search element at the ith position then the probability of occurrence of the first search element is P/n for every ith element. 53(1 - P)is the probability of getting unsuccessful search. Therefore the average case time complexity Cavg(n) is given as: Cavg(n) = Probability of successful search + Probability of unsuccessful search Cavg(n)= Plan) +n(1-P) 2 ‘The above equation gives the general formula for computing average case time complexity. If the search is complete and the search element is not found, then P = 0 which means that there is no ‘successful search in such circumstances. Cavg(n) = 0(1 + n)/2 +n (1 +0) Cavg(n) =n From the above equation we can see that the average case time complexity Cavg(n) will be equal ton. Thus calculating average case time complexity depends on the probability of getting a successful search and the number of operations required to perform the search. Therefore calculating average case time complexity is difficult compared to calculating worst case and best case complexities. Methodologies for Analyzing Algorithms In the previous section you have studied the analysis framework, time and space complexities, and tradeoff in algorithms. We also discussed measuring input size, running time of an algorithm, and best, worst and average case analysis. In this section we will study the methodologies used for analyzing the algorithms. There are different methodologies for analyzing the algorithms. Following are some of the methodologies used for analyzing the algorithm: © Pseudocode © Random access machine model * Counting primitive operations © Analyzing recursive algorithms © Testing and measuring over a range of instances PSEUDOCODE Itisa compact and informal high level explanation of computer algorithms that uses the structural principles ofa programming language. It is meant for human reading rather than machine reading. Itexcludes some details from the algorithms which are not needed for human understanding such as variable declaration, system specific code and subroutines. The objective of using pseudocode is to make the programming language code easier for the human to understand. 54Pseudo-Code Conventions: 1. Comments begin with // and continue until the end of line. Blocks are indicated with matching braces {and}. An identifier begins with a letter. The data types of variables are not explicitly declared. BeoN Assignment of values to variables is done using the assignment statement.
=
; 5. There are two Boolean values TRUE and FALSE. a Logical Operators. AND, OR, NOT aRelational Operators <, <=,>, 6. The following looping statements are employed. For, while and repeat-until While Loop: While < condition >
;
; For Loop: For variable= value-1 to value-2
;
; J 55repeat-until: repeat
;
; until
7. Aconditional statement has the following forms. a If
{
:} a If
{
Else (
3} Switch statement: Switch
{ Case
:
; Case
:
; Default :
; 8. Inputand output are done using the instructions read & write. 9. There is only one type of procedure: Algorithm, the heading takes the form, Algorithm Name (Parameter lists) a Asan example, the following algorithm fields & returns the maximum of n’ given numbers: 1. algorithm Max(A,n) 2. / Kisanarray of sizen 3 { 564. Result = A[1); 5. fork=2tondo 6. if A[I] > Result then 7. Result :=A[I}; 8 return Result; 9 3 In this algorithm (named Max), A & n are procedure parameters. Result & I are Lucal variables. Pseudocode for selection sort Algorithm Selection sort (B) { forp=1ton-1 { min x= Bip] forj=m+lton f If B[q] < minx { ming=q min x= B(q] B[min q] = B [p] Bip]= minx i } } Counting primitive operations ‘While analyzing the algorithm we have to count the number of primitive operations that the algorithm executes. Examples of some of the primitive operations are as follows: © Callingamethod © Returninga value from a function * Performing some arithmetic operations like addition, subtraction etc. © Assigning a value toa variable 57© Comparing two variables © Reference tothe pointer © Indexing anarray Counting primitive operations describes how to count the maximum number of primitive operations an algorithm executes. Let us now consider the arrayMax algorithm which helps in finding the maximum number of primitive operations. Algorithm factorial(x) Mnput x /IR is the factorial of the given number x Fact(x) { Ifx=1 Return 1 Else Fe x’fact(x-1)// recursive function which stops when value of x =1 j Let us now trace the factorial algorithm Algorithm tracing for factorial algorithm Letx=5 Fact(5) { Ifx= 1// xis not equal to 1 so the else part gets executed Return] Else F= 5*fact(5-1)// recursive function which stops when value of x =1 //inally the algorithm returns 120 as the factorial of the number 5 J Analysis of factorial algorithm For analyzing this algorithm and computing the primitive operation we have to consider some operations that are repeated as they are enclosed in the body of the loop. First getting the value for x corresponds to one primitive operation. This step executes only once at the beginning of the algorithm and contributes one unit to the total count. In the function Fact(x), there are two primitive operations. © Tocheck if the value of xis 1 © Tomultiply xand Fact(x-1)‘The function recurs these two operations x number of times. Therefore it contributes 4 2x value to the total count. Hence the total number of primitive operations T(n) that the factorial algorithm executes is given in the following equation. T(n) = 142x Asymptotic Notations and Basic Efficiency Classes To choose the best algorithm we need to check the efficiency of each algorithm. Asymptotic notations describe different rate-of-growth relations between the defining function and the defined set of functions. The order of growth is not restricted by the asymptotic notations, and can also be expressed by basic efficiency classes having certain characteristics. Let us now discuss asymptotic notations of algorithms ASYMPTOTIC NOTATIONS Asymptotic notation within the limit deals with the behavior ofa function, i.. for sufficiently large values of its parameter. While analyzing the run time of an algorithm, it is simpler for us to get an approximate formula for the run-time. ‘The main characteristic of this approach is that we can neglect constant factors and give importance to the terms that are present in the expression (for T(n)) dominating the functions behavior whenever n becomes large. This allows dividing of un-time functions into broad efficiency classes. To give time complexity as “fastest possible”, “slowest possible” or “average time”, asymptotic notations are used in algorithms. Various notations such as &! (omega), T (theta), O (big 0) are known as asymptotic notations. Big Oh notation (O) “Ois the representation for big oh notation. It is the method of denoting the upper bound of the running time of an algorithm. Big Oh notation helps in calculating the longest amount of time taken for the completion of algorithm. O(g)=(f/ fis a non negative function ,there exists constants c2 & nO such that f(x) d” -2.g(n), ne"n0} ‘The graph of C h(n) and T(n) can be seen in the figure,As n becomes larger, the running time increases considerably. For example, consider T(n)=13n°+42n"+2nlogn+4n. Here as the value on n increases n° is. much larger than n?, nlogn and n. Hence it dominates the function T(n) and we can consider the running time to grow by the order of n3. Therefore it can be written as T(n)=O(n*). The value of n for T(n) and C h(n) will not be less than n0.Therefore values less than n0 are considered as not relevant. gum fimBig Oh Notation T(n) * O(h(n)) Example: 1. f(n)=10n°+5n2+17 10n°d” f(x) 10n*d” f(x) Cl=10 Cl.” {(x) forall ne” 1 =n0 F belongs to the class n? 2. f(n)=2n*+3n+79 2n3d” f(x) 2n?d” f(x) Cl=2 & c2=84 Cl.n*d” f(x) for all ne” 1 =n0 F belongs to the class n* Omega notation (©) ““Q” is the representation for omega notation. Omega notation represents the lower bound of the running time of an algorithm. This notation denotes the shortest amount of time that an algorithm takes. Q@)=(f/fis a non negative function there exists constants cl & nO such that cl.g(n) d” f(x), ne"n0} The giuph of Ch(n) and T(n) can be seen in the figure. pm cum maar 60Example: 1, f{n)= 10n°45n?+17 A(x) d” (104547) n? A(x) d” (82) n* ¢2=32 f(x) d” c2.n° for alll ne” 1 =n0 F belongs to the class n* 2. f(n)=2n%s3n479 f(x) d” (243479) n? f(x) 4” (84) n? 2-84 f(x) d” 2.n° for all ne” 1 =n0 F belongs to the class n? Theta notation ( r) The depiction for theta notation is “T. This notation depicts the running time between the upper bound and lower bound. O(g)={f/ fis a non negative function ,there exists constants cl,c2 & nO such that cl.g(n) d” f(x)” c2.g(n), ne’n0} The graph of Cl h(n), C2 h(n) and T(n) can be seen in the figure. fim =e1gony Example: 1. f(n)=10n%45n2417 10n*4” f(x) d” (104547) n* 10n*4” f(x) d” (32) n? Cl=10 & c2=32 C1.n°” f(x) d” c2.n? for all'ne” 1 =n0 F belongs to the class n? 612. f{n)=2n+3n+79 2n3d” f(x) d” (243+79) n? 2n°” f(x) d” (84) n? 3. a(n)= "an" Cl=2 & c2=84 C1.n'd” f(x) 4” c2.n* forall ne” 1 =n0 F belongs to the class n? O,1,..1ka>0 a belongs to the class n* 4. x(a) =5nlogn +n x belongs to the class nlogn 5. x(n)=2+1/n x belongs to the class 1 Practical Complexities We have previously analyzed that we can obtain a different order of growth by means of constant multiple (CinC'f{n)). We used different types of notations for these orders of growth. But we do not restrict the classification of order of growth to &!, Tand O. There are various efficiency classes and each class possesses certain characteristic which is shown in table Growth | Name ofthe Explanation Example Order | Efficiency Class 1 Constant Specifies that algorithm?s running | Scanning the elements of array time is not changed with increase in size of the input logn | Logarithmic For each iteration of algorithm a _ | Performing the operations of constant factor shortens the binary search problem's size a Linear ‘Algorithms that examine thelist _| Performing the operations of of size n. sequential search nlogn | n-log-n Divide and conqueralgorithms. | Using merge sort or quick sort elements are sorted | nd Quadratic ‘Algorithms with twoembedded | Scanning the elements of matrix loops 3 Cubic Algorithms with three Executing matrix embedded loops. _| Multiplication an Exponential Algorithms that generate allthe _| Generatingall the subsets which are present inn subsets of n different — element sets elements nt Factorial Algorithmsthat generate all the | All the permutationsare generated permutations ofan n-element set 62
You might also like
Hourglass Workout Program by Luisagiuliet 2
PDF
76% (21)
Hourglass Workout Program by Luisagiuliet 2
51 pages
12 Week Program: Summer Body Starts Now
PDF
87% (46)
12 Week Program: Summer Body Starts Now
70 pages
Read People Like A Book by Patrick King-Edited
PDF
57% (82)
Read People Like A Book by Patrick King-Edited
12 pages
Livingood, Blake - Livingood Daily Your 21-Day Guide To Experience Real Health
PDF
77% (13)
Livingood, Blake - Livingood Daily Your 21-Day Guide To Experience Real Health
260 pages
Cheat Code To The Universe
PDF
94% (79)
Cheat Code To The Universe
34 pages
Facial Gains Guide (001 081)
PDF
91% (45)
Facial Gains Guide (001 081)
81 pages
Curse of Strahd
PDF
95% (467)
Curse of Strahd
258 pages
The Psychiatric Interview - Daniel Carlat
PDF
91% (34)
The Psychiatric Interview - Daniel Carlat
473 pages
The Borax Conspiracy
PDF
91% (57)
The Borax Conspiracy
14 pages
TDA Birth Certificate Bond Instructions
PDF
97% (285)
TDA Birth Certificate Bond Instructions
4 pages
The Secret Language of Attraction
PDF
86% (108)
The Secret Language of Attraction
278 pages
How To Develop and Write A Grant Proposal
PDF
83% (542)
How To Develop and Write A Grant Proposal
17 pages
Penis Enlargement Secret
PDF
60% (124)
Penis Enlargement Secret
12 pages
Workbook For The Body Keeps The Score
PDF
89% (53)
Workbook For The Body Keeps The Score
111 pages
Donald Trump & Jeffrey Epstein Rape Lawsuit and Affidavits
PDF
83% (1016)
Donald Trump & Jeffrey Epstein Rape Lawsuit and Affidavits
13 pages
KamaSutra Positions
PDF
78% (69)
KamaSutra Positions
55 pages
7 Hermetic Principles
PDF
93% (30)
7 Hermetic Principles
3 pages
27 Feedback Mechanisms Pogil Key
PDF
77% (13)
27 Feedback Mechanisms Pogil Key
6 pages
Frank Hammond - List of Demons
PDF
92% (92)
Frank Hammond - List of Demons
3 pages
Phone Codes
PDF
79% (28)
Phone Codes
5 pages
36 Questions That Lead To Love
PDF
91% (35)
36 Questions That Lead To Love
3 pages
How 2 Setup Trust
PDF
97% (307)
How 2 Setup Trust
3 pages
The 36 Questions That Lead To Love - The New York Times
PDF
91% (35)
The 36 Questions That Lead To Love - The New York Times
3 pages
100 Questions To Ask Your Partner
PDF
78% (36)
100 Questions To Ask Your Partner
2 pages
Satanic Calendar
PDF
25% (56)
Satanic Calendar
4 pages
The 36 Questions That Lead To Love - The New York Times
PDF
95% (21)
The 36 Questions That Lead To Love - The New York Times
3 pages
Jeffrey Epstein39s Little Black Book Unredacted PDF
PDF
75% (12)
Jeffrey Epstein39s Little Black Book Unredacted PDF
95 pages
14 Easiest & Hardest Muscles To Build (Ranked With Solutions)
PDF
100% (8)
14 Easiest & Hardest Muscles To Build (Ranked With Solutions)
27 pages
1001 Songs
PDF
70% (73)
1001 Songs
1,798 pages
The 4 Hour Workweek, Expanded and Updated by Timothy Ferriss - Excerpt
PDF
23% (954)
The 4 Hour Workweek, Expanded and Updated by Timothy Ferriss - Excerpt
38 pages
Zodiac Sign & Their Most Common Addictions
PDF
63% (30)
Zodiac Sign & Their Most Common Addictions
9 pages
Rogramming for Problem Solving Using c Me Lecture Notes
PDF
No ratings yet
Rogramming for Problem Solving Using c Me Lecture Notes
118 pages
Wa0012.
PDF
No ratings yet
Wa0012.
23 pages
1 - Introduction to Computers and C++ Programming
PDF
No ratings yet
1 - Introduction to Computers and C++ Programming
33 pages
C Programming Notes
PDF
No ratings yet
C Programming Notes
117 pages
1-Introduction To Algorithms and C Programming
PDF
No ratings yet
1-Introduction To Algorithms and C Programming
50 pages
Unit 1
PDF
No ratings yet
Unit 1
34 pages
Chapter 1 - Introduction To Computers and C++ Programming: Outline
PDF
No ratings yet
Chapter 1 - Introduction To Computers and C++ Programming: Outline
12 pages
C Programing PDF Optimized Kumail
PDF
No ratings yet
C Programing PDF Optimized Kumail
52 pages
Chapter 1 3
PDF
No ratings yet
Chapter 1 3
44 pages
01 Introduction
PDF
No ratings yet
01 Introduction
59 pages
C slides
PDF
No ratings yet
C slides
411 pages
Fundamentals of Computer
PDF
No ratings yet
Fundamentals of Computer
14 pages
PSC-UNIT-1
PDF
No ratings yet
PSC-UNIT-1
61 pages
Topic1 Programming Concepts
PDF
No ratings yet
Topic1 Programming Concepts
70 pages
Lecture 2 & 3 - Basic C++ Structure
PDF
No ratings yet
Lecture 2 & 3 - Basic C++ Structure
52 pages
Roderick M Nuttall C Kenny N Expert Proficiency Coursebook PDF
PDF
No ratings yet
Roderick M Nuttall C Kenny N Expert Proficiency Coursebook PDF
209 pages
Lab No: 1 Date: Introduction To Computers and Programming Ide Objectives
PDF
No ratings yet
Lab No: 1 Date: Introduction To Computers and Programming Ide Objectives
45 pages
c-lecture-notes-2023
PDF
No ratings yet
c-lecture-notes-2023
49 pages
CSCE 1001 Chapter 1
PDF
No ratings yet
CSCE 1001 Chapter 1
61 pages
Name: Dr. Gufran Ahmad Ansari
PDF
No ratings yet
Name: Dr. Gufran Ahmad Ansari
37 pages
Programming With C and Lab
PDF
No ratings yet
Programming With C and Lab
199 pages
Lecture 1
PDF
No ratings yet
Lecture 1
37 pages
LP1 - Unit 1 - OVERVIEW OF COMPUTES, ALGORITHM, AND PROGRAM DESIGN
PDF
No ratings yet
LP1 - Unit 1 - OVERVIEW OF COMPUTES, ALGORITHM, AND PROGRAM DESIGN
14 pages
Lecture 1
PDF
No ratings yet
Lecture 1
57 pages
CENG103 Week1 LN
PDF
No ratings yet
CENG103 Week1 LN
31 pages
Lecture 01 - Introduction
PDF
No ratings yet
Lecture 01 - Introduction
64 pages
Programming With C
PDF
No ratings yet
Programming With C
199 pages
C++ Programming
PDF
No ratings yet
C++ Programming
35 pages
C++Lecture 1 Intro To Computers
PDF
No ratings yet
C++Lecture 1 Intro To Computers
32 pages
Programming With C++ Chapter01-2
PDF
No ratings yet
Programming With C++ Chapter01-2
68 pages
Lec 1-1
PDF
No ratings yet
Lec 1-1
65 pages
PPS Notes by IT Department Gtu
PDF
No ratings yet
PPS Notes by IT Department Gtu
425 pages
CS-303 Theorical Concepts
PDF
No ratings yet
CS-303 Theorical Concepts
36 pages
Introduction To Computer Programming
PDF
No ratings yet
Introduction To Computer Programming
38 pages
CMP 201 Computer Programming I
PDF
No ratings yet
CMP 201 Computer Programming I
82 pages
Lec 01 Introduction
PDF
No ratings yet
Lec 01 Introduction
36 pages
PPS unit-1
PDF
No ratings yet
PPS unit-1
44 pages
Notes of UNIT1,2
PDF
No ratings yet
Notes of UNIT1,2
70 pages
Topic1 Programming Concepts
PDF
No ratings yet
Topic1 Programming Concepts
62 pages
Unit-I PPS
PDF
No ratings yet
Unit-I PPS
89 pages
Lecture 1
PDF
No ratings yet
Lecture 1
25 pages
1 EPT 162 Introduction
PDF
No ratings yet
1 EPT 162 Introduction
12 pages
Untitled Document 4
PDF
No ratings yet
Untitled Document 4
17 pages
CP 5 Units Notes 2017
PDF
No ratings yet
CP 5 Units Notes 2017
93 pages
C PROgRAMINg 2
PDF
No ratings yet
C PROgRAMINg 2
84 pages
1 Week 1 Full
PDF
No ratings yet
1 Week 1 Full
40 pages
Programming Fundamentals Lec 1,2.3
PDF
No ratings yet
Programming Fundamentals Lec 1,2.3
34 pages
Introduction To Computers
PDF
No ratings yet
Introduction To Computers
71 pages
comprog-reviewer
PDF
No ratings yet
comprog-reviewer
3 pages
Chapter 1 Part 1
PDF
No ratings yet
Chapter 1 Part 1
34 pages
Pps
PDF
No ratings yet
Pps
93 pages
C Programming
PDF
No ratings yet
C Programming
71 pages
C Programming LECTURE August 19 2019 NEW 1A
PDF
No ratings yet
C Programming LECTURE August 19 2019 NEW 1A
18 pages
Class 1
PDF
No ratings yet
Class 1
39 pages
Programming Lecture 1
PDF
No ratings yet
Programming Lecture 1
27 pages
Unit 1 PIC
PDF
No ratings yet
Unit 1 PIC
35 pages
Programming - Lectures - 01 - Section B
PDF
No ratings yet
Programming - Lectures - 01 - Section B
42 pages
Programmin Fundamentals Weak 1 and 2
PDF
No ratings yet
Programmin Fundamentals Weak 1 and 2
86 pages
MOD IT2 c1 3
PDF
No ratings yet
MOD IT2 c1 3
22 pages