PROGRAMING IN C PDF

adminComment(0)

C is a general-purpose, procedural, imperative computer programming language developed in by Dennis M. Ritchie at the Bell Telephone Laboratories to. Lecture monolithic vs modular programming, Storage classes. Lecture titles : The original was still called Programming in C, and the title that covered. adirknesmala.gq J2P and P2J Ver 1 J2P and P2J Ver 1 . This book is a tutorial for the computer programming language C. Unlike.


Programing In C Pdf

Author:SETSUKO FULWOOD
Language:English, Indonesian, French
Country:New Zealand
Genre:Fiction & Literature
Pages:105
Published (Last):21.04.2016
ISBN:343-4-70498-872-6
ePub File Size:22.75 MB
PDF File Size:11.79 MB
Distribution:Free* [*Registration Required]
Downloads:24019
Uploaded by: MARQUETTA

PDF Drive is your search engine for PDF files. As of today we This book is a tutorial for the computer programming language C. Unlike BASIC or. Pascal, C. The first chapter deals with the fundamental concepts of C language. The second chapter focuses on introduction C programming. The third chapter provides. C Language Overview .. 1 C Program Structure . 5 Compile & Execute C Program .

Operators, functions, constants and variables are combined together to form expressions…. If the condition is false, then, else part statements are executed. In C programming, there are 3 types of decision making control statements in C language. Control comes out of the loop statements once the condition becomes false. There are 3 types of loop control statements in C language. There are 4 types of case control statements in C programming.

They are 1 switch 2 break 3 continue 4 goto…. There are two types of qualifiers available in C programming. They are 1 const 2 volatile.

Constants are also like normal variables…. There are 4 storage class specifiers available in C language. You can store group of data of the same data type in an array. There are 2 types of arrays in C programming. They are 1 One dimensional array 2 Multidimensional array…. This null character indicates the end of the string. In C programming, strings are always enclosed by double quotes. The variable might be any of the data types such as int, float, char, double, short etc.

Normal variable stores the value, whereas pointer variable stores the address of the variable…. All C programs are written using functions to improve re-usability, understandability and to keep track of them. A large C program is divided into basic building blocks called C function. Each library function in C programming language performs a specific operation. We can make use of these library functions to get the pre-defined output instead of writing our own code to get those outputs….

They are 1. In real time application, it will happen to pass arguments to the main program itself. These arguments are passed to the main function while executing binary file from command line…. In C89 standard, fixed arguments only can be passed to the functions.

When a function gets the number of arguments that changes at run time, we can go for a variable length arguments. It is denoted as … 3 dots …. Example program for abs , floor , round , ceil , sqrt , exp , log , sin , cos , tan , pow and trunc functions are…. C — Int, char validation functions: There are many inbuilt functions in C language which are used to validate the data type of given variable and to convert upper to lower case and lower to upper case are given below with description….

C — Buffer manipulation function: Buffer manipulation functions in C programming work on the address of the memory block rather than the values inside the address. C — Time related functions: Time functions in C are used to interact with system time routine and formatted time outputs are displayed. Example programs for the time functions are…. Character constants have integer values that are determined by the computers particular character set.

Thus, the value of a character constant may vary from one computer to another. The constants themselves, however, are independent of the character set. This feature eliminates the dependence of a C program on a particular character set. American Standard Code for Information Interchange character set, in which each individual character 7. Several character constant and their corresponding values, as defined by ASCII character set are shown below: String Constants: A string consists of any number of consecutive characters including none , enclosed in double quotation marks.

Several string constants are shown below: Washinton, D. This character is not visible when the string is displayed.

A character constant e. A and the corresponding single-character string constant A are not equivalent. A variable is an identifier that is used to represent some specified type of information within a designated portion of the program.

In its simplest form, a variable is an identifier that is used to represent a single data item, i. The data item must be assigned to the variable at some point in the program. A given variable can be assigned different data items at various places within the program. Thus, the information represented by the variable can change during the execution of the program. However, the data type associated with the variable are not change.

A C program contains the following lines: Thus, a, b and c will each represent an integer-valued quantity, and d will represent a single character.

The type declaration will apply throughout the program. The next four lines cause the following things to happen: The character a is assigned then assigned to d. In the third line within this group, the values of the variables a and b are accessed simply by writing the variables on the right-hand side of the equal sign.

