Vous êtes sur la page 1sur 56

MARTHANDAM COLLEGE OF ENGINEERING AND

TECHNOLOGY
COLLEGE ROAD, KUTTAKUZHI, VEEYANNOOR POST,

KANYAKUMARI DISTRICT – 629177

LABORATORY RECORD NOTE BOOK

NAME
: :

REGISTER NO :

DEPARTMENT :

SEMESTER & YEAR :

SUBJECT CODE & NAME :


MARTHANDAM COLLEGE OF ENGINEERING AND TECHNOLOGY
COLLEGE ROAD, KUTTAKUZHI, VEEYANNOOR POST,
KANYAKUMARI DISTRICT - 629177

BONAFIDE CERTIFICATE

Certified that this is a Bonafide Record of work done by …………..

………………………….……………………….. of the ………………. Year/semester in

………………………………………………… branch of this College in the

…………………………………… Laboratory during 2015-2016 in partial fulfillment of the

requirement of the B.E./B.Tech Degree course of the Anna University, Chennai.

Staff-In charge Head Of the Department

University Register Number: ………………………………….

Submitted for the University Practical Examination held on …………………….

Internal Examiner External Examiner


INDEX

Page
Ex No Date Name of the Experiment Sign
No

Search, Generate, And Manipulate Data Using MS Office / Open Office

1a Text Manipulation With Scientific Notations 1

1b Creating Advertisement 3

Presentation And Visualization – Graphs, Charts, 2D, 3D

2a Creating Spread Sheet Chart 5

2b Mark List Preparation Using Formulae 8

2c Simple Sorting Using Spreadsheet 10

Problem Formulation, Problem Solving And Flowcharts

3 Drawing Flowchart 12

4 Letter Preparation Using Mail Merge 18

C Programming Using Simple Statements And Expressions

5a Largest Among Three Numbers 21

5b Area And Circumference Of A Circle 22

5c Checking Leap Year 23

5d Menu Driven Calculator Program Using


24
Switch

Scientific Problem Solving Using Decision Making And Looping

6a Fibonacci Series 26

6b Finding Sum of Digits And Checking


28
Palindrome

6c Finding Prime Number 30


Simple Programming For One Dimensional And Two Dimensional Arrays

7a Matrix Addition and Subtraction 32

7b Matrix Multiplication 35

7c Sorting 37

Solving Problems Using String Functions

8 String Length and Concatenation 39

Programs With User Defined Functions – Includes Parameter Passing

9a Swapping 41

Function Without Arguments and No Return


9b 42
Value

Function With Arguments and No Return


9c 43
Value

9d Function With Arguments and Return Value 44

Function Without Arguments and With


9e 45
Return Value

Program Using Recursive Function

Factorial of a Given Number Using


10 46
Recursion

Program Using Structures And Unions

Displaying Marks of Students Using


11 a 48
Structure

11 b Program Using Union 51


Ex.No. 1(a)
Text Manipulation With Scientific Notations
01-09-2015

Aim

To create a document that includes some equations and text with bullets and
numbering in OpenOffice Writer.

Procedure

Equations and Formula Editing

1. Open a new document and type the equations.


2. Select the character that should be displayed as subscript or superscript.
3. Format  Character  Position then selects the subscript or superscript option
from the character dialog box and then select OK.
4. For typing mathematical formulas, click on Insert objectFormulatype the
equation.
5. Choose Element option in the View menu
6. In the elements choose the needed options such as brackets, formats and others.
7. Save the document.

Bullets and Numbering

1. Open a new document and type the text.


2. Select the text where you want to add Bullets
3. Choose Format  Bullets and numbering and choose the required bullets option.
4. Select the text where you want to add Numbering
5. Click Numbering button and choose the required Numbering.
6. Save the document.

1
Output

Equations and Formula Editing

Ca(HCO3 )2→CaCO3 +CO2 +H 2 O

− b± √b2 − 4ac
2a

2C2 H 2 (g )+ 7O2 (g )→4CO2 (g )+ 6H2 O

Bullets and Numbering

Civil Engineering
Computer Science and Engineering
Electrical and Electronics Engineering
Electronics and Communication Engineering
Information Technology
Mechanical Engineering

Result

The OpenOffice Writer document was created with equations and text with bullets
and numbering successfully and verified.

2
Ex.No. 1(b)
Creating Advertisement
01-09-2015

Aim

To create an advertisement about our college in OpenOffice Writer.

Procedure

1. Open a new document.


