ACKNOWLEDGMENTS
A dream is visualized by a pair of eyes; however, many pairs of hands join together and work hard toward its realization. This book has been a similar enterprise.
I next thank my college staff, director, and HOD for their contributions to this book on the C programming language.
I would also like to thank the entire staff of Mercury Learning for bringing the book to a new market.
Finally, I would like to thank my wife, Mrs. Shakti, my twin kids, Arjessh and Arshitha Chopra, as well as my parents who cooperated with me in all terms in order to write this book.
Dr. Rajiv Chopra
APPENDICES
APPENDIX A: C PROGRAMMING LAB PROJECTS
Write a C program to find the roots of a given quadratic equation using:
(a) If-then-else statements.
(b) Switch statements.
Write a C program to find the GCD and LCM of two integers.
Write a C program to reverse a given number and check whether it is a palindrome . Output the given number with a suitable message.
Write a C program to evaluate the given polynomial f(x) = ax + ax + ax + ax + a for a given value of x and the coefficients using Horners method.
Write a C program to copy its input to its output, replacing each string of one or more blanks by a single blank.
Write a C program to read n integer numbers in ascending order into a single-dimensional array and then to perform a binary search for a given key integer number and report success or failure in the form of a suitable message.
Write a C program to implement the bubble sort technique on a single-dimensional array. Display your arrays properly.
Write a C program to find out the average word length on the host machine.
Write a C program to compute the approximate value of exp(0.5) using the Taylor series expansion for the exponential function.
Write a C program to multiply two matrices.
Write a C function rightrot(x, n) and hence the main program to return the value of the integer x rotated to the right by n bit positions as an unsigned integer. Invoke the function from the main with different values of x and n and print the result with suitable headings.
Write a C function isprime(x) and hence the main program to read an integer x and return 1 if the argument is prime and 0 otherwise.
Write a C function reverse(s) and hence the main program to reverse a string s in place. Invoke this function from main for different strings and print the original and reversed strings.
Write a C program to find out whether the given string is a palindrome.
Write a C function match-any (s1, s2) that returns the first location in the string s1 where any character from the string s2 occurs or -1 if s1 contains no character from s2. Do not use any inbuilt standard library function. Invoke the function match-any (s1, s2) from the main for different strings and print both strings and return value from the function match-any (s1, s2).
APPENDIX B: KEYWORDS IN C
There are 32 keywords in C as follows:
| | | |
---|
auto | double | if | static |
break | else | int | struct |
case | enum | long | switch |
char | extern | near | typedef |
const | far | register | union |
continue | float | return | unsigned |
default | for | short | void |
do | goto | signed | while |
APPENDIX C: ESCAPE SEQUENCES IN C
| | |
---|
Character | Escape Sequence | ASCII Value |
Bell (alert) | \a | |
Backspace | \b | |
Horizontal tab | \t | |
Newline | \n | |
Vertical tab | \v | |
Form feed | \f | |
Carriage return | \r | |
Quotation mark () | \ | |
Apostrophe () | \ | |
Question mark (?) | \? | |
Backslash (\) | \\ | |
Null | \0 | |
Most compilers allow the apostrophe () and the question mark (?) to appear within a string constant as either an ordinary character or an escape sequence.
APPENDIX D: OPERATOR PRECEDENCE AND ASSOCIATIVITY
| | |
---|
Precedence Group | Operators | Associativity |
Function, array, structure member, | ( ) [ ] -> | L R |
pointer to structure member |
Unary operators | - ++ - - ! ~ | R L |
* & sizeof (type) |
Mul, div, and remainder | * / % | L R |
Add and subtract | + | L R |
Bitwise shift operators | << >> | L R |
Relational operators | < <= > >= | L R |
Equality operators | = = != | L R |
Bitwise and | & | L R |
Bitwise exclusive or | ^ | L R |
Bitwise or | | | L R |
Logical and | && | L R |
Logical or | | | | L R |
Conditional operator | ? : | R L |
Assignment operators | = += -= *= /= | R L |
%= &= ^= |= <<= >>= |
Comma operator | , | L R |
[ Aid to memory: UARL CA C] |
APPENDIX E: STANDARD LIBRARY STRING FUNCTIONS
| |
---|
Functions | Use |
strlen( ) | finds the length of string |
strlwr( ) | converts a string to lowercase |
strupr( ) | converts a string to uppercase |
strcat( ) | appends one string at the end of another |
strncat | appends first n characters of a string at the end of another string |
strcpy( ) | copies a string into another |
strncpy( ) | copies first n characters of one string into another |
strcmp( ) | compares two strings |
strncmp( ) | compares first n characters of two strings |
strcmpi( ) | compares two strings without regard to case |
strnicmp( ) | compares first n characters of two strings without regard to case |