0% found this document useful (0 votes)
284 views

Sample Lab Report of C

The document discusses input and output functions in C programming. It provides the objectives, theory, algorithms, flowcharts and code for a program to calculate the area of a rectangle using input and output functions. It also provides a sample output and conclusion.

Uploaded by

rkrajan1225
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
284 views

Sample Lab Report of C

The document discusses input and output functions in C programming. It provides the objectives, theory, algorithms, flowcharts and code for a program to calculate the area of a rectangle using input and output functions. It also provides a sample output and conclusion.

Uploaded by

rkrajan1225
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

TRINITY INTERNATIONAL SS & COLLEGE

Lab-report on c-programming

(COMPUTER SCIENCE)

SUBMITTED BY: SUBMITTED TO:


NAME: Purushottam Lal Karn
GRADE:

STUDENT ID NUMBER:-

REGISTRATION NUMBER:-

STUDENT’S EMAIL:-

KATHMANDU, NEPAL
2023
TRINITY INTERNATIONAL SS & COLLEGE

Lab sheet #1
(Input and output functions)

Lab date:-
Submission date:-

Internal signature External Signature


Objectives:-
The objective of a program using input and output functions is
to know about different input and output functions and their
use in different programs. It will help us to be familiar with
some frequently used I/O functions like scanf(),printf(),
gets(),puts, putchar() ,getchar() etc. Having used functions, we
will be able to input and output numerical and string related
data easily

Page 1
Table of Contents
Objectives:-............................................................................................1
Theory ....................................................................................................3
Data Input and Output functions in C ...................................................3
Algorithm to find area of rectangle: ......................................................5
Flowchart to find area of rectangle: ......................................................5
Program Code to find area of rectangle: ...............................................6
Sample Output : .....................................................................................7
Conclusion:- ..........................................................................................8

Page 2
Theory
Data Input and Output functions in C

For data input and output, C provides a collection of library functions


such as getchar, putchar, scanf, printf, gets and puts. These functions
enable the transfer of data between the C program and standard
input/output devices. C always treats all input-output data, regardless
of where they originate or where they go, as a stream of characters.
The operating system makes the input and output devices available to
a C program as if these devices were files. So, essentially, when a C
program reads data from the keyboard, it is in effect reading from the
file associated with the keyboard device. When a C program sends
output data to the console, it is in effect writing to the file associated
with the console device.
getchar()
This is a single character input function. getchar() reads a single
character from stdin - the standard input data stream, viz. the file
associated with the standard input device, which is normally the
keyboard.
putchar()
This is a single character output function. putchar() writes a single
character to stdout - the standard output data stream, viz. the file
associated with the standard output device, which is normally the
console.
gets() and puts()
The standard library function gets accepts input in the form of a
string. The character string may even include whitespace characters.
Each call to gets will read all the characters from the input steam until
an end of line character is encountered. The end of line character is

Page 3
represented as \n and gets generated when you press
the enter key. gets assigns the read string to the variable that is passed
as its parameters. gets assigns NULL when an error occurs.
The standard library function puts sends the passed string to stdout.
After the output, puts sends out a carriage return and a line
feed character. This takes the cursor to the next line automatically.
scanf()
The scanf function is used to read formatted input data. The format in
which input data is to be provided is specified by the scanf function
itself as it's first parameter. The scanf function is written as -
scanf(<control string>, &address1, &address2, . . . , &address_n);
Here, the first parameter <control string> contains a list of format
specifiers indicating the format and type of data to be read. The
remaining parameters - &address1, &address2, ..., &addressn are
addresses of the variables where the read data will be
stored. scanf reads the input data as per the format specifiers and
stores them (i.e., assigns them) to the corresponding addresses.
An & is pre-fixed to the variable name to denote its address.
Note that there must be the same number of format specifiers and
addresses as there are input data. For instance, in the following
example:
scanf("%d %f",&x,&y);

Page 4
Question 1 :

Algorithm to find area of rectangle:


Step-1: start
Step-2: Read length (l) and breadth (b)
Step-3 : Let area=lxb
Step-4 :print area
Step-5: stop

Flowchart to find area of rectangle:

Page 5
Program Code to find area of rectangle:
#include<stdio.h>
// C program to find araa of rectangle
main()
{
printf("\n Program written by Student Name \n");
int l,b,area;
printf(" Enter length and breadth : ");
scanf("%d%d",&l,&b);
area=l*b;
printf(" Area of rectanlge is %d",area);
}

Page 6
Sample Output :

Question 2 :
algorithm:
flowchart
Program code:
sample output:
Question 3:
algorithm:
flowchart
Program code:
sample output:

-------------
and follow this to all questions given in the lab work list

Page 7
Conclusion:-
It was a wonderful time in the lab and classroom while
learning. The outcome of the learning is great and is very
similar to the prediction made in the beginning. We learned
about input and output functions in detail. It helped us a lot in
our programming. We came to know its syntax, semantic with
example. I hope that this will help us in future in my project
work. At last I would like to thank my class subject teacher
for his support and cooperation.

Page 8

You might also like