2. Place the different sized boxes in the document using table Inserttable.
3. Type the text in the boxes.
4. Fill the box with black color using background color in table menu.
5. Select the text where you want to add Bullets
6. Click format  bullet and numbering and choose the required bullets.
7. Save the document.

3
Output

Result

An advertisement about our college in OpenOffice Writer was created successfully


and verified.

4
Ex.No. 2(a)
Creating Spread Sheet Chart
09-09-2015

Aim

To generate different types of charts to analyze the marks of the students of a class
using OpenOffice Calc.

Procedure

1. Open a new OpenOffice Calc spreadsheet.


2. Enter the Student Name, Marks in the spreadsheet.
3. Find the total and average of marks by applying formulae.
4. For finding Total, place the cursor in F2 and type =SUM(C2:E2)
5. For finding Average, place the cursor in G2 and type =AVERAGE(C2: E2)
6. Copy the formulae to the remaining students.
7. To create a chart for the student marks, select the Name and Marks Columns Insert
Chart select the needed chart from chart wizard.
1. Choose the chart type after choosing click next.
2. Data Range is already selected so click next.
3. Data Series has also been selected so click next.
4. In the chart elements enter all the needed information such as Title, Subtitle, X
Axis, Y Axis and then click finish.
8. Repeat the same step for inserting other charts.

5
Output

Table in OpenOffice Calc

Sl.No Name Physics Chemistry Maths


1 Arvinth 46 78 89
2 Arjun 50 26 55
3 Arul 88 99 85
4 Anish 95 100 96
5 Alex 84 86 95

Charts

Column Chart

Mark Statement
2015-2016 ODD

120

100

80 Physics
Chemistry
Marks

60
Maths
40

20

0
Arvinth Arjun Arul Anish Alex
Student Names
Bar Chart

Mark Statement
2015-2016 ODD

Alex

Anish
Physics
Student Name

Chemistry
Arul
Maths
Arjun

Arvinth

0 20 40 60 80 100 120
Marks

6
Line Chart

Mark Statement
2015-2016 ODD

120

100

80 Physics
Chemistry
Marks

60
Maths
40

20

0
Arvinth Arjun Arul Anish Alex
Student Name
Net Chart
Mark Statement
2015-2016 ODD
Arvinth
100

50 Physics
Arjun Alex Chemistry
Marks

Maths
0

Arul Anish
Student Name

Result

The spreadsheet for generating different types of charts to analyze the marks of the
students of a class using OpenOffice Calc was created successfully and verified.

7
Ex.No. 2(b)
Mark List Preparation Using Formulae
09-09-2015

Aim

To prepare the Mark list of students by applying formulas using OpenOffice Calc.

Procedure

1. Open a new OpenOffice Calc spreadsheet.


2. Enter the Student Name, Marks in the spreadsheet.
3. Find the total and average of marks by applying formulae.
4. For finding Total, place the cursor in F2 and type =SUM(C2:E2)
5. For finding Average, place the cursor in G2 and type =AVERAGE(C2: E2)
6. Copy the formulae to the remaining students.

8
Output

Before entering the formulae

Sl.No Name Physics Chemistry Maths Sum Average


1 Arvinth 46 78 89
2 Arjun 50 26 55
3 Arul 88 99 85
4 Anish 95 100 96
5 Alex 84 86 95

After entering the formulae

Sl.No Name Physics Chemistry Maths Sum Average


1 Arvinth 46 78 89 213 71
2 Arjun 50 26 55 131 43.6666666667
3 Arul 88 99 85 272 90.6666666667
4 Anish 95 100 96 291 97
5 Alex 84 86 95 265 88.3333333333

Result

The spreadsheet for preparing the Mark list of students by applying formulas using
OpenOffice Calc was created successfully and verified.

9
Ex.No. 2(c)
Simple Sorting Using Spreadsheet
09-09-2015

Aim

To sort a set of names and numbers using OpenOffice Calc.

Procedure

1. Open a new OpenOffice Calc spreadsheet.


2. Type the list of names and mark randomly.
3. Select the Subject name. Select data  sort  in sort range select Ascending and
then click OK.
4. Save the spreadsheet.

10
Output

Before Sorting

Sl.No Name Physics


1 Arvinth 46
2 Arjun 50
3 Arul 88
4 Anish 95
5 Alex 84

Sorting Selection

After Sorting

Sl.No Name Physics


1 Anish 95
2 Arul 88
3 Alex 84
4 Arjun 50
5 Arvinth 46

Result

