POP Manual
POP Manual
INTRODUCTION
The motherboard will be This is simple and slowest It helps to connect various
having 3 or 4 PCI bus used in IBM PCs I/O devices like keyboard,
connectors, so that we can mouse, pen drives, printer,
insert various chips. etc.
Fastest and presently more Oldest, simplest and slowest Newest and widely used bus
powerful bus Bus
Main Board or Mother Board: Mother Board is a set of Integrated Chips (ICs) which are designed to work
together. It controls the flow of data/instructions within our computer. It is the main board on which other hardware
components are connected to enable the computer system to work as an integrated unit. It consists of sockets, slots,
power connectors and bus.
Chip sets: Chip set is the set of integrated chips that are designed to work together. These set of chips controls the
flow of information on computer. The chips may be controllers for memory, cache, hard drive, key board and
peripherals.
Operating System and its types: An Operating System (OS) is system
software that controls and supervCSEs the hardware components of a
computer system and it provides the services to computer users. Also
called as Resource Manager that manages the resources such as CPU,
Memory, I/O devices, Job/Task/Process etc., a computer cannot run
without it. The major functions of OS includes: CPU Management,
Memory Management, File
Management, Device Management, Process/Task/Job Management
and Security Management.
The primary goal of an OS is to make the computer system convenient and efficient to use. An OS ensures that the
system resources (such as CPU, memory, I/O devices, etc) are utilized efficiently. For example, there may be many
programs residing in the main memory. Therefore, the system needs to determine which programs are active and
which need to wait for some I/O operation.
Some of the examples of Operating Systems:
Windows –XP is an O.S. is used for Personal Computers (PCs) Unix and XENIX are the OSs used for
multi-user computers. Windows 7, Windows 8, Macintosh OS, Fedora, and Android, etc.
Types of Operating Systems: The operating systems are classified into 7 types based on their capability and usage.
Fig 3: Types of OS
Batch Processing Tasking OS: The data is collected into a group called batch and provides only one batch
(one after another) of jobs as input to the computer system at a time. The jobs in a batch are processed on first
come first serve basis. In this type, the process takes place at specified time intervals i.e. weekly or monthly
without user interaction. E.g. Punch cards were using to store the data in batch processing and in payroll
preparation in a business batch processing was helpful.
Single user and single tasking OS: The OS that allows only one program to execute at a time is called
single user single tasking operating system. Using this operating system user can do only one task at a
time. E.g. DOS (Disk Operating System).
Single user and multi tasking OS: The OS that allows a single use to perform more than one
task at a time is called single user multi tasking operating system. While working with the Ms-Word user
can perform other work like print a document, listen music.E.g. Windows-XP, Windows Vista, Windows
– 7, etc.
Multi user and multitasking OS: The O.S. that allows two or more users to use a main computer
system to do more than one task is called multiuser and multitasking operating system.E.g. UNIX is a
multiuser and multitasking operating system.
Multiprocessing OS: The OS that allows multiple programs to be executed by multiple CPUs
(Processors) is called multiprocessing operating system. Super and main frame computers have more
than one CPU and multiprocessing operating system.
Real Time Operating System (RTOS): The OS that is used for real time applications and to carry
out certain calculations within the specified time constraint. This OS is used in applications such as mobile
phones, supporting systems in hospitals, nuclear power plants, oil refining, chemical processing, environmental
applications and air-traffic control systems, disaster management etc.,
Virtual machine OS: Allows several users of a computer system to operate as if each has the only
terminal attached to the computer.
Random Access Memory (RAM): RAM is basically main memory of the computer.
RAM is a semiconductor memory made up of small memory chips that form a memory
module. These modules are installed in the RAM slots on the motherboard of computer.
Every time you open a program, it gets loaded from the hard drive into the RAM. This is
because reading data from the RAM is much faster than reading data from the hard
drive.
Synchronous Dynamic Random Access Memory (SDRAM): It is an improvement to standard DRAM
because it retrieves data alternately between two sets of memory. This eliminates the delay caused when
one bank of memory addresses is shut down while another is prepared for reading. It is called
"Synchronous" DRAM because the memory is synchronized with the clock speed that the computer's
CPU bus speed is optimized for. The faster the bus speed, the faster the SDRAM can be. SDRAM speed
is measured in Megahertz.
FLASH memory: Flash memory is a type of Electrically Erasable Programmable Read-Only Memory
(EEPROM). The name comes from how the memory is designed -- a section of memory cells can be
erased in a single action or in a "flash.” Flash memory cards used for digital cameras, cellular phones,
networking hardware, and PC cards.
Hard disks: Hard disk is prime unit of storage of the computer. Huge amount of data can be stored and
accessed in few millCSEconds. The hard disk consists of more number of disks arranged in the
cylindrical order, one above another on a spindle.
The read/write heads are attached to single access mechanism
so that they cannot move independently. All read/write heads are
moved together to position that heads on the required track. The hard
disks available today ranges from 200 GB to 2TB and so on. The
present day hard disk ranges from 3600 rpm to more than 10000 rpm
and so on.
A CD-ROM uses the round shaped optical disk to store data, applications, games and
audio files. It can store up to 700 MB of data. It has become integral part of every
organization due to its features like reliability, reasonable, storage capacity and easy to
use of carry.
CD-Drive will be with motor to rotate the disks to perform read and write operations. A CD-drive
will
consists of the components like Disc drive, disk drive motor, laser pick up assembly tracking drive and
tracking motor and so on.
Compact Disk Recordable (CD-R): The CD-R allows you to create your own CD.CD-R drives have the
ability to create CDs but they can write data on the disk only once.CD-R technology also called as Write
Once-Read much (WORM) technology. Laser technology is used to write the data on the compact
disk.CD-R drives come in IDE, SCSI and USB models.
Compact Disc Rewritable (CD-RW): CD-RW is an erasable optical disk which is used to write data
multiple times on a disk, CD-RW disks are good for data backup, data archiving or data distribution on
CDs. The disk normally holds 700MB of data. Technology to write data multiple times on a CD was
known as the Phase change Dual (PD) technology. The reflective properties of a CD-RW are different
than regular CD-ROM disks.
Disk or Digital Versatile Disc (DVD-ROM): A DVD is a small optical disk having high density
medium and capable of storing a full-length movie on a single disk. The high density is achieved by
using both sides of the disk, special data-compression technology, and extremely small tracks to store the
data.
Advantages: Storage capacity is more compared to CDs.
Flash Drives (Pen drives): USB flash drives are removable, rewritable, and physically much smaller
drives weighing even less than 30 g. A flash drive consists of a small printed circuit board carrying the
circuit elements and a USB connector, insulated electrically and protected inside a plastic, metal, or
rubberized case which can be carried in a pocket or on a key chain.
Advantages
Data stored on flash drives is impervious to scratches and
dust Mechanically very robust
Easily portable
Have higher data capacity than any other removable media. Compared to
hard drives, flash drives use little power
Flash drives are small and light-weight devices
Flash drives can be used without installing device drivers.
Disadvantages
Can sustain only a limited number of write and erase cycles before the drive fails. Most
flash drives do not have a write-protect mechanism
Flash drives are very small devices that can easily be misplaced, left behind, or otherwCSE
lost. The cost per unit of storage in a flash drive is higher than that of hard disks
Keyboard: A keyboard is the primary input device used in all computers. Keyboard has a group of
switches resembling the keys on an ordinary typewriter machine. Normally keyboard has around 101
keys. The keyboard includes key that allows us to type letters, numbers and various special symbols such
as *, /, [, % etc.
Mouse: The mouse is the key input device to be used in a Graphical User Interface (GUI). The users can
use mouse to handle the cursor pointer easily on the screen to perform various functions like opening a
program or file.
With mouse, the users no longer need to memorize commands, which was earlier a necessity when
working with text-based command line environment such as MS-DOS.
Advantages:
Easy to use; Cheap; Can be used to quickly place the cursor anywhere on the screen Helps
to quickly and easily draw figures
Point and click capabilities makes it unnecessary to remember certain commands
Disadvantages:
Needs extra desk space to be placed and moved easily
The ball in the mechanical mouse needs to be cleaned very often for smooth movements
Printers: The printer is an output device, which is used to get hard copy of the text displayed on the
screen. The printer is an external optional device that is connected to the computer system using cables.
The printer driver software is required to make the printer working. The performance of a printer is
measured in terms of Dots Per Inch (DPI) and Pages Per Minute (PPM) produced by the printer.
Plotters: A plotter is similar to printer that produces hard-copy output with high-quality color graphics.
Plotters are generally more expensive than printers, ranging from about $1000 to $75000.
STEPS:
Step 1:[Initialize]
Start
Step 2: [Input the sides of Rectangle]
Read length, breadth
Step 3:[Compute the area of rectangle]
Area length*breadth
Step 4:[Display the Area]
Print Area
Step 5: [Finished]
Stop
Flowcharts: A flowchart is a graphical or symbolic representation of an algorithm. They are basically
used to design and develop complex programs to help the users to visualize the logic of the program so
that they can gain a better understanding of the program and find flaws, bottlenecks, and other less-
obvious features within it. Basically, a flowchart depicts the “flow” of a program. The following table
shows the symbols used in flowchart along with its descriptions.
Symbol Name Description
oval Represents the terminal point
Represents
Looping
Hexagon structures
Subroutine
Process function
Advantages of Flowcharts:
A flowchart is a diagrammatic representation that illustrates the sequence of steps that must be
performed to solve a problem. They are usually drawn in the early stages of formulating computer
solutions to facilitate communication between programmers and business people.
Flowcharts help programmers to understand the logic of complicated and lengthy problems. They
help to analyze the problem in a more effective manner
Flowchart can be used to debug programs that have error(s).
E.g.: To compute the Area of Rectangle
Limitations of using Flowcharts:
Drawing flowcharts is a laborious and a time consuming activity. Flowchart of a complex program
becomes, complex and clumsy. At times, a little bit of alteration in the solution may require complete re-
drawing of the flowchart Essentials of what is done may get lost in the technical details of how it is
done. There are no well-defined standards that limits the details that must be incorporated in a flowchart
start
Read length & breadth
Area = length * breadth
Print Area
Stop
Pseudo code: It is a form of structured English that describes algorithms. It facilitates the designers to
focus on the logic of the algorithm without getting bogged down by the details of language syntax.
Pseudocode is a compact and informal high-level description of an algorithm that uses the structural
conventions of a programming language. It is meant for human reading rather than machine reading, so it
omits the details that are not essential for humans. Such details include keywords, variable declarations,
system-specific code and subroutines. There are no standards defined for writing a pseudocode because it
is not an executable program. Flowcharts can be considered as a graphical alternative to pseudocode, but
are more spacious on paper.
E.g.: To compute the area of Rectangle
Begin
Input length, breadth
Area=length*breadth
Print Area
End
Familiarization with computer hardware and programming environment, concept of naming
the program files, storing, compilation, execution and debugging. Taking any simple C- code.
Step 1: Locate the TC.exe file and open it. You will find it at location C:\TC\BIN\.
Step 2: File > New (as shown in the below picture) and then write your C program
Step 3: Save the program using F2 (OR file > Save), remember the extension should be “.c”. In the
below screenshot I have given the name as summ.c.
Computer Programming Laboratory
Step 4: Compile the program using Alt + F9 OR Compile > Compile (as shown in the below screenshot).
Step 5: Press Ctrl + F9 to Run (or select Run > Run in menu bar ) the C program.
Step 6: Alt+F5 to view the output of the program at the output screen.
Develop a program to solve simple computational problems using arithmetic expressions and use
of each operator leading to simulation of a commercial calculator. (No built-in math function).
1.1 ALGORITHM
PURPOSE : To simulate a calculator using arithmetic expressions
INPUT: Enter num1 and num2
OUTPUT: Print the result of addition or subtraction or multiplication or division or modulus.
START
Step 1: [Enter first number]
read num1
Step 2: [Enter Second number]
read num2
Step 3:[Enter Choice]
read choice
Step 4:[To perform addition]
if choice is equal to plus
add num1 and num2
print result
Step 5: [To perform subtraction]
if choice is equal to minus
subtract num2 from num1
print result
Step 6: [To perform multiplication]
if choice is equal to multiplication
multiply num1 and num2
print result
Step 7: [To perform division]
If choice is equal to division
divide num1 by num2
print result
Step 8: [To perform Modulus]
if choice is equal to modulus
divide num1 by num2
print result (remainder)
STOP
START
Read choice
if choice=?
case '+'
result=num1+num2;
case '-'
result=num1-num2;
result=(float)num1/
case '/' (float)num2;
case '%'
result=num1%num2;
default
Invalid operation.
Result
STOP
1.3 PROGRAM
#include<stdio.h>
#include<math.h>
void main()
{
int ch,a,b;
float res;
printf(“Enter two number:\n”);
scanf(“%d%d”,&a,&b);
printf(“1=Add,2=Sub,3=Mul,4=div,5=Rem\n);
printf(“Enter your choice:\n”);
scanf(“%d”,&ch);
Switch(ch)
{
Case1: res=a+b;
break;
Case2: res=a-b;
break;
Case3: res=a*b;
break;
Case4: res=a/b;
break;
Case5: res=a%b;
break;
default:printf(“entered wrong choice\n”);
}
printf(“result=%f\n”,res);
}
***************************************************************************
OUTPUT 1:
Enter two number:
12 5
1=Add, 2=Sub, 3=Mul,4=Div,5=Res
Enter your choice:
1
Result=17.00000
OUTPUT 2:
Enter two number:
34 56
1=Add, 2=Sub,3=Mul,4=Div,5=Res
Enter your choice:
2
Result=22.00000
OUTPUT 3:
Enter two number:
23 53
1=Add, 2=Sub,3=Mul,4=Div,5=Res
Enter your choice:
3
Result=1219.000000
OUTPUT 4:
Enter two number :
22 7
1=Add, 2=Sub,3=Mul,4=Div,5=Res
Enter your choice:
4
Result=3.142857
OUTPUT 5:
Enter two number:
22 7
1=Add,2=Sub,3=Mul,4=Div,5=Res
Enter your choice:
5
Result=1.000000
******************************************************************************
VIVA QUESTIONS:
1) What is Switch statement?
2) How many cases can you have in switch statement?
3) How switch statement works?
4) What does break in switch statement indicate?
5) What is a case in a switch statement?
Laboratory Program 2
Develop a program to compute the roots of a quadratic equation by accepting the coefficients.
Print appropriate messages.
2.1 ALGORITHM
Purpose : To find roots of a given quadratic equation.
Input: Coefficients of quadratic equation a, b, c
Output: Root1 and Root2
START
STEP 1: [Input the values of a, b, c]
read a, b, c
STEP 2: [Calculate the determinant]
determinant = b*b-4*a*c
STEP 3: [Check for validity]
If a is equal to 0 and b is equal to 0
print “Invalid Inputs”
STEP 4: [Check for different roots]
If a is equal to 0
print “Linear equation”
Root1=-c/b
Print “Root1”
STEP 5: [Check for real and equal roots]
If determinant is equal to 0
print “Roots are real and equal”
Root1= -b/(2*a)
Root2 = -b/(2*a)
Print “Root1 & Root2”
STEP 6: [Check for real and distinct roots]
If determinant is greater than 0
Then print “Roots are real and distinct”
Root1= (-b+ (sqrt (fabs (determinant))))/(2*a)
Root2= (-b-(sqrt (fabs (determinant))))/(2*a)
Print “root1 and root2”
End if
STEP 7: [Check for imaginary roots]
print “Roots are imaginary”
Real=-b/ (2*a)
Imaginary=sqrt (fabs (determinant))/ (2*a)
print “Root1 and R oot2”
STEP 8: [Finished]
STOP
2.2 FLOWCHART
2.3 PROGRAM
#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
float a,b,c,root1,root2,rpart,ipart,disc;
scanf("%f%f%f",&a,&b,&c);
if((a*b*c)= =0)
{
printf("roots cannot be determined:\n");
exit(0);
}
disc=(b*b)-(4*a*c);
if(disc= =0)
{
printf("Roots are equal \n");
root1=root2=-b/ (2*a);
printf("root1=root2=%f",root1);
}
else if(disc>0)
{
printf("Roots are real and distinct \n");
root1=(-b+(sqrt(disc))/(2*a);
root2=(-b-(sqrt(disc))/(2*a);
printf("root1=%f\n root2=%f",root1,root2);
else
{
printf("Roots are complex \n");
rpart=-b/(2*a);
ipart=(sqrt(-disc))/(2*a);
printf("root1=%f+i%f\n",rpart,ipart);
printf("root2=%f-i%f\n",rpart,ipart);
getch();
}
******************************************************************************
Output 1:
Enter the 3 Co-efficient
123
Roots are complex
root=-1.000000+i1.414214
root=1.000000+i1.414214
Output 2:
Enter the 3 Co-efficient
121
Roots are equal
Root1=root2=1.00000
Output 3:
Enter the 3 Co-efficient
253
Roots are Real and distinct
Root1=-1.0000
Root2=-1.50000
******************************************************************************
Viva Questions:
1) What is quadratic Equation?
2) What is math.h?
3) What are decision making capabilities of C language?
4) Write the syntax of “ if ”statement?
5) Difference between if and switch statements?
6) Write an unconditional control statement in C.
7) Write a flowchart for „ if‟ conditional construct?
Laboratory Program 3
An electricity board charges the following rates for the use of electricity: for the first 200 units 80
paisa per unit: for the next 100 units 90 paise per unit: beyond 300 units Rs 1 per unit. All users are
charged a minimum of Rs. 100 as meter charge. If the total amount is more than Rs 400, then an
additional surcharge of 15% of total amount is charged. Write a program to read the name of the
user, number of units consumed and print out the charges.
3.1 ALGORITHM
PURPOSE: Read The Name Of The User, Number Of Units Consumed And Print
INPUT: Customer Name and Unit consumed
OUTPUT: Customer name, unit consumed and total amt to be paid
STEP 1: Start
STEP 2: Read the name of customer and the unit consumed by the customer
STEP3: Check if the unit consumed is greater than 1 and less than 200, if
true goto step 4 else goto step 5
Stop
3.3 PROGRAM
#include <stdio.h>
#include<stdlib.h>
void main()
{
char name[10];
float unit, amt;
printf("Enter your name and unit Consumed:");
scanf("%s %f", &name, &unit);
if(unit<=200)
amt= unit*0.80+100;
else if((unit>200) &&(unit<=300))
amt=200*0.80+((unit-200)*0.90)+100;
else
amt=200*0.80+100*0.90+((unit-300)*1)+100;
if(amt>400)
amt=1.15*amt;
printf("Name: %s\n unit:%f \n Charge: %f", name, unit, amt);
getch 0;
}
*****************************************
Output 1:
Enter your name and unit Consumed:
Suresh
100
Name: Suresh
unit : 100.00000
Charge : 180.000
Output 2:
Enter your name and unit Consumed:
Ramesh
350
Name: Ramesh
unit: 350.0000
Charge : 400.0000
Output 3:
Enter your name and unit Consumed:
Ramesh
400
Name: Ramesh
unit: 460.0000
Charge : 586.0000
******************************************************************************
Viva Questions:
Write a C program to display the following by reading the number of rows as Input
4.1 Algorithm
Step 1: Start
Step 2: Declare i,j,n
Step 3: Input no. of row
Step 4: for i=0;i<=n;i++
Do the following process
Step 4.1: for j=0;j<=i;j++
Print tabspace
Step 4.2: for j=1;j<=i;j++
Print j
Step 4.3: for j=-i1;j>=1;j--
Print j
Print new line
Step 5: Stop
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,n;
printf(“Input number of rows:”);
scanf(“%d”,&n);
for(i=0;i<=n;i++)
{
for(j=1;j<=n-i;j++)
{
printf(“\t”);
}
for(j=1;j<=i;j++)
{
printf(“%d\t”,j);
}
for(j=i-1;j>=1;j--)
{
printf(“%d\t”,j);
}
printf(“\n”);
}
getch();
}
Laboratory Program 5
5.1 ALGORITHM
Read n
For i=0 to n
Read a[i]
STEP 4: [Initiliazation]
low = 0;
high = n-1;
STEP 5: [ Check whearther low is less than of equal to high and calculate mid)
while low <=high
found=1
high = mid-1;
low = mid+1;
If not found
STEP 12:[Finished]
STOP
5.2 FLOWCHART
5.3 PROGRAM
#include <stdio.h>
void main()
{
int n ,a[100], i, key, high, low, high, mid, loc=-1 ;
printf("\n Enter the size of the array:\n");
scanf ("%d", &n);
printf (" Enter the elements of the array in sorted order\n”: ");
for(i=0;i<n;i++)
scanf(“%d”,&a[i]);
printf(" Enter the key element to be searched: \n" );
scanf ("%d", &key);
low = 0;
high = n-1;
while (low <=high)
{
mid= (low+ high)/2;
if (key = =a[mid])
{
loc=mid+1;
break;
}
else
{
if(key<a[mid])
high=mid-1;
else
low=mid+1;
}
}
if(loc>0)
printf(“\n the element %d is found at %d”,key,loc);
else
printf(“\n the search is unsuccessful”);
}
***************************************************************
Output 1:
Enter the size of the array:
5
Enter the elements of the array in sorted order:
10 20 30 40 50
Enter the key element to be searched:
30
The element 30 is found at 3
Output 2:
Enter the size of the array:
5
Enter the elements of the array in sorted order:
10 20 30 40 50
Enter the key element to be searched:
60
The search is unsuccessful
******************************************************************************
Viva Questions:
What is searching?
What are the types of searching?
Explain with an example for binary search.
Explain with an example for linear search.
Which is better searching technique?
Laboratory Program 6
Implement Matrix Multiplication and validate the rules of multiplication.
6.1 ALGORITHM
Step 1: Start
Step 2: [Enter the order of matrix A]
Read m,n
Step 3: [Enter the order of matrix B]
Read p,q
Step 4: [Check for matrix multiplication is possible or not]
If(n!=p)
Print “matrix multiplication not possible Exit if true
Terminate otherwise goto step7
Step 5: [Enter the elements of matrix A]
For i=0 to m, for j=0 to n
Read a[i][j]
Step 6: [Enter the elements of matrix B]
For i=0 to p, for j=0 to q
Read a[p][q]
Step 7: [Compute matrix multiplication]
For i=0 to m
If true compute the following steps otherwise goto step 8
For j=0 to q
If true compute the following steps otherwise increment the I loop
C[i][j]=0;
For(k=0;k<n;k++)
If true compute the following steps otherwise increment the j loop
C[i][j]+=a[i][k]*b[k][j];// Equation to compute
Multiplication
Step 8: [print the element of matrix ABC]
Print a[i][j],b[i][j],c[i][j]
Step 9: Stop
6.3 PROGRAM
#include<stdio.h>
#include <stdlib.h>
int main()
{
int m,n,p,q,row,col,k,a[3][3],b[3][3],c[3][3];
printf(“Enter the order of matrix A\n”);
scanf(“%d%d”,&m&n);
printf(“Enter the order of matrix B\n”);
scanf(“%d%d”,&p&q);
if(n!=p)
‘{
printf(“Matrix multiplication is not possible\n”);
exit(0);
}
printf(“Enter the elements into matrix A\n”);
for(row=0;row<m;row++)
{
for(col=0;col<n;col++)
{
scanf(“%d”,&a[row][col]);
}
}
printf(“Enter the elements into matrix B\n”);
for(row=0;row<p;row++)
{
for(col=0;col<q;col++)
{
scanf(“%d”,&b[row][col]);
}
}
for(row=0;row<m;row++)
{
for(col=0;col<q;col++)
{
c[row][col]=0;
for(k=0;k<n;k++)
{
c[row][col]=c[row][col]+a[row][k]*b[k][col];
}
}
}
printf(“the elements of matrix A are\n”);
for(row=0;row<m;row++)
{
for(col=0;col<n;col++)
{
printf(“%3d”,a[row][col]);
}
Printf(“\n”);
}
printf(“the elements of matrix B are\n”);
for(row=0;row<p;row++)
{
for(col=0;col<q;col++)
{
printf(“%3d”,b[row][col]);
}
Printf(“\n”);
}
Printf(“the product of Matrix A and B is \n”);
for(row=0;row<m;row++)
{
for(col=0;col<q;col++)
{
Printf(“%3d”,c[row][col]);
}
Printf(“\n”);
}
Retrun(0);
}
******************************************************************************
OUTPUT 1:
OUTPUT 2:
Enter the order of matrix A
2 3
Enter the order of matrix B
2 3
Matrix multiplication is not possible
******************************************************************************
VIVA QUESTION:
Develop a Program to compute Sin(x) using Taylor series approximation .Compare your result with the
built- in Library function. Print both the results with appropriate messages.
7.1 ALGORITHM
7.2 FLOWCHART
7.3 PROGRAM
#include<stdio.h>
#include<conio.h>
#include<math.h>
#define PI 3.142
int main( )
{
int i,degree;
float x,sum=0,term,num,deno;
printf(“Enter the value of degree”);
Scanf(“%d”,°ree)
X=degree*(PI/180);
Num=x;
Deno=1;
I=2;
do
{
Term=name/deno;
Num=-num*x*x;
Deno=deno*I*(I+1);
Sum=sum+term;
I=I+2;
}
While(fabs(term)>=0.00001);
Printf(“The sin of %d is %3f\n”,degree,sum);
Printf(“the sin of %d using built in function is %3f”,degree,sin(x));
Return();
}
************************************************************************
Output1:
Enter the value of degree
30
The sin of 30 is 0.500
using built in function sin(30)=0.500
Output 2:
Enter the value of degree
45
The sin of 45 is 0.707
using built in function sin(45)=0.707
Output 3:
Enter the value of degree
60
The sin of 60 is 0.866
using built in function sin(60)=0.866
************************************************************************
VIVA QUESTIONS:
1.What is a multi-dimensional array?
Laboratory Program 08
Develop a program to sort the given set of N numbers using Bubble sort.
8.1 ALGORITHM
ALGORITHM : Bubble sort
PURPOSE : Arranging the numbers in ascending order using bubble sort technique
INPUT : N, interger numbers in arrary a[i]
OUTPUT : Numbers are arranged in ascending order
START
STEP 1: [Input number of elements]
Read n
STEP 2: [Input the elements/numbers into array]
For i 0 to n
Read a[i]
Endfor
STEP 3 : [Sorting the elements in ascending order]
For j o to n-1
[Compare the adjacent elements]
If(a[j]>a[j+1]) then
[Swap these elements]
Temp a[j]
a[j] a[j+1]
a[j+1] temp
end if
end for
STEP 4: [Display the sorted elements of array]
For i 0 to n
Print a[i]
end for
STEP 5: [Finished]
STOP
8.2 FLOWCHART
8.3PROGRAM
#include<stdio.h>
#include<conio.h>
int main()
{
int n,i,j,a[10],temp;
clrscr();
printf("Enter the no. of elements :\n");
scanf("%d",&n);
printf("Enter the array elements \n”);
scanf("%d",&a[i]);
printf("The original elements are \n");
for(i = 0 ; i < n ; i++)
printf("%d ",a[i]);
for(i= 0 ; i < n-1 ; i++)
{
for(j= 1 ; j< n-j-1; j++)
{
if(a[j] > a[j+1])
{
temp = a[j];
a[j] = a[j+1];
a[j+1] = temp;
}
}
}
printf("\n The Sorted elements are \n");
for(i = 0 ; i < n ; i++)
printf("%d\t ",a[i]);
return 0;
}
******************************************************************************
Output 1:
Enter the no. of elements:
5
Enter the array elements
54321
The original elements are
The Sorted elements are 1 2 3 4 5
Output 1:
Enter the no. of elements:
2
Enter the array elements
4 2
The original elements are
The Sorted elements are 2 4
******************************************************************************
VIVA QUESTIONS:
1. Why the name bubble sort?
2. Mention the different types of sorting techniques?
3. Explain the logic of bubble sort with an example.
4. What is nested for loop?
Laboratory Program 9
Write functions to implement string operations such as compare, concatenate, string length.
Convince the parameter passing techniques.
9.1 ALGORITHM
Purpose: To find String length, Compare two Strings, Concatenate two strings
Concatenated String
START
increment i by 1
initialize i to 0
break;
increment i by 1
return str1[i]-str2[i];
initialize i to 0 and j to 0
increment i by 1
str1[i++]=str2[j++];
STOP
#include <stdio.h>
#include<conio.h>
#include<string.h>
int length(char s1[]);
int compare(char s1[],char s2[]);
void concate(char s1[],char s2[]);
int main()
{
char s1[200],s2[100];
int len,res,count;
printf(“\n Enter the string s1:”);
gets(s1);
printf(“\n Enter the string s2:”);
gets(s2);
len=Length(s1);
printf(“\n the length of the string s1 is %d”,len);
res=compare(s1,s2);
if(res==0)
{
Printf(“\n both the string are equal \n”);
}
Else
{
Printf(“\n the string are not equivalent \n”);
}
Concate(s1,s2);
Printf(“\n concated string is %s”, s1);
Return(0);
}
Int length(char s1[])
{
Int len=0;
While(s1[len]!=’\0’)
Len++;
Return(len);
}
Int compare(char s1[], char s2[]);
{
Int count=0;
While(s1[count]==s2[count])
{
If(s1[count]==’\0’||s2[count]==’\0’)
Break;
Else
Count++;
}
If(s1[count]==’\0’&&s2[count]==’\0’)
Return 0;
Else
Return-1;
}
Void concat(char s1[], char s2[])
{
Int I,j;
I=strlen(s1);
For(j=0;s2[j]!’\0’;i++,j++)
{
S1[i]=s2[j];
}
S1[i]=’\0’;
}
OUTPUT 1:
Enter the string s1:
data
Enter the string s2:
type
the length of the string s1 is
4
the string are not equivalent
concated string is datatype
OUTPUT 2:
Enter the string s1:
data
Enter the string s2:
data
the length of the string s1 is 4
both the string are equal
concated string is datadata
****************************************************************
VIVA QUESTIONS
1) What is string?
2) What are the built-in functions of string?
3) Difference between user defined functions and built in functions.
4) What is null character?
5) Explain the flow of program with example.
Laboratory Program 10
Implement structures to read, write, compute average- marks and the students scoring above and
below the average marks for a class of N students.
10.1 ALGORITHM
Algorithm: structures to read, write, compute average- marks
Step 1: Start
Step 2: Read the number of students
Step 3: For each student,read the student id, name and marks of all field
Step 4: Calculate the average of the marks and store in the avg field
Step 5:Print results
Step 6:Repeat
Read the average of each student
Check if avg>15.00
If yes print result else go to step 6
Step 7: Repeat’
Read average of each student
Check if avg<15.00
If yes
Print result else go to step 7
Step 8: stop
10.2FLOWCHART
10.3 PROGRAM
#include<stdio.h>
Struct student
{
Char usn[50];
Char name[50];
Int marks;
}
S[10];
Void main()
{
Int I,n,countav=0,countbv=0;
Float sum,average;
Clrscr();
Printf(“enter number of students \n”);
Scanf(“%d”,&n);
Printf(“enter information of students \n”);
For(i=0;i<n;i++)
{
Printf(“enter usn:”);
Scanf(“%s”,s[i].usn);
Printf(“enter name:”);
Scanf(“%s”,s[i].name);
Printf(“enter marks:”);
scanf (“%d”,&s[i].marks);
printf(“\n”);
}
Printf(‘displaying information:\n\n”);
For(i=0;i<n;i++)
{
Printf(“\n usn:%s\n”,s[i].usn);
Printf(“name:”);
Puts(s[i].name);
Printf(“marks:%d”,s[i].marks);
Printf(“\n”);
}
For(i=0;i<n;i++)
{
Sum=sum+s[i].marks;
}
Average=sum/n;
Printf(“\n average marks:%f”,average);
Countav=0;
Countbv=0;
For(i=0;i<n;i++)
{
If(s[i].marks>=average)
Countav++;
Else
Countbv++;
}
Printf(“\n total number of student above average=%d”,countav);
printf(“\n total number of student below average=%d”,countbv);
}
*****************************************************************************
OUTPUT 1:
enter number of students
3
enter information of students
enter usn:572
enter name: abc
enter marks:43
enter usn:896
enter name: xyz
enter marks: 65
enter usn:088
enter name: pqr
enter marks: 56
displaying information:
usn:572
name:abc
marks:43
usn:896
name:xyz
marks:65
usn:088
name:pqr
marks:56
average marks:54.6666
total number of student above average=2
total number of student above average=1
******************************************************************************
Laboratory Program 11
Develop a program using pointers to compute the sum, mean and standard deviation of all elements
stored in an array of n real numbers.
11.1 ALGORITHM
Algorithm
For i= 0 to n
increment ptr by 1
STEP 4: [Calculate mean]
mean=sum/n
STEP 5: [Calculate Standard deviation]
sumstd=sumstd + pow((*ptr - mean),2);
increment ptr by 1
std = sqrt(sumstd/n)
STEP 6:[Display output]
Print the sum,mean and standard deviation of all elements in an array
STOP
int n,i;
clrscr();
printf("Enter the no of elements\n");
scanf("%d",&n);
printf("Enter the array elements \n");
for(i=0;i<n;i++)
{
scanf("%f",&a[i]);
}
ptr=a;
for(i=0;i<n;i++)
{
sum=sum+ *ptr; ptr++;
}
mean=sum/n;
ptr=a;
for(i=0;i<n;i++)
{
sumstd=sumstd + pow((*ptr - mean),2);
ptr++;
}
std = sqrt(sumstd/n);
printf("Sum=%.3f\t",sum);
printf("Mean=%.3f\t",mean);
printf("Standard deviation=%.3f\t", std);
}
******************************************************************************
Output 1:
Enter the number of elements 5
Enter the array elements are 1 5 9 6 7
Sum=28
Mean=5.6
Standard deviation=2.09
******************************************************************************
Viva Questions:
1. Define pointer?
2. How do you declare a pointer variable?
3. What is * and & in pointer concept.
4. What are the advantages and disadvantages of using pointer?
5. Give the difference between static allocation and dynamic allocation of memory space.
6. What is the effect of the ++ and -- operators on pointer variable
7. Explain the pointers to arrays concept?
Laboratory Program 12
Write a C program to copy a text file to another, read both the input file name and
target file name.
12.1 FLOWCHART
12.3 PROGRAM
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
FILE *fp1,*fp2;
int ch;
char fname1[100], fname2[100];
printf("\nEnter File name to be copied\n");
scanf("%s",fname1);
fp1 = fopen(fname1,"r");
if(fp1 == NULL)
{
printf("\nInput File %s doesn’t exist\n", fname1);
exit(0);
}
printf("\nEnter target File name\n");
scanf("%s",fname2);
fp2 = fopen(fname2,"w");
while((ch=fgetc(fp1)) != EOF)
{
fputc(ch,fp2);
}
printf("\nFile %s successfully created\n",fname2);
fclose(fp1);
fclose(fp2);
return 0;
}
Output
Enter File name to be copied
out9.c
Enter target File name
out99.c
secret.txt