C PROGRAMMING
COMPILED BY ARUP ROY CHOUDHURY, ASSOCIATE PROFESSOR, DEPARTMENT OF MATHEMATICS, MALDA COLLEGE, MALDA, WEST BENGAL
Overview of the C-Programming Languages, Data Type, Constants and Variables, Input and�Output, Operators and Expressions, if-else Statement, switch Statement, for Loop, while Loop,�do-while Loop, break and continue, functions, array and simple problems.
Program Logic and Technique:To write a program we must follow certain logical sequence so as to enable the computer to solve a particular problem. To develop such logical sequence certain program designing tools must be used. Basically there are three types of program designing tools.
1) Algorithm: It is a textual representation of a logic of the programming in a step by step manner.
Example: Write an algorithm to find the sum of any two numbers.
Solution: Step 1: Accept the first number.
Step 2: Store the number in X.
Step 3. Accept the second number.
Step 4: Store the number in Y.
Algorithm & Flow Chart
Step 5: Calculate the sum of X and Y.
Step 6: Store the sum in Z.
Step 7: Display the value of Z.
Step 8: End.
2) Flow Chart: It is a diagrammatic representation of a programming logic. The following symbols are used in a flow chart.
Algorithm & Flow Chart
(v) On page connector
(vi) Flow of program logic
Example: Write a flow chart to find the sum of any two numbers.
Solution:
Start
“Accept any two numbers”;X,Y
S=X+Y
“The sum of two numbers is:”; S
End
Pseudo-code
3) Pseudo-code: It is a textual representation of a programming logic written in an english like statement which is independent of any programming logic.
Example: Write a pseudo-code to calculate the sum of two numbers.
Solution:
BEGIN:
Accept the first number in X.
Accept the second number in Y.
S=X+Y.
Display S.
END:
Flow chart
Example: Write a flow chart to find the sum of first hundred natural numbers.
Solution:
Yes
No
Start
I=1
S=0
S=S+I
I=I+1
Is
I<=100?
“The required sum=”;S
End
Flow Chart
Example: Write a flow chart to find the sum of the finite series 1 + 1/2! + 1/3! + …..+ 1/n!.
Solution:
Yes No
Start
“Accept the number:”; n
I = 1; S = 1; S1 = 0
S = S * I
S1 = S1 +1.0/(S)
I = I +1
Is I <=n ?
“The required sum=“;S1
End
Flow Chart
Exercise: 1) Write a flow chart to find the sum of the finite series 1+ ½ + 1/3 +…+1/n.
2) A book seller offers two rates of discount. When the price of a book lies below Rs. 100, the rate of discount is 15% of the price, otherwise the rate is 18%. It require to find out the discount and thus the net price of a book purchased by a customer. Draw a flow chart.