The spreadsheet for sorting a set of names and numbers using OpenOffice Calc was
created successfully and verified.

11
Ex.No. 3
Drawing Flowchart
16-09-2015

Aim

To create flowcharts in OpenOffice Writer.

Procedure

1. Open a new document OpenOffice Writer.


2. Select View  Toolbox  Drawing
3. From the drawing tools choose the flow chart symbols.
4. Select Symbols you want to insert and drag the symbols to the document.
5. Type the text in the Symbols, by selecting the symbol.
6. Use the Block Arrow button to draw the arrows connecting to the different flow chart
symbols.
7. Save the document.

12
Output

Flowchart for Largest of two numbers

START

Read a, b

Is a>b

Yes No

Print a Print b

STOP

13
Flowchart for Largest of three numbers

START

Read a, b, c

Is
a>b

Is Is
b>c a>c Yes

Yes No No

Print b Print c Print a

STOP

14
Flowchart for Factorial of a given number

START

Input N

Fact = 1

No Yes
For i=1 to
N

Fact = Fact * i
Print Fact

STOP

15
Flowchart for Area and Circumference of Circle

START

Input r

Print Area,
Circumference

STOP

16
Flowchart for finding Odd or Even number

START

Input n

Num=n%2

If Num==0

Print even Print Odd

STOP

Result

The document for creating flowcharts in OpenOffice Writer was created successfully
and verified.
17
Ex.No. 4
Letter Preparation Using Mail Merge

Aim

To create letters using mail merge option in OpenOffice Writer.

Procedure

Creating a Spreadsheet for a Data Source

1. Create a new empty OpenOffice Calc spreadsheet.


2. Type the data given in the table in the spreadsheet.
3. Save the spreadsheet in the name “mydataspreadsheet.ods”.
Title First Name Last Name Address Line 1 ZIP City
Dr. C.P. Jesuthanam Narayanaguru College of Engineering 629151 Manjalumoodu
Dr. T.R. Sethuraman Sivaji College of Engineering and Technology 695504 Manivilai
Dr. S. Joseph Sekar St. Xaviers Catholic College of Engineering 629003 Chunkankadai

Creating Mail merge

1. Open a new document with File  New  Text Document.


2. Start the Mail Merge wizard using Tools  Mail Merge Wizard.
3. Select Use the current document and click Next.
4. Select Letter and click Next.
5. Insert address block.
a. Click Select different address list. Select Add button.
b. In the opened window select the Spreadsheet which has been created. The data
source is the "mydataspreadsheet.ods" spreadsheet created earlier. Then click
OK.
c. Select the address block to use in the document.
6. Create salutation of the document. Adjust layout if needed.
7. In Edit document, the document letter can be created by inserting the needed subjects.
8. Click the Edit individual Document button to edit the document.
9. The merged document can now be saved by selection of save merged document. This
will reveal the Save merged document settings section, from which you can select to
save either as one large file containing all the individual, generated letters or as a
separate file for each letter.

18
Output

From

The Staff Coordinator,


Marthandam College of Engineering and Technology,
Kuttakuzhi.
629177

To

Dr.C.P.Jesuthanam,
Narayanaguru College of Engineering,
Manjalumoodu.
629151

Dear Sir,

We are organizing a national level conference, Innovation in computers’15,


NCIC’15 on 20th of October 2015. You are cordially invited to participate in the Conference
and that will be held in our college itself. We sincerely hope that you will join us in making
NCIC’15 a success.

Thanking you,

Station: Kuttakuzhi. Yours faithfully,


Date:
Staff Coordinator
NCIC ‟15

19
From

The Staff Coordinator,


Marthandam College of Engineering and Technology,
Kuttakuzhi.
629177

To

Dr.T.R.Sethuraman,
Sivaji College of Engineering and Technology,
Manivilai.
695504

Dear Sir,

We are organizing a national level conference, Innovation in computers’15,


NCIC’15 on 20th of October 2015. You are cordially invited to participate in the Conference
and that will be held in our college itself. We sincerely hope that you will join us in making
NCIC’15 a success.

Thanking you,

Station: Kuttakuzhi. Yours faithfully,


Date:
Staff Coordinator
NCIC ‟15

Result

The document for creating letters using mail merge option in OpenOffice Writer was
created successfully and verified.

