Ramaiah University of Applied Sciences
Laboratory 1
Title of the Laboratory Exercise: Introduction to C
programming
1. Introduction and Purpose of Experiment
C is a powerful general-purpose programming
language. It can be used to develop software
like operating systems, databases, compilers, and
so on. C. In this laboratory exercise,
students get familiar with the program
development tool such as netbeans IDE to edit and
run C programs using a set of simple exercises.
2. Aim and Objectives
Aim
● To familiarize IDE and simple C programs
Objectives
At the end of this lab, the student will be able to
● Explain the features and use of IDE to develop C
programs
● Edit and execute simple C programs
3. Experimental Procedure
Students are given a set of C programs. Edit and
execute C programs using net beans IDE
i. Analyse the problem statement
ii. Problem solving approach for the given problem
statement and develop
algorithm
iii. Implement the algorithm in C language
iv. Execute the C program
v. Test the implemented program
vi. Document the Results
vii. Analyze and discuss the outcomes of the
experiment
4. Questions
a. Write a C program to print Hello World.
b. Write a C program to calculate the area of a
circle.
c. Write a C program to experiment on escape
sequences.
5. Problem Solving Logic and Algorithm
A. Problem to Print Hello World
a. If you write ' printf(" Hello World&
quot;)' in the main() function, then the
compiler
prints the string " Hello World " on the
output.
● Algorithm
Algorithm for print Hello world
Begin
Output Hello World
End
Name: Registration Number:
B. Program to calculate the area of Circle
a. Problem solving Logic: we will be calculating the
area of a circle using its radius. As we know the
formula to find the area of circle, If the radius is
given as- Area = pi*r*r. Now simply, we have to
write a program to convert
this logic into code.
● Algorithm:
Algorithm for area of circle ()
Var radius, pi, area: Integer
Begin
Read radius and pi
Begin
End
End Area = pi*radius*radius
Write area
C. Program to experiment on escape sequences.
a. Program solving logic: In this experiment we will
see how to use the escape
sequence and test the various escape sequences
like:-\n , \t etc. The
purpose of the escape sequence is to represent
the characters that cannot
be used normally using the keyboard.
● Algorithm:
Algorithm for Experiment on escape sequence
Begin
Output hello world \n
Output This is my computer
End
6. Program with Test cases
1)
a. Program
b. Test cases
2 a.
Program
b. Test Cases
3)
a. program
b. test cases
7. Summary
i) Limitations of Experiments and/or Results
ii) Recommendations
iii) Learning happened
Laboratory 2
Title of the Laboratory Exercise: Introduction to C
programming
1. Introduction and Purpose of Experiment
C is a powerful general-purpose programming
language. It can be used to develop software
like operating systems, databases, compilers, and
so on. C. In this laboratory exercise,
students get familiar with the program
development tool such as NetBeans IDE to edit and
run C programs using a set of simple exercises.
2. Aim and Objectives
Aim
● To develop programs involving branching using
appropriate control statements in
Objectives
● At the end of this lab, the student will be able to
Apply conditional control statements such as if-
else and nested if-else to express decisions
3. Experimental Procedure
Students are given a set of C programs. Edit and
execute C programs using NetBeans IDE
i. Analyse the problem statement
ii. Problem solving approach for the given problem
statement and develop
algorithm
iii. Implement the algorithm in C language
iv. Execute the C program
v. Test the implemented program
vi. Document the Results
vii. Analyse and discuss the outcomes of the
experiment
4. Questions
a. Write a C program to test if a number is zero,
positive or negative.
b. Write a C program to find a minimum of three
numbers.
c. Write a C program to display the roots of a
quadratic equation.
5. Program solving logic : The program inputs
quadratic coefficients, computes the
discriminant, and determines roots accordingly.
Positive discriminants yield two real roots,
zeros lead to a single real root, while negatives
indicate imaginary roots. It displays results
and returns 0 upon completion, effectively solving
quadratic equations.
Algorithms:
1. Algorithm for to test if a number is zero, positive
or negative
1. Begin
2. Initialize a variable called "num".
3. Ask the user to input a number.
4. Read the input number and store it in the
variable " num& quot;.
5. If the value of " num& quot; is less than 0,
then
5.1. Print " Negative number& quot;.
6. Else if the value of " num& quot; is greater
than 0, then
6.1. Print " Positive number& quot;.
7. Otherwise (if the value of " num& quot; is
equal to 0),
7.1. Print " The number is 0& quot;.
8. End.
2. Algorithm for to find a minimum of three
numbers
1. Begin.
2. Declare variables a, b, c to store three numbers.
3. Prompt the user to enter three numbers.
4. Read the three numbers from the user.
5. If a is less than b and less than c, then
5.1. Print & quot; The number a is the smallest&
quot;.
6. Else if b is less than c and less than a, then
6.1. Print & quot; The number b is the smallest&
quot;.
7. Otherwise (if c is the smallest),
7.1. Print & quot; The number c is the smallest&
quot;.
8. End.
3. Algorithm for to display the roots of a quadratic
equation.
[Link]
2. Declare variables: a, b, c, d, r1, r2
3. Prompt the user to enter coefficients of
quadratic equation: a, b, c
4. Read coefficients a, b, c from user input
5. Calculate discriminant d = (b^2) - (4 * a * c)
6. If d > 0, then
6.1. Calculate first root r1 = (-b + sqrt(d)) / (2 * a)
6.2. Calculate second root r2 = (-b - sqrt(d)) / (2 * a)
6.3. Print & quot; The roots are r1 and r2"
7. Else if d == 0, then
7.1. Calculate the only root r1 = -b / (2 * a)
7.2. Print & quot; The root is r1"
8. Else,
8.1. Print & quot; The roots are imaginary& quot;
9. End
6. Program with Test cases
1)
a. Program
b. test cases
2)
a. Program
b. Test cases
3)
a. program
b. Test cases
Laboratory 3
Title of the Laboratory Exercise: Loops and Arrays
1. Introduction and Purpose of Experiment
Loop statements are used to repeat a statement or
set of statements multiple times. By solving the
problems students will be able to apply iterative
control statements to control the program
execution. An array is a data structure consisting
of a collection of elements (values or variables), of
same memory size, each identified by at least one
array index or key.
2. Aim and Objectives
Aim
• To develop programs involving loops using
appropriate control statements in C
Objectives
At the end of this lab, the student will be able to
• Apply loop control statements such as for, do
while and while to repeat a block of
code
3. Experimental Procedure
i. Analyze the problem statement
ii. Problem solving approach for the given problem
statement and develop algorithm
iii. Implement the algorithm in C language
iv. Execute the C program
v. Test the implemented program
vi. Document the Results
vii. Analyze and discuss the outcomes of the
experiment
4. Questions
a. Write a C program to perform matrix addition
and multiplication
b. Write a C program which uses the formula C=
(5/9) * (F-32) to print a table of Fahrenheit
temperatures and their centigrade or Celsius
equivalents from 1 to 300 Fahrenheit temperature.
5. Problem Solving Logic and Algorithm
Algorithms
1. Algorithm for a C program to perform matrix
addition and multiplication
1. Begin the program.
2. Declare variables `row A`, `col A`, `i`, `j`, `a[10]
[10]`, `b[10][10]`, and `c[10][10]` to store the
dimensions and elements of matrices A, B, and the
resultant matrix C.
3. Print a message asking the user to enter the
number of rows and columns for matrix A.
4. Read the number of rows and columns for matrix
A from the user and store them in
variables `rowA` and `colA`.
5. Print a message asking the user to enter the
elements of matrix A.
6. Use nested loops to read the elements of matrix
A from the user and store them in the
array `a[][]`.
7. Print a message asking the user to enter the
number of rows and columns for matrix B.
8. Read the number of rows and columns for matrix
B from the user and store them in
variables `row A` and `col A`.
9. Print a message asking the user to enter the
elements of matrix B.
10. Use nested loops to read the elements of
matrix B from the user and store them in the
array `b[][]`.
11. Print a message indicating the beginning of the
output matrix.
12. Use nested loops to calculate the sum and
multiplication of corresponding elements of
matrices A and B and store the result in the array
`c[][]`.
13. Print each element of the resultant matrix C.
14. After printing each row, move to the next line.
15. End the program.
2. Algorithm for a C program which uses the
formula C= (5/9) * (F-32) to print a table of
Fahrenheit temperatures and their centigrade or
Celsius equivalents from 1 to 300
Fahrenheit temperature.
1. Begin the program.
2. Declare two integer variables `Fah` and `Cell` to
store Fahrenheit and Celsius values
respectively.
3. Start a `for` loop with `Fah` initialized to 1,
running while `Fah` is less than or equal to 30,
and incrementing `Fah` by 1 in each iteration.
4. Within the loop, calculate the Celsius value
corresponding to the current Fahrenheit value
using the formula: ` (Fah - 32) * (5/9)` . However, in
the code, it's using integer division which
means only the integer part of the result is kept.
Since `0.55` is less than `1`, the result will be
`0`. The correct formula should use floating-point
division.
5. Print the Fahrenheit value (`Fah`), and the
calculated Celsius value (`Cell`) using `printf`.
6. Repeat steps 3-5 until `Fah` becomes greater
than 30.
7. End the program.
6. Program with Test cases
i) Program
ii) Test cases
iii) Program
iv) Test cases
b)
i) Program
ii) Test cases
c)
7. Summary
i) Limitations of Experiments and/or Results
ii) Recommendations
iii) Learning happened