0% found this document useful (0 votes)
6 views9 pages

C Programming

The document is a lab manual for C programming, compiled by Er. Rama Bastola, aimed at helping students understand the basics of programming in C. It outlines the software requirements, structure of a C program, and provides a detailed guide for pre-lab, in-lab, and post-lab activities, including a sample lab report format. The manual also includes a specific example of calculating the area of a triangle using its sides, along with an algorithm, flowchart, and code implementation.

Uploaded by

ratnabeepwool69
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views9 pages

C Programming

The document is a lab manual for C programming, compiled by Er. Rama Bastola, aimed at helping students understand the basics of programming in C. It outlines the software requirements, structure of a C program, and provides a detailed guide for pre-lab, in-lab, and post-lab activities, including a sample lab report format. The manual also includes a specific example of calculating the area of a triangle using its sides, along with an algorithm, flowchart, and code implementation.

Uploaded by

ratnabeepwool69
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

2019

Lab Manual on
Programming in C

Department of Electronics and Computer Engineering


IOE, Thapathali Campus

Compiled By:
Er. Rama Bastola
C Programming
Welcome to the C Programming Lab. The lab exercises in this lab will give the students an
opportunity for learning and better understanding of the basic concepts and constructs of
computer programming in C language.

Introduction
C is a programming language developed by Dennis Ritchie at AT&T‟s BELL Laboratory
of USA in 1972. Because of its reliability, C is very popular. C is highly portable & it is
well suited for structured programming. C program consists of collection of functions.

Software Requirement
 Linux Operating System with GCC
 TURBO C in WINDOWS OS (You may use other IDEs or text editors such as
CodeBlocks, Notepad++ etc)

Structure of C Program
C program is a collection of several instructions where each instruction is written as a separate
statement. The C program starts with a main function followed by the opening braces which
indicates the start of the function. It then follows the variable and constant declarations which
are followed by the statements that include input and output statements.
C program may contain one or more sections The composition of C program with main
components are shown in the following figure.

1
Fig. Structure of C Program

2
Steps of programming
1. Code in editor
2. Save the file with .c extension
3. Compile
4. Debug 5. Run

General Instructions to students


For the lab works of C programming, you have to complete all lab activities included in this lab
manual throughout the course. These lab sheets will guide you to prepare for programming and
submission of lab reports. Further, it helps you to understand the basic knowledge of
programming. You can use this lab guide as the base reference during your lab which mainly
includes the following activities.

Pre-Lab Activities
Students need to prepare an initial lab report prior to the lab time. The report consists of
statement of problem, objective(s), problem analysis, algorithm or flowchart.

In-Lab Activities
Student must code each program themselves and show to the lab instructor. Lab instructor
evaluate you on the basis of efficiency of the program, output of each program and viva

3
Post-Lab Activities
Student should submit final report of the previous lab in the following lab report format.

Lab Report Format

C programming lab report should include the following topics.

1. Cover page
2. Problem Title
3. Objective(s)
4. Problem Analysis
5. Algorithm or Flowchart
6. Code
7. Output
8. Discussion and Conclusion

4
Tribhuvan University
Institute of Engineering
THAPATHALI CAMPUS

LAB Report on C
Lab Sheet: 1

C Lab Report Submitted By:


Name: ___________________
RollNo: ___________________

Submitted To:
Department of Electronics and Computer Engineering

Obtained Marks:
Lab Date:
Remarks:

Submission Date: Signature: ………………………

5
Objective(s):

 To be familiar with syntax and structure of C-programming.


 To learn problem solving techniques using C

Title:
Evaluate area of triangle with 3 sides given
Problem Analysis:

The problem is to evaluate area of a triangle using its sides. It has three input parameters
identitied as side a, b and c which datatype is integer type. The output of the program is
to display the area of the triangle which is identified as area (float type). During the
processing phase, we need to calculate value of s (float).
The formula to calculate area of triangle is
area=sqrt(s(s -a)(s-b)(s-c))
where a,b,c are the sides of the triangle
and s=(a+b+c)/2
Input Processing variables Output Necessary header
Variables variable files/functions/macr
os
a(int) s= (a+b+c)/2 Area(float) stdio.h

b(int) area = sqrt(s*(s-a)*(s-b)*(s-c))

c(int)

6
Algorithm

Step1: start
Step2: input a,b,c
Step3: s=(a+b+c)/2
Step4: A=sqrt(s(s-a) (s-b) (s-c))
Step5: Print A
Step 5: stop

Flowchart:

7
Code:
/*To evaluate area of triangle (sqrt(s(s-a)(s-b)(s-c)*/
#include<math.h>
#include<stdio.h>
void main()
{
int a,b,c;
float s,area;
clrscr();
printf("enter the values of a,b,c");
scanf("%d%d%d",&a,&b,&c);
s=(a+b+c)/2.0;
area=sqrt(s*(s-a)*(s-b)*(s-c));
printf("the area of a trangle is =%f",area);
getch();
}

Output (Compilation, Debugging & Testing)


enter the values of a,b,c
15
20
30
The area of a trangle is = 133.317
Discussion and Conclusion
This is the first code written in C program. The program is focused on the calculation of area of
a triangle for the given three sides. From this lab, I understood the basic structure of C
programming and steps of problem solving. Hence, area of a triangle given three sides is
calculated and displayed.

You might also like