20
PROCEDURE TO EXECUTE THE C PROGRAM IN LINUX
1. Create a folder in Documents. [ex : GE6161]
2. Open the folder. [ex : GE6161]
3. Right Click in the folder and create a new file as filename.c [ex : largest.c]
4. After creating the file, type the program in the file and save.
5. After saving the file you have to execute the file C program.
6. To execute the file navigate to the Terminal command line from Application menu.
7. In the terminal menu input the commands.
cd Documents
Then press the Enter key.
cd GE6161
Then press the Enter key.
8. To Compile the program use the command:
gcc –o <filename> <filename.c> [ex: gcc –o largest largest.c]
If any errors are there in the program the error message will be displayed else the
command line will be displayed.
9. To execute / run the program:
./filename [ex: ./largest]
10. The output will be displayed in the terminal command line.

21
Ex.No. 5(a)
Largest Among Three Numbers

Aim
To write a program to find the largest among three given numbers.

Algorithm

Step-1: Start the program.


Step-2: Declare the necessary variables.
Step-3: CHECK IF ((a > b && a > c)
Step-3.1: Print A.
Step-4: Otherwise, check if (b>c)
Step-4.1: Print B
Step-5: else print C
Step-6: Stop
Program

#include<stdio.h>
main()
{
int a,b,c;
printf("Enter the three numbers:\n");
scanf("%d%d%d",&a,&b,&c);
if((a>b)&&(a>c))
{
printf("%d is the largest number",a);
}
else if(b>c)
{
printf("%d is the largest number",b);
}
else
{
printf("%d is the largest number",c);
}
}

Output

Enter the three numbers: 8 9 5


9 is the largest number
Result
The program to find the largest among three given numbers was written and executed.
22
Ex.No. 5(b)
Area And Circumference Of A Circle

Aim

To write a program to find the area and circumference of a circle.

Algorithm

Step-1: Start the program.


Step-2: Declare the necessary variables and read r.
Step-3: Find area and circumference of the circle using the formulae
Area=3.14*r*r
Circumference=2*3.14*r;
Step-4: Print the area and circumference of the circle.
Step-5: Stop.

Program

#include<stdio.h>
main()
{
float r,area,circum;
printf("\nEnter the radius of the circle:");
scanf("%f",&r);
area=3.14*r*r;
circum=2*3.14*r;
printf("\nArea=%f\n",area);
printf("\nCircumference=%f\n",circum);
}

Output

Enter the radius of the circle: 3


Area=28.260000
Circumference=18.840000

Result

The program to find the area and circumference of a circle was written and executed.

23
Ex.No. 5(c)
Checking Leap Year

Aim

To write a program to find whether the given year is leap year or not.

Algorithm

Step-1: Start the program.


Step-2: Declare the required variable in the necessary data type;
Step-3: Read the year value.
Step-4: Execute the following condition.
if(ye%4==0)
Display it is a leap year
else
Display it is not a leap year
Step-5: Stop the program.

Program

#include<stdio.h>
main()
{
int ye;
printf("Enter the year ");
scanf("%d",&ye);
if(ye%4==0)
printf("It is a leap year\n");
else
printf("It is not a leap year\n");
}

Output
Enter the year 2016
It is a leap year
Enter the year 2015
It is not a leap year
Result

The program to find whether the given year is leap year or not was written and
executed.

24
Ex.No. 5(d)
Menu Driven Calculator Program Using Switch

Aim

To write a program for menu driven calculator using switch statement.

Algorithm

Step 1: Start the program


Step 2: Declare the necessary variable needed.
Step 3: Display a menu using printf() function.
1. Addition
2. Subtraction
3. Multiplication
4. Division
Step 4: Get two values a and b from user.
Step 5: Get the choice n from which mentioned in the menu.
Step 6: If the choice is 1. It performs addition.
Step 7: If the choice is 2. It performs subtraction.
Step 8: If the choice is 3. It performs multiplication.
Step 9: If the choice is 4. It performs division.
Step 10: If the choice is 5. Exit from program.

Program

#include<stdio.h>
void main()
{
int a,b,sum,sub,mul,div,n;
printf("Enter the values of a and b\n");
scanf("%d%d",&a,&b);
printf("1.Addition\n2.Subtration\n3.Multiplication\n4.Division");
printf("Enter your choice : ");
scanf("%d",&n);
switch(n)
{
case 1:
sum=a+b;
printf("Addition is: %d",sum);
break;
case 2:
sub=a-b;
printf("Subtraction is:%d",sub);
break;
case 3:
mul=a*b;
printf("Multiplication is:%d",mul);
25
break;
case 4:
div=a/b;
printf("Division is:%d",div);
break;
default:
printf("invalid choice");
break;
}
}

Output

Enter the values of a and b


6
5

1. Addition
2. Subtraction
3. Multiplication
4. Division

Enter your choice: 1


Addition is: 11

Enter the values of a and b


6
5

1. Addition
2. Subtraction
3. Multiplication
4. Division

Enter your choice: 2


Subtraction is: 1

Result

The program for menu driven calculator using switch statement was written and
executed.
26
Ex.No. 6(a)
Fibonacci Series

Aim

To write a program to generate the Fibonacci series.

Algorithm

Step-1:Start
Step-2:Read the input variable „n‟
Step-3:Call function fib(n)
Step-4:Stop.

Program

#include<stdio.h>
void main()
{
int num,fib=0,a=0,b=1,i;
printf("Enter the number\n");
scanf("%d",&num);
printf("\n Fibonacci Series\n");
if(num==0)
printf("0");
else
{
for(i=0;i<num;i++)
{
fib=fib+a;
a=b;
b=fib;
printf("%d\n",fib);
}
}
}

27
Output

Enter the number


5

Fibonacci Series
0
1
1
2
3

Result

The program to generate the Fibonacci series was written and executed.

28
Ex.No. 6(b)
Finding Sum of Digits And Checking Palindrome

Aim

To write a program to find the sum of digits and checking palindrome.

Algorithm

Step-1: Start
Step-2: Read the input values
Step-3: check the while condition
Step-4: print the output
Step-5: Stop.

Program

#include<stdio.h>
main()
{
unsigned long int a,num,sum=0,rnum=0,rem;
printf("\nEnter the number...");
scanf("%ld",&num);
a=num;
while(num!=0)
{
rem=num%10;
sum=sum+rem;
rnum=rnum*10+rem;
num=num/10;
}
printf("\nThe sum of the digits of %ld is %ld\n",a,sum);
printf("\nThe reverse of the number %ld is %ld\n",a,rnum);
if(a==rnum)
printf("\nThe given number is a palindrome\n");
else
printf("\nThe given number is not a palindrome\n");
}

29
Output

Enter the number...5858


The sum of the digits of 5858 is 26
The reverse of the number 5858 is 8585
The given number is not a palindrome

Result

The program to find the sum of digits and checking palindrome was written and
executed.
30
Ex.No. 6(c)
Finding Prime Number

Aim

To write a program to find the given number is prime or not.

Algorithm

Step-1: Start
Step-2: Assign i=2
Step-3: Read the num values
Step-4: check the condition (num%i=0) means not prime
Step 5: if(i==num) means print prime
Step-6: Stop.

Program

#include<stdio.h>
main()
{
int num,i=2;
printf("Enter the number...");
scanf("%d",&num);
while(i<=num-1)
{
if(num%i==0)
{
printf("The given number is not a prime number\n");
break;
}
i++;
}
if(i==num)
printf("The given number is a prime\n");
}

31
Output

Enter the number...44


The given number is not a prime number
Enter the number...11
The given number is a prime

Result

The program to find the given number is prime or not was written and executed.

32
Ex.No. 7(a)
Matrix Addition and Subtraction

Aim

To write a program to perform matrix addition and subtraction.

Algorithm

Step-1: Start the program.


Step-2: Declare the necessary variables.
Step-3: Set a loop to get A matrix.
Step-4: Read A matrix value
Step-5: Set a loop to get B matrix.
Step-6: Read B matrix value.
Step-7: c[i][j] = a[i][j] + b[i][j]
c[i][j] = a[i][j] - b[i][j]
Step-8: Set a loop to print the addition and subtraction matrix value.
Step-9: Stop the program.

Program

#include<stdio.h>
void main()
{
int a[25][25],b[25][25],c[25][25], d[25][25],i,j,m,n;
printf("Enter the rows and columns of two matrixes..\n");
scanf("%d %d",&m,&n);
printf("\nEnter the elements of A matrix...\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
}
printf("\nEnter the elements of B matrix..\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
scanf("%d",&b[i][j]);
}
printf("\nThe elements of A matrix");
for(i=0;i<m;i++)
{

33
printf("\n");
for(j=0;j<n;j++)
printf("\t%d",a[i][j]);
}
printf("\nThe elements of B matrix");
for(i=0;i<m;i++)
{
printf("\n");
for(j=0;j<n;j++)
printf("\t%d",b[i][j]);
}
printf("\nThe addition of two matrixes");
for(i=0;i<m;i++)
{
printf("\n");
for(j=0;j<n;j++)
{
c[i][j]=a[i][j]+b[i][j];
printf("\t%d",c[i][j]);
}
}
{
printf("\nThe subtraction of two matrixes");
for(i=0;i<m;i++)
{
printf("\n");
for(j=0;j<n;j++)
{
d[i][j]=a[i][j]-b[i][j];
printf("\t%d",d[i][j]);
}
}
}
}

34
Output

Enter the rows and columns of two matrixes..


2
2

Enter the elements of A matrix...


1
2
3
4

Enter the elements of B matrix..


5
6
7
8

The elements of A matrix


1 2
3 4
The elements of B matrix
5 6
7 8
The addition of two matrixes
6 8
10 12
The subtraction of two matrixes
-4 -4
-4 -4

Result

The program to perform matrix addition and subtraction was written and executed.

35
Ex.No. 7(b)
Matrix Multiplication

Aim

To write a program to perform matrix multiplication.

Algorithm

Step-1: Start the program.


Step-2: Declare the necessary variables.
Step-3: Set a loop to get A matrix.
Step-4: Read A matrix value
Step-5: Set a loop to get B matrix.
Step-6: Read B matrix value.
Step-7: Assign c[i][j]=0,Using this formula to calculate the multiplication matrix
c[i][j] = c[i][j] + a[i][k] * b[k][j].
Step-8: Set a loop to print the multiplication matrix value.
Step-9: Stop the program.

Program

#include<stdio.h>
void main()
{
int a[10][10],b[10][10],d[10][10];
int i,j,p,q,m,n,k;
printf("Enter size of the A matrix\n");
scanf("%d%d",&p,&q);
printf("Enter size of the B matrix\n");
scanf("%d%d",&m,&n);
if(p==n)
{
printf("Enter the elements of A matrix.\n ");
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
scanf("%d",&a[i][j]);
}
printf("Enter elements of B matrix. \n ");
for(i=0;i<m;i++)
{
for(j=0;j<m;j++)
36
scanf("%d",&b[i][j]);
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
d[i][j]=0;
for(k=0;k<p;k++)
d[i][j]=d[i][j]+a[i][k]*b[k][j];
}
}
printf("Multiplication of A and B matrix:\n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
printf("%5d ",d[i][j]);
printf("\n");
}
}
else
printf("The no.of rows and columns should not be equal");
}

