C Manual
C Manual
Guide to Learn C
programming
CONTENTS
Acknowledgments i
1 What is Programming 1
2 Arithmetic Operations in C Pg #
3 Operators in C Pg #
4 Decision Statements Pg #
5 Loops Pg #
6 Functions Pg #
7 Arrays Pg #
9 File operations Pg #
i
1 WHAT IS PROGRAMMING
1
Let’s C: A Practical Guide to Learn C programming
2
Let’s C: A Practical Guide to Learn C programming
3
Let’s C: A Practical Guide to Learn C programming
4
Let’s C: A Practical Guide to Learn C programming
5
Let’s C: A Practical Guide to Learn C programming
6
2 ARITHMETIC OPERATIONS IN C
7
3 OPERATORS IN C
9
Let’s C: A Practical Guide to Learn C programming
10
4 DECISION STATEMENTS IN C
Decision statements are used when you have to use between two
different types of sequence of commands and the decision is based
on a condition.
Practice Problems:
1. Write a program to input marks of 5 subjects (Physics, Chemistry,
Math, English & Biology) for a student. Display the rank of each
subjects and also the result of total marks and percentage obtained
with his/her rank in the class. The rank is categorized as fail (marks
< 40%), pass & third division (marks between 40 to 55%), second
(marks between 55 to 65%), first (marks between 65 to 80%),
Distinction (marks between 80 to 95%), extra ordinary (marks above
95 to 100%).
2. Write a program to find the largest and smallest among three
entered numbers and also display whether the identified
largest/smallest number is even or odd.
3. Write a program to check whether input alphabet is vowel or not
using if-else and switch statement.
4. Write a program to get input of two or higher digit integer number
and display in reverse order.
5. Write a program that asks a number and test the number whether
it is multiple of 5 or not, divisible by 7 but not by eleven.
6. Write a program to check whether the entered year is leap year or
not (a year is leap if it is divisible by 4 and divisible by 100 or 400.)
7. Write a program to read the values of coefficients a, b and c of a
12
Let’s C: A Practical Guide to Learn C programming
13
5 LOOPS
Practice Problems:
1. Write a program to find sum as Y of the following series excluding
prime numbers in the series:
1 22 32 102
𝑌 =1+ + + + ⋯+
1! 2! 3! 10!
2. Write a program to input two integer numbers and display the sum
of even numbers between these two input numbers.
3. Write a program to display Fibonacci series of last term up to 300.
4. Write a program to display the flag of Nepal using symbolic/HEX
character in C.
16
Let’s C: A Practical Guide to Learn C programming
17
6 FUNCTIONS
Practice Problems:
1. Write a program to find sum as Y of the following series excluding
prime number in the series. (Write function program to check
whether the number is prime or not. also write recursive function to
calculate the factorial of the series numbers).
1 22 32 102
𝑌 =1+ + + + ⋯+
1! 2! 3! 10!
2. Write a program to add, subtract, multiply and divide two integers
using user defined type function with return type.
3. Write a program to calculate sum of first 50 natural numbers using
recursive function.
4. Define a function named fact() to calculate factorial of a number
n and then write a program that uses this function fact() to calculate
combination and permutation.
5. Write a recursive function to generate Fibonacci series.
6. Write a program that illustrates use of local, global and static
variables.
18
7 ARRAYS
Practice Problems:
1. Write a program to find separately the sum of the positive and
negative integer elements of an array of size 10. Pass this array to a
function called sortarray(int[]) and display the array elements into
ascending order.
2. Write a program to enter 10 floating numbers in an array and
display it.
3. Write a program to display largest and smallest element of an array
defined in Q.No. 2.
4. Write a program to initialize one dimensional array of size 8 and
display the sum and average of array elements.
5. Write a program to read two matrices of order 3 * 2, add them
and display the resultant matrix in matrix form.
6. Write a program to multiply two 3*3 matrix.
7. Write a program to read a string and check for palindrome without
using string related function (a string is palindrome if its half is
mirror by itself eg: abcdcba).
22
8 POINTERS AND STRINGS
Practice Problems:
1. Write a program to find separately the sum of the positive and
negative integer elements of an array of size 10. Pass the positive and
negative elements to separate functions eg: sumpositive(int*),
sumnegative(int*) to carry out its sum. Also pass this array to a
function called sortarray(int[]) and display the array elements into
ascending order using pointer.
2. Write a program to find biggest among three numbers using
pointer
3. Write a program to find the sum of all the elements of an array
using pointers.
4. Write a program to swap value of two variables using pointer.
5. Write a program to read a sentence and count the number of
characters &words in that sentence.
6. Write a program to read a sentence & delete all the white spaces.
Replace all “.” by “:”.
7. Write a program to copy one string to another string with and
without using string handling function.
8. Write a program to concatenate two strings.
9. Write a program to compare two strings.
10. Write a program to sort 5 string words stored in an array of
pointers.
11. Write a program to print the following pattern:
26
Let’s C: A Practical Guide to Learn C programming
UN
UNIV
UNIVER
UNIVERSI
UNIVERSITY
UNIVERSI
UNIVER
UNIV
UN
27
9 STRUCTURES
Practice Problems:
1. Write a program to read RollNo, Name, Address, Age & marks in
physics, C, math in 1st semester of three students in BCT and display
the student details with average marks achieved.
2. Create a structure named company which has name, address,
phone and noOfEmployee as member variables. Read name of
company, its address, phone and noOfEmployee. Finally display
these members’ value.
3. Write a program to enter to Cartesian coordinate points and
display the distance between them.
4. Write a function which accepts structure as argument and returns
structure to the calling program.
5. Pass the structures defined in Question 1 into a function and read
the structure member and display the values from the function (use
structure pointer).
6. Define a structure “complex” (typedef) to read two complex
numbers and perform addition, subtraction of these two complex
numbers and display the result.
7. Write a program to read RollNo, Name, Address, Age & average-
marks of 12 students in the BCT class and display the details from
function.
8. Write a program to show programming examples with union and
31