The last four lines redefine the values assigned to the variables as the integer quantity 4 is assigned to a, replacing the earlier value, 3; then 2 is assigned to b, replacing the earlier value, 5; The difference between a and b i. Finally the character w is assigned to d, replacing the earlier character, a. Declarations A declaration associates a group of variables with a specific data type. All variables. A declaration consists of a data type, followed by one or more variable names, ending with a semicolon.

Each array variable must be followed by a pair of square brackets, containing a positive integer which specifies the size i. Square brackets enclosing the size specification for text. These declarations could also have been written as follows: A C program contains the following type declarations: A C program contains the following type declarations float c1, c2, c3 ; double root1, root2 ; also written as long float root1, root2 ;.

A C program contains the following type declarations. The first 10 th. In such situations, it is important, however, that the size be specified correctly. If the size is too small, eg. If the size is too large e. The array is another kind of variable that is used extensively in C. An array is an identifier that refers to collection of data items that have the same name. The data items must all be of the same type e.

The individual data items are represented by their corresponding array element i. The individual array elements distinguished from one another by the value that is assigned to a subscript. An escape sequence always begins with a backslash and is followed by one or more special characters. For example, a linefeed LF , which is. Such escape sequences always represent single characters, even though they are written in terms of two or more characters. The commonly used escape sequences are listed below: Preprocessors Directives: The C preprocessor is a collection of special statements, called directives, that are executed at the beginning of compilation process.

Preprocessors directives usually appear at the beginning of a program. A preprocessor directive may appear anywhere within a program.

Preprocessor directives follow special syntax rules that are different from the normal C syntax. They all begin with the symbol in column one and do not require a semicolon at the end. We have already used the directives define and include to a limited extent. A set of commonly used preprocessor directives and their functions are listed below: Directives define. Functions Defines a macro substitution Er. Computer Programming in C undef include ifdef endif ifndef if else.

Undefines a macro Species the files to be included Test for a macro definition Specifies the end of if Tests whether a macro is not defined Tests a compile-time condition Specifies alternatives when if test fails.

These directives can be divided into three categories: Macro substitution directives 2. File inclusion directives 3. Compiler control directives Macro substitution directives: Macro substitution is a process where an identifier in a program is replaced by a predefined string composed of one or more tokens.

The general format define identifier string define PI 3. In order find files based switch or on or off particular line or groups of lines in a program, we use conditional compilation.

For that, we use following preprocessor directives such as ifdef, endif, ifndef, if. C supports a feature known as type definition that allows users to define an identifier that would represent an existing data type. The user-defined data type identifier can later be used to declare variables.

It takes the general form: The existing data type may belong to any class of type, including the user defined. The new type is new only in name, but not the data type.

Some examples of type definition are: They can be later used to declare variables as follows: The main advantage of typedef is that we can create meaningful data type names for increasing the readability of the program. A symbolic constant is a name that substitutes for a sequence of characters. The characters may represent numeric constant, a character constant or a string constant. Thus, a symbolic constant allows a name to appear in place of a numeric constant, a character constant or a string.

When a program is compiled, each occurrence of a symbolic constant is replaced by its corresponding character sequence. Symbolic constants are usually defined at the beginning of a program. The symbolic constants may then appear later in the program in place of the numeric constants, character constant, etc that the symbolic constants represent. A symbolic constant is defined by writing define name text where name represents a symbolic name, typically written in uppercase letters, and text represents the sequence of characters that is associated with the symbolic name.

It doesnt require semicolon. What do you mean by Character set in C? What are constants and variables? Describe its types. PU What is Symbolic constant, differentiate between keywords and identifier. Describe different data types are used in c-program. What is Escape Sequence? Write any four escape sequence with meaning and symbols 6. What do you mean by a variable and a constant? List out any three-escape sequence with their uses.

PU 7. Define variables and constant. What are the token of C language? C includes a number of operators which fall into several different categories such as arithmetic operators, unary operators, rational and logical operators, assignment operators and the conditional operators, bitwise operator.

The data items that operators act upon are called operands. Some operators require two operands, while other act upon only one operand. Most operators allow the individual operands to be expressions.

A few operators permit only single variable as operand. There are five arithmetic operators in C. Purposes Addition Subtraction Multiplication Division remainder after integer division also called modulus operator. There is no exponential operator in C. However, there is a library function pow to carry out exponential. The operands acted upon by arithmetic operators must represent numeric values.