Output

Enter size of the A matrix


2
2
Enter size of the B matrix
2
2
Enter the elements of A matrix.
1
2
3
4
Enter elements of B matrix.
5
6
7
8
Multiplication of A and B matrix:

19 22
43 50

Result

The program to perform matrix multiplication was written and executed.

37
Ex.No. 7(c)
Sorting

Aim

To write a program to sort a given set of numbers in ascending and descending order.

Algorithm

Step-1: Start
Step-2: Read the input values num, no, i, j
Step-3: Repeat for i=0 to no
Step-4: Repeat for j=i+1 to no
Step-5: Check whether the condition num[i] < num[j]
Step-6: Repeat for i=0 to no, print ascending order
Step-7: Repeat for j=n0-1 to 0, print descending order
Step-8: Stop.

Program

#include<stdio.h>
main()
{
int num[100],no,i,j,a;
printf("Enter upper limit....");
scanf("%d",&no);
printf("Enter the numbers\n");
for(i=0;i<no;i++)
scanf("%d",&num[i]);
for(i=0;i<no-1;i++)
{
for(j=i+1;j<no;j++)
{
if(num[i]<num[j])
{
a=num[i];
num[i]=num[j];
num[j]=a;
}
}
}
printf("\nThe ascending order of the given numbers");
for(i=0;i<no;i++)
printf("\n%d",num[i]);

38
printf("\n The descending number of the given numbers");
for(j=no-1;j>=0;j--)
printf("\n%d",num[j]);
}

Output

Enter upper limit....2

Enter the numbers


3
6

The ascending order of the given numbers


6
3

The descending number of the given numbers


3
6

Result

The program to sort a given set of numbers in ascending and descending order was
written and executed.
39
Ex.No. 8
String Length and Concatenation

Aim

To write a program to find the string length and concatenation of string.

Algorithm

Start 1: Start the program.


Start 2: Get the first string.
Start 3: Get the second string.
Start 4: Using strcat() function combine the two strings.
Start 5: Using strlen() function find the length of the two strings.
Start 6: Stop the program.

Program

#include <stdio.h>
#include <string.h>
int main()
{
char a[1000], b[1000];
int length;
printf("Enter the first string\n");
scanf("%s",a);
length = strlen(a);
printf("Length of entered string is = %d\n",length);
printf("Enter the second string\n");
scanf("%s",b);
length = strlen(b);
printf("Length of entered string is = %d\n",length);
strcat(a,b);
printf("String obtained on concatenation is %s\n",a);
return 0;
}

40
Output

Enter the first string


Computer
Length of entered string is = 8

Enter the second string


Programming
Length of entered string is = 11

String obtained on concatenation is ComputerProgramming

Result

The program to find the string length and concatenation of string was written and
executed.
41
Ex.No. 9(a)
Swapping

Aim

To write a program to swap two numbers using functions.

Algorithm

Start 1: Declare the two pointer variables.


Start 2: Get the value for both the variables.
Start 3: Swap the values.
Start 4: Print the result.
Program

#include<stdio.h>
main()
{
int x,y;
printf("\nEnter the two number ...\n");
scanf("%d%d",&x,&y);
printf("\nThe entered number for x and y are, x=%d\ty=%d",x,y);
display(&x,&y);
printf("\nAfter the swapping the value of, x=%d\ty=%d\n",x,y);
}
display(int *a,int *b)
{
int t;
t=*a;
*a=*b;
*b=t;
}

Output

Enter the two number ...


5
6
The entered number for x and y are, x=5 y=6
After the swapping the value of, x=6 y=5

Result

The program to swap two numbers using functions was written and executed.

42
Ex.No. 9(b)
Function Without Arguments and No Return Value

Aim

To write a program to illustrate function without arguments and no return value.

Algorithm

Step 1: Start the program


Step 2: Declare the string.
Step 3: Read the string value
Step 4: Print the string value.
Program

#include<stdio.h>
void main()
{
void message(void);
message();
}
void message()
{
char str[100];
printf("\nEnter A String..");
scanf("%s", str);
printf("The Given String Is:%s", str);

Output

Enter A String..MACET
The Given String Is:MACET

Result

The program to illustrate function without arguments and no return value was written
and executed.
43
Ex.No. 9(c)
Function With Arguments and No Return Value
01-09-2015

Aim

To write a program to illustrate function with arguments and no return value

Algorithm

Step 1: Start the program


Step 2: Declare a, b.
Step 3: Read a, b values
Step 4: Add a and b values and store to c using add function
Step 5: Print c value
Program

#include<stdio.h>
void main()
{
int a,b;
printf("\nENTER TWO NUMBERS....\n");
scanf("%d%d",&a,&b);
add(a,b);
}
add(int a, int b)
{
int c;
c=a+b;
printf("%d+%d=%d",a,b,c);
}

Output

ENTER TWO NUMBERS....


8
9
8+9=17

Result

The program to illustrate function with arguments and no return value was
written and executed.

44
Ex.No. 9(d)
Function With Arguments and Return Value
01-09-2015

Aim

To write a program to illustrate function with arguments and return value

Algorithm

Step 1: Start the program.


Step 2: Declare the necessary variables.
Step 3: Get the number from user to find the factorial.
Step 4: Write a user defined function for factorial using the formula n*fact (n-1).
Step 5: Print the factorial of the given number.
Step 6: Stop the program.
Program

#include<stdio.h>
void main()
{
int num,a;
printf("\nEnter the Number:");
scanf("%d",&num);
a=recur(num);
printf("The Factorial of the number %d is:%d",num,a);
}
recur(int no)
{
int fact=1;
if(no==1)
return(1);
else
fact=no*recur(no-1);
}

Output

Enter the Number: 5


The Factorial of the number 5 is: 120

Result

The program to illustrate function with arguments and return value was written and
executed.
45
Ex.No. 9(e)
Function Without Arguments and With Return Value
01-09-2015

Aim

To write a program to illustrate function without arguments and with return value

Algorithm

Step 1: Start the program


Step 2: Declare l, str1, len.
Step 3: l is assigned to the function strf()
Step 4: Read the str1 value.
Step 5: Find the given string length using strlen function
Step 6: Print the length
Program

#include<stdio.h>
#include<string.h>
void main()
{
int l;
int strf();
l=strf();
printf("\nThe given string length is:%d",l);
}
int strf()
{
char str1[100];
int len;
printf("\nEnter the string....");
scanf("%s",str1);
return(len=strlen(str1));
}

Output

Enter the string....Programming


The given string length is: 11

Result

The program to illustrate function with arguments and with return value was
written and executed.

46
Ex.No. 10
Factorial of a Given Number Using Recursion
01-09-2015

Aim

To write a program to find the factorial of a given number using recursion.

Algorithm

Step 1: Start the program.


Step 2: Declare the necessary variables.
Step 3: Get the number from user to find the factorial.
Step 4: Write a user defined function for factorial using the formula n*factorial(n-1).
Step 5: Print the factorial of the given number.
Step 6: Stop the program.
Program

#include<stdio.h>
long factorial(int);
int main()
{
int n;
long f;
printf("Enter an integer to find factorial\n");
scanf("%d", &n);
if (n < 0)
printf("Negative integers are not allowed.\n");
else
{
f = factorial(n);
printf("%d! = %ld\n", n, f);
}
return 0;
}
long factorial(int n)
{
if (n == 0)
return 1;
else
return(n * factorial(n-1));
}

47
Output

Enter an integer to find factorial


8
8! = 40320

Enter an integer to find factorial


5
5! = 120

Result

The program to find the factorial of a given number using recursion was written and
executed.
48
Ex.No. 11(a)
Displaying Marks of Students Using Structure
01-09-2015

Aim

To write a program to display the marks of students using structure.

Algorithm

Step 1: Start the program.


Step 2: Defining the structure student with members.
Step 3: Declare the necessary variables.
Step 4: Set a loop to get the details of student mark list
Step 5: Read the student details.
Step 6: Total the marks, and to calculate the average of students mark.
Step 7: Check the conditions.
Step 8: Set a loop to print the mark list
Step 9: Stop.

49
Program

#include<stdio.h>
struct student
{
int rno;
char name[10];
int m1,m2,tot;
float avg;
};
void main()
{
struct student s[10];
int n,i;
printf("Enter the no of student : ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("For %d student\n",i+1);
printf("Enter the rno of student : ");
scanf("%d",&s[i].rno);
printf("Enter the name of student : ");
scanf("%s",s[i].name);
printf("Enter the mark1 of student : ");
scanf("%d",&s[i].m1);
printf("Enter the mark2 of student : ");
scanf("%d",&s[i].m2);
}
for(i=0;i<n;i++)
{
s[i].tot=s[i].m1+s[i].m2;
s[i].avg=s[i].tot/2;
}
printf("\n\nDisplaying information of students :: ");
printf("\nRoll No\tName\tMark 1 \tMark 2\tTotal\tAverage");
for(i=0;i<n;i++)
{
printf("\n%d\t%s\t%d\t%d\t%d\t%f\t",s[i].rno,s[i].name,s[i].m1,s[i].m2,s[i].tot,s[i].av
g);
}
}

50
Output

Enter the no of student : 5

For 1 student
Enter the rno of student : 1
Enter the name of student : Arvind
Enter the mark1 of student : 55
Enter the mark2 of student : 66

For 2 student
Enter the rno of student : 2
Enter the name of student : Arun
Enter the mark1 of student : 45
Enter the mark2 of student : 89

For 3 student
Enter the rno of student : 3
Enter the name of student : Raja
Enter the mark1 of student : 78
Enter the mark2 of student : 89

For 4 student
Enter the rno of student : 4
Enter the name of student : Ramesh
Enter the mark1 of student : 59
Enter the mark2 of student : 89

For 5 student
Enter the rno of student : 5
Enter the name of student : Vishal
Enter the mark1 of student : 92
Enter the mark2 of student : 96

Displaying information of students ::

Roll No Name Mark 1 Mark 2 Total Average


1 Arvind 55 66 121 60.000000
2 Arun 45 89 134 67.000000
3 Raja 78 89 167 83.000000
4 Ramesh 59 89 148 74.000000
5 Vishal 92 96 188 94.000000

Result

The program to display the marks of students using structure was written and
executed.

51
Ex.No. 11(b)
Program Using Union
01-09-2015

Aim

To write a program using union.

Algorithm

Step 1: Start the program.


Step 2: Defining the union name with members.
Step 3: Declare the necessary variables.
Step 4: print c.a and c.b[0] , c.b[1] memory location values
Step 5: Stop.
Program

#include <stdio.h>
union item
{
int a;
float b;
char ch;
};
int main( )
{
union item it;
it.a =1101004922;
it.b = 20.000233;
it.ch='z';
printf("%d\n",it.a);
printf("%f\n",it.b);
printf("%c\n",it.ch);
return 0;
}

Output

1101004922
20.000233
z

Result

The program using union was written and executed.

52

Vous aimerez peut-être aussi