0% found this document useful (0 votes)
88 views16 pages

Welcome To Practical Class: Subject Code: 275

This document provides instructions for a programming lab work to arrange data items into ascending order using C language. It includes: 1) An explanation of the theory which is to store data in an array, compare elements, and swap them if out of order until sorted. 2) Details on the required hardware (computer and UPS) and software (OS, editor). 3) Steps to perform the experiment, including checking equipment, writing the algorithm, flowchart and code. 4) An example C code provided to perform the sorting, taking input, comparing elements, swapping if out of order, and printing output.

Uploaded by

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

Welcome To Practical Class: Subject Code: 275

This document provides instructions for a programming lab work to arrange data items into ascending order using C language. It includes: 1) An explanation of the theory which is to store data in an array, compare elements, and swap them if out of order until sorted. 2) Details on the required hardware (computer and UPS) and software (OS, editor). 3) Steps to perform the experiment, including checking equipment, writing the algorithm, flowchart and code. 4) An example C code provided to perform the sorting, taking input, comparing elements, swapping if out of order, and printing output.

Uploaded by

Hasibul Islam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 16

Welcome to Practical class

Subject: ICT

Subject code: 275


Conducted by

Rashedul Islam
Lecturer in Computer Science
Rajuk Uttara Model College
Lab Work # 11 Date of Lab work: 30/ 10/2014

Date of submission: 01/ 11/2014

Name of the lab work:


Write a program in C language to arrange list of data items into
ascending order.

Theory:
At first we have to store the data items into an array. Then compare
the elements with each other like 1st data with 2nd, 3rd and so on. The
procedure will continue until all the data items are arranged in
ascending order.
Uses of the instruments:

• Hardware :
• i. A Microcomputer/Laptop
• ii. UPS for the microcomputer
• Software :
i. Operating system-Windows XP/Windows 7/8
ii. Editor of C language: TC/Borland C/Dev C++/Code
blocks
Use :
Following procedure have to followed to perform
the above experiment in terms of using the
instruments:
1. Before starting the task, we have to check electric
connection of the computer.

2. Turn on the power switch of the computer to start it.


3. We have to check whether the above mentioned
software are installed in the computer or not.

4. To run necessary program to perform the mentioned


experiment.

5. After performing the experiment, we have to close all


the programs and shutdown the computer in proper way.
To present the results:
(a). To follow up the process:

• Following procedure have to be followed to


perform the experiment.
i. Writing algorithm
ii. Drawing flow chart
iii. To write code in any C editor
i. Algorithm of the given lab work
• Step-1:Start
• Step-2: Compare each element of the array with remaining
elements , if they are in reversed order, swap them.
• Step-3:Repeat step-2 until sorted list is obtained.
• Step-4: Stop
ii. Flow chart
iii. Code in C language
• Before writing code following procedure have
to be followed:-
• Double click on TC>Bin>Tc.exe
• Then Turbo C++ IDE window will appear.
• From this window click File>New. So following
C Editor will appear.
In this window write following code to calculate area of the
triangle:-
#include<stdio.h>
#include<conio.h>
void main()
{clrscr();
int i,j,n,temp,a[100];
printf(" How many number(<100) you want to sort?:");
scanf("%d",&n);
printf("\n\nEnter Your numbers");
for(i=0;i<n ;i++)
scanf("%d",&a[i]);
for(i=0;i<n-1;i++)
for(j=i+1;j<n;j++)
if(a[i]>a[j])
{ temp=a[i];
a[i]=a[j];
a[j]=temp;
}
printf("\n\nThe sorted list is\n");
for(i=0;i<n;i++)
printf("%5d",a[i]);
getch();
}
To save the file

Click on file menu


Click on Save submenu
Type sorting in the file name box
Click OK button. So the file will be saved
as SORTING.CPP
Explanation:
Explanation of the statements and functions used in the
program are given below:
Statement/ Description
function
#include To establish link with header file
<stdio.h> To use standard input/output function. Such as:
printf(), scanf()
<conio.h> To use function. Such as: getch()
void main() Mandatory function of every c program
clrscr() To clear the output screen
{ } Indicates start and end of every program
for Loop statement. Generally used in series.
Statement/ Description
function
int To declare integer type data.
printf To display anything on the screen
scanf To take input from keyboard
%5d To fixed 5 digits for integer data
++ Increment operator. Value of the variable will
increment by 1.
a[100] Array a[], that can store maximum 100
elements.
\n Newline operator
If To execute the statement under the given
condition.
getch() To tell the program control to wait for a single
character.
Result: Open the file SORTING.CPP
Press Ctrl+F9 from the keyboard.
After providing 5 and 500 400 100 200 300 as
input, following output will be displayed as result.
Let’s have a practice……

You might also like