Division of one integer quantity by another is referred to as integer division. The operation always result in a truncated quotient i. On the other hand, if a division operation is carried out with two floating-point numbers, or one floating point numbers and other integer, the result will be a floating point.

Precedence of an operator in C is defined as the order of evaluation. The operators are. Operations with a high precedence are Er. Computer Programming in C carried out before operation having a lower precedence. The natural order of evaluation can be altered using parenthesis. The order, in which consecutive operations within the same precedence group are carried out, is known as associativity.

Within each of the precedence groups described above, the associativity is left to right. In other word, consecutive addition and subtraction operations are carried out from left to right, as are consecutive multiplication, division and remainder operations.

Determine the hierarchy of operations and evaluate the following expressions, assuming that i is an integer variables: Relational and Logical Operators: Relational Operators are those that are used to compare two similar operands, and depending on their relation take some actions.

These operators all fall within the same precedence group, which is lower than the arithmetic and unary operators. The associativity of these operators is left to right. Suppose that i, j and k are integer variables whose values are 1, 2 and 3 respectively. Several relational expressions involving these variables: In addition to the relational and equality operators, C also includes the unary operator!

This operator is referred to as the logical negative or logical not operator. Logical operators: C contains three logical operators: The result of a logic and operation will be true only if both operands are true where as the result of a logic or operation will be true if either operand is true or if both operands are true. In other word, the result of a logic or operation will be false only if both operands are false.

Suppose that i is an integer variable whose value is 7, f is a floating-point variable whose value is 5. Several complex logical expressions that make use of these variables are shown below: Assignment Operators: There are several different assignment operators in C. All of them are used to form assignment expressions which assign the value of an expression to an identifier. The assignment operator is used to assign a value to an identifier, where as the equality operator is used to determine if two expressions have the same value.

These operators cannot be used in place of one another. Assignment expressions are often referred as assignment statements. In such situation, the assignments are carried out from right to left. C contains the following five additional assignment operators: They are also known as shorthand assignment operators.

Most Beginner Friendly Tutorials for Programmers

The use of shorthand assignment operator has three advantages: What appears on the left-hand side need not be repeated and therefore it becomes easier to write. The statement is more concise and easier to read. The statement is more efficient. Unary Operators: C includes a class of operators that act upon a single operand to produce a new value, Such operators known as unary operators.

C Language Books

Unary operators usually precede their single operands, though some unary operators are written after their operands. The common use unary operators in C are: Decrement Operator - 3. Unary minus - 4. The operand used with each of these operators must be a single variable. The increment or decrement operators can each be utilized two different ways, depending on whether the operator is written before or after. If the operator is written before the operand then it is called as prefix unary operator.

If the operator is written after the operand, then it is called as postfix unary operator. When prefix is used, the operand will be altered in value before it is utilized for its intended purpose within the program. Similarly, when postfix is used, the operand will be altered in value after it is utilized. The most common use unary operator is unary minus, where a numeric constant, variable expression is preced by a minus sign.

Unary minus is distinctly difference from the arithmetic operator which denotes subtraction -. The subtractor operator requires two separate operands. Several examples of unary minus are -0x7fff A C program includes an integer variable i whose initial value is 1.

Suppose the program includes the following three printf statements. The precedence of unary increment or decrement or unary minus or plus is same and associativity is right to left. Bitwise Operators: Bitwise Operators are used for manipulating data at bit level.

These operators are used for testing the bits, or shifting them right or left. Bitwise operators can be applied only to integer type signed or unsigned and not to float or double.

They are Er. Comma Operator: The comma operator can be used to link the related expression together. A comma linked list of expression are evaluated left to right and the value of right-most expression is the value of combined expression. For example, Downloaded from www. Size of Operator: The size of operator is used with an operand to return the number of bytes it occupies.

It is a compile time operand. The operand may be a variable, a constant or a data type qualifier. The associativity of size of right to left. For e. Suppose that i is an integer variable, x is a floating-point variable, d is double-precision variable and c is character type variable.

The statements: The operator?: Simple conditional operations can be carried out with conditional operator. An expression that make use of the conditional operator is called a conditional expression. Such an expression can be written in place of traditional ifelse statement. A conditional expression is written in the form: Computer Programming in C expression1?

If expression1 is true, the value of expression2 is the value of conditional expression. If expression1 is false, the value of expression3 is the value of conditional expression. For example: Rightshift Less than Less than or equal to Greater than Greater than or equal to.

Navigation menu

Write the general form of ternary operator and explain with example. PU 2. What is a datatype? Write down the various types of it in C-program. PUBack 3. What are the various types of operators used in C language? Give a table that shows their precedence and associatively. PU 4.

Define the data types. Describe different data types. PUBack 5. Write a program to enter two numbers. Make the" comparison between them with conditional operator. If the first number is greater than second, perform multiplication otherwise division 6. What are operators? Describe unary, binary and ternary operators with examples. Chapter 5 Input and Output Operations A program is a set of instructions that takes some data and provides some data after execution.

The data that is given to a program is known as input data. Similarly, the data that is provided by a program is known as output data. Generally, input data is given to a program from a keyboard a standard input device or a file.

The program then proceeds the input data and the result is displayed on the screen monitor a standard output device or a file. Reading input data from keyboard and displaying the output data on screen, such input output system is considered as conio input out. When a program needs data, it takes the data through the input functions and sends the results to output devices through the output functions.

As keyboard is a standard input device, the input functions used to read data from keyboard are called standard input functions. The standard input functions are scanf , getchas , getch , gets , etc. Similarly, the output functions which are used to display the result on the screen are called standard output functions. The standard output functions are printf , putchas , putch , puts , etc.

The standard library stdio. The contents of the header file become part of the source code when it is compiled. Formatted functions ii. Unformatted functions. Formatted Functions: Formatted functions allow the input read from the keyboard or the output displayed on screen to be formatted according to our requirements.

The input function scanf and output. While displaying a certain data on screen, we can specify the number of digits after decimal point, number of spaces before the data, the position where the output is to be displayed, etc, using formatted functions.

Formatted Input: Formatted input refers to an input data that has been arranged in a particular format. For example, consider the following data. The first be read into a variable int, the second into float, and the third into char. This is possible in C using the scanf function. The input data can be entered into the computer from a standard input device keyboard by means of the C library function scanf.

This function can be used to enter any combination of numerical values, single characters and strings. The function returns the number of data items that have been entered successfully. The general syntax of scanf function is scanf control string, arg1, arg2, , argn where, control string refers to a string containing certain required formatting information so also known as format string and arg1, arg2, , argn are arguments that represent the individual input data items.

Actually, the arguments represent pointers that indicate the addresses of the data items within the computers memory. The control string consists of individual groups of characters, with one character group for each input data item. In its simplest form, a single character group will consist of the percentage sign, followed by a conversion character which indicates the types of corresponding data item.

Within the control string, multiple character groups can be contiguous, or they can be separated by whitespace i. If whitespace characters are used to separate multiple character groups in the control string, then all consecutive white-space characters in the input data will be read but ignored. The use of blank spaces as character group separators is very common. Several of the more frequently used conversion characters are listed below:.

Meanings Data item is a single character Data item is a decimal integer Data item is a floating-point value Data item is a floating-point value Data item is a floating point value. Conversion Charater Table Example: Different methods for entering the inputs: If the string were written as Eastern College of Engineering then only the single letter E would be assigned to line.

Since the first lowercase letter in this case a would be interpreted as the first character beyond the string. If the character within the brackets is simply the circumflex followed by a newline character, then string entered from the standard input device can contain any ASCII characters except the newline characters line feed.

Thus, the user may enter whatever he or she wishes and then presses the Enter Key. The Enter Key will issue the newline character, thus signifying the end of the string. The consecutive nonwhitespace characters that define a field. It is possible to limit the number of such characters by specifying a maximum field width for that data item. The data item may contain fewer characters than the specified filed width.

However, the number of characters in the actual data item cannot exceed the specified field width. Any characters that extend beyond the specified filed width will not be read. Such leftover characters may be incorrectly interpreted as the components of the next data item. The second will be assigned to a long decimal integer variable, and the third will be assigned to a double precision variable.

The control string in the second scanf function indicates that the first data item will have a maximum field width of 3 characters and it will be assigned to short octal integer variable, the second data item will have a maximum field width of 7 characters and it will be assigned to a long hexadecimal integer variable, and the third data item will have a maximum field width of 15 characters and it will be assigned to double precision variable.

In most version of C, it is possible to skip over a data item, without assigning it to the designated variable or array. This feature is referred to as assignment suppression. However will not be assigned partno because of asterisk, which is interpreted as an assignment suppression character. Formatted Output: Formatted output refers to the output of data that has been arranged in a particular format.

The printf is a built-in function which is used to output data from the computer onto a standard output device i. The printf statement provides certain features that can be used to control the alignment and spacing of print-outs on the terminals.

The general form of printf statement is printf control string, arg1, arg2,. The arguments can be written as constants, single variable or array names, or more complex expressions. Function references may also be included. In contrast to scanf function, the arguments in a printf function do not represent memory addresses and therefore are not preceded by ampersands. An individual character group in control string will consist of the percent sign, followed by a conversion character indicating the type of the corresponding data item.

Multiple character group can be contiguous, or they can be separated by other characters, including whitespace character. These other characters are simply transferred directly to the output device, where they are displayed. The use of blank spaces are character group separators is particularly common.

Meaning Data item is displayed as a single data Data it Data item is displayed as floating point value with an exponent em is displayed as a signed decimal Data item is displayed as floating point without an exponent Data item is displayed as floating point value using either e-type or f-type conversion Data item is displayed as a signed decimal integer Data item is displayed as an octal integer w Data item is displayed as a string ithout a leading zero Data item is displayed as an unsigned decimal integer Data item is displayed as a hexadecimal integer without the leading 0x.

Conversion Charater Table Note: So, the output generated will be fastener Control string: The general syntax of control string: Flags [Optional] T he flag affect the appearance of the output. They must be placed immediately after the percent sign. Data item is left justified within the field. The blank spaces required to fill the. Without this flag, only negative data items are precededby a sign.

Causes leading zeros to appear instead of leading blanks. Applies only to data items that are right justified within a field whose minimum size is larger than the data item: A blank space will precede each positive signed numeric data item. Field Width [Optional] The field width is an integer specifying the minimum output field width. If the number of characters in the corresponding data item is less than the specified field width then the data item will be preceded by enough leading blanks to fill the specified field.

If the number of characters in the data item exceeds the specified field width, then additional space will be allocated to the data item so that the entire data item will be displayed. Precision [Optional] The operation of precision field depends on the types of conversion. It must start with a period. Format for Integer Output: Computer Programming in C where w is the integer number specifying the minimum field width of output data.

If the length of the variable is less than the specified field width, then the variable is right justified with leading blanks. Format for floating point output: The general form: Computer Programming in C Output of Strings: Unformatted Functions: Unformatted functions do not allow the user to read or display data in desired format.

These library functions basically deal with a single character or a string of characters. The functons getchar , putchse , gets , puts , getch , getche , putch are considered as unformatted functions.

The getchar function reads a character from a standard input device. The putchar function displays a character to the standard output device. Enter gender M or F: M Our gender is: M Note: The functions getch and getche reads a single character the instant it is typed without waiting for the enter key to be hit.

The difference between them is that getch reads the character typed without echoing it on the screen, while getche reads the character and echoes displays it on the screen. The general syntax of getch: Second character: However, using getche function, we can see what we have typed. In both cases, input accepted as soon as the character typed. The last getch simply takes a character but doesnot store it anywhere. So, its work is merely to hold the output screen until a key is pressed.

The gets function is used to read a string of text containing whitespaces, until a newline character is encountered. It offers an alternative function of scanf function for reading strings. Unlike scanf function, it doesnot skip whitespaces. Write short noteson: PU 5. Distinguish between getc a getchar. PU 6. Write the various input unformatted function and describe any two. Write the various output unformatted function and describe any two. Chapter 6 Control Statements The statements which alter the flow of execution of the program are known as control statements.

In the absence of control statements, the instruction or statements are executed in the same order in which they appear in the program. Sometimes, we may want to execute some statements several times. Sometime we want to use a condition for executing only a part of program. So, control statements enable use to specify the order in which various instruction in the program are to be executed.

There are two types of control statements: Loops Loops are used when we want to execute a part of program or block of statement several times. So, a loop may be defined as a block of statements which are repeatedly executed for a certain number of times or until a particular condition is satisfied. There are three types of loop statements in C: For 2.

While 3. The control statement in loop decides whether the body is to be executed or not.

For Loop: For loops is useful to execute a statement for a number of times. When the number of repetitions is known in advance, the use of this loop will be more efficient.

Thus, this loop is also known as determinate or definite loop. Flowchart of For Loop: Print" Enter a number whose factorial is to be calculated. Read num. Initilize fact to 1 and counter i to1 5. Print fact as factorial of the number num. While Loop: After the execution, again the condition is checked and if it is found to be true then again the statements in the body of loop are executed. This means that these statements are executed continuously till the condition is true and when it becomes false, the loop terminates and the control comes out of the loop.

Each execution of the loop body is known as iteration. Body of Loop Next statement out of loop fig: Enter the number: The do The body of this loop may contain a single statement or a block of statements. The general syntax is:.

If the condition is true, then again the loop body is executed and this process continues until the condition becomes false. Unlike while loop, here a semicolon is placed after the condition. In a while loop, first the condition is evaluated and then the statements are executed whereas in do while loop, first the statements are executed and then the condition is evaluated.

So, if initially the condition is false the while loop will not execute at all, whereas the do while loop will always execute at least once. Differences between while loop and do while loop: The body of the loop may not be executed at all if the condition is not satisfied at the very first attempt. Nesting of loops: When a loop is written inside the body of another loop, then it is known as nesting of loops.

Any type of loop can be nested inside any other type of loop. For example, a for loop may be nested inside another for loop or inside a while or do Similarly, while and do while loops can be nested. Decisions Since decision making statements control the flow of execution, they also fall under the category of control statements. Following are decision making statements: The if statement is a powerful decision making statement and is used to control the flow of execution of statements. This is a bi-directional condition control statements.

This statement is used to test a condition and take one of two possible actions, If the condition is true then a single statement or a block of statements is executed one part of the program , other wise another single statement or a block of statements is executed other part of the program. In C, any non-zero value is regarded as true while zero is regarded as false. Flowchart of if control statement Here if the condition is true non-zero then statement1 is executed, and if it is false zero , then the next statement which is immediately after the if control statement is executed.

For eg: The if.. It is used when there are two possible actions one when a condition is true and the other when it is false. The syntax is: Flowchart of if After this the control transfers to the next statement which is immediately after the if Enter a number: Nested if We can have another if This is called nested if..

C Tutorial

This is a type of nesting in which there is an if This type of nesting is frequently used in programs and is also known as else if ladder.

This is a multi-directional conditional control statement. Sometimes, there is a need in program to make choice among number of alternatives. For making this choice, we use the switch statement. The expression following the switch keyword can be any C expression that yields an integer value or a character value. It can be value of any integer or character variable, or a function call returning on integer, or an arithmetic, logical, relational, bitwise expression yielding integer value.

The constants following the case keywords should be of integer or character type. These constants must be different from each other.

The statements under case can be any valid C statements like if Writing a switch statement inside another is called nesting of switches. Firstly, the switch expression is evaluated then value of this expression is compared one by one with every case constant.

If the value of expression matches with any case constant, then all statements under that particular case are executed. If none of the case constant matches with the value of the expression then the block of statements under default is executed. Out of switch fig: Computer Programming in C case 2: Enter your choice: The statements of case 3 and default are also executed in addition to the statements of case2.

This is known as falling through cases. Suppose we dont want the control to fall through the statements of all the cases under the matching case, then we can use break statement. Break statement: Break statement is used inside lops and switch statements.

Sometimes it becomes necessary to come out of the loop even before the loop condition becomes false. In such a situation, break statement is used to terminate the loop. This statement causes an immediate exit from that loop in which this statement appears. It can be written as i. The continue statement is used to bypass the remainder of the current pass through a loop.

The loop does not terminate when a continue statement is encountered. Instead the remaining loop statements are skipped and the computation proceeds directly to the next pass through the loop. The general syntax: The goto statement is used to alter the normal sequence of program execution by unconditionally transferring control to some other part of the program. The goto statement transfers the control to the labeled statement somewhere in the current function. The general syntax of goto statement: Whenever, the statement goto label, is encountered, the control is transferred to the statement that is immediately after the label.

Generally, the use of goto statement is avoided as it makes program illegible and unreliable. This statement is used in unique situations like Branching around statements or group of statements under certain conditions Jumping to the end of a loop under certain conditions, thus bypassing the remainder of loop during current pass. Jumping completely out of the loop under certain conditions, terminating the execution of a loop. We have already known that we can jump out of a loop using either the break statement or goto statement.

In a similar way, we can jump out of a program by using the library function exit. In case, due to some reason, we wish to break out of a program and return to the operating system. The general syntax is if condition exit 0 ; The exit function takes an integer value as its argument. Normally zero is used to indicate normal termination and non zero value to indicate termination due to some error or abnormal condition.

Computer Programming in C printf Enter your choice: Write a program to check whether the number is prime or not. Enter number: Computer Programming in C printf Enter value of x: Enter the number to be checked: What is a control statement?

Differentiate between do while and while statement with the help of flow charts 2. What do you mean by control statements? Describe the application of break and continue in C-programming. Explain with examples 3. Write a program to check the given number is prime or not.

Write a program to check number is palindrome or not. What is control statement? Describe different control statement 6. Describe the different types of looping statement used in C with flow chart. Write a menu driven program using switch statement having the following options.

Chapter 7 Functions A function is defined as a self contained block of statements that performs a particular task. This is a logical unit composed of a number of statements grouped into a single unit. It can also be defined as a section of a program performing a specific task.

The function main is always present in each program which is executed first and other functions are optional. Advantages of using Functions: The advantages of using functions are as follows: Generally a difficult problem is divided into sub problems and then solved.

This divide and conquer technique is implemented in C through functions. A program can be divided into functions, each of which performs some specific task. So, the use of C functions modularizes and divides the work of a program.

When some specific code is to be used more than once and at different places in the program, the use of function avoids repetition of that code. The program becomes easily understandable. It becomes simple to write the program and understand what work is done by each part of the program. Functions can be stored in a library and reusability can be achieved. Types of Functions C program has two types of functions: Library Functions 2.

User defined functions Library Functions: These are the functions which are already written, compiled and placed in C Library and they are not required to be written by a programmer. The functions name, its return type, their argument number and types have been already defined.

We can use these functions as required. User defined Functions: These are the functions which are defined by user at the time of writing a program. The user has choice to choose its name, return type, arguments and their types.

The job of each user defined function is as defined by the user. A complex C program can be divided into a number of user defined functions. The function main is an user defined function except that the name of function is defined or fixed by the language. The return type, argument and body of the function are defined by the programmer as required.

This function is executed first, when the program starts execution. Function Declaration or Prototype: The function declaration or prototype is model or blueprint of the function. If functions are used before they are defined, then function declaration or prototype is necessary. Many programmers prefer a top-down approach in which main appears ahead of the programmer defined function definition. Function prototypes are usually written at the beginning of a program, ahead of any user-defined function including main.

Function prototypes provide the following information to the compiler. The name of the function The type of the value returned by the function The number and the type of arguments that must be supplied while calling the function.

In bottom-up approach where user-defined functions are defined ahead of main function, there is no need of function prototypes. A function can return value of any data type. If there is no return value, the keyword void is used. Arguments are optional. Function definition: A function definition is a group of statements that is executed when it is called from some point of the program. Parameters as many as needed: Each parameter consists of a data type specifier followed by an identifier like any regular variable declaration.

They allow to pass arguments to the function when it is called. The different parameters are separated by commas. The first line of the function definition is known as function header. The result is 8. Computer Programming in C return statement: The return statement is used in a function to return a value to the calling function. It may also be used for immediate exit from the called function to the calling function without returning a value.

This statement can appear anywhere inside the body of the function. There are two ways in which it can be used: The first form of return statement is used to terminate the function without returning any value.

In this case only return keyword is written. The value returned by the return statement may be any constant, variable, expression or even any other function call which returns a value. Calling a function or A calling function: A function can be called by specifying its name, followed by a list of arguments enclosed in parenthesis and separated by commas in the main function.

The arguments are classified into 1. Actual 2. Formal Actual:This process is called preprocessing. When prefix is used, the operand will be altered in value before it is utilized for its intended purpose within the program. When a function has no arguments, it does not receive any data from the calling function.

Format for floating point output: The do This feature eliminates the dependence of a C program on a particular character set. An expression that make use of the conditional operator is called a conditional expression.

The C compiler combines the capabilities of an assemble language with the features of a high-level language and therefore it well suited for writing both system software and business packages.

ELLEN from Saginaw
I love exploring ePub and PDF books daintily. See my other posts. I am highly influenced by martial arts.
>