cp lab manual - updated with cbts

96
MS-WORD 1

Upload: mskumarme

Post on 30-Jan-2016

23 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CP Lab Manual - Updated With CBTS

MS-WORD

1

Page 2: CP Lab Manual - Updated With CBTS

SEARCH, GENERATE, AND MANIPULATE DATA USING MS

OFFICE / OPEN OFFICE

Ex No: 1(a) RESUME PREPARATION

Date :

AIM To prepare a resume using Microsoft Office Word.

ALGORITHM

Step 1: Start the Application

Step 2: Open the New Document (ctrl key + n).

Step 3: Enter the details of name, qualification, address, Hobbies etc.

Step 4: Align the document by using the alignment tools.

Step 5: Set the proper font size, Spacing, Line width etc.

Step 6: Save the document FILE SAVE (ctrl key + s) and press OK. While saving select

the particular place like desktop or local disk C:

Step 7: Close the Application.

2

Page 3: CP Lab Manual - Updated With CBTS

OUTPUT

CURICULUM VITAE Name: XXXXXXX PH: 0000000000000 Email-id: [email protected] ZZZZZZZZZ YYYYYYY RRRRRRRR

Career Objective Aspiring to build a leading corporate of I-tech environment with committed

and dedicated people which will help me to explore myself fully and realize my potential Educational Profile

12th

Standard, first class with 80% from St. Peters school Kodaikanal in the period of 2008-2009

10th

Standard, first class with 95% from Bhavans Vidyashram School Kodaikanal in the period of 2006-2007

Strength Ability to give qualitative output with presenting and cope up with the workload Ability to work under pressure, stress, and meet deadlines Ability to work in a team with high level of involvement

Skill Set

Languages : Visual Basic, Java RDBMS : Oracle, MS Access, Sql Server 2005

.Net Technologies : Asp.Net, vb.Net

Platforms : Windows 9.x, XP, Vista, Linux, Solaris

Others : HTML (Dreamweaver), Basic JavaScript, Flash

Personal Details

Name : XXXXXXX

Fathers Name : EEEEEEEE

Date of Birth : 18-08-1992

Marital Status : Unmarried

Languages Known : English, Tamil, Malayalam

Declaration I hereby declare that the above particulars given by me are true to the best of my

knowledge.

XXXXXXX

RESULT Thus the resume has been prepared using Microsoft Office Word and the output was

verified successfully.

3

Page 4: CP Lab Manual - Updated With CBTS

Ex No: 1(b) TIME TABLE PREPARATION

Date :

AIM

To prepare the time table using Microsoft Office Word.

ALGORITHM

Step 1: Start the Application

Step 2: Open the New Document.

Step 3: Click on the TABLE INSERT TABLE.

Step 4: Now the insert table dialog box is opened.

Step 5: Choose number of columns and rows.

Step 6: Auto format the table if necessary.

Step 7: Click OK.

Step 8: Enter the data’s in the appropriate boxes, by right click and then ADDTEXT.

Step 9: Align the table, set the font size etc..

Step 10: Save the document FILE SAVE and press OK.

Step 11: Close the Application.

4

Page 5: CP Lab Manual - Updated With CBTS

OUTPUT

TIME TABLE

DAY I II III IV V VI VII

Mon Eng Che Phy F.O.C BR

EA

KL

UN

CH

Engg. Graphics

INT

ER

VA

L

Tue F.O.C Mat Mat Eng C.P. Lab

Wed Phy Engg. Graphics F.O.C Che Mat

Thu Mat Phy/Che Lab Che Phy F.O.C

Fri Che

Mat

Eng Phy Engg. Practice Lab

Sat Phy Eng Mat Che F.O.C Che Phy

RESULT Thus the time table was prepared by using Microsoft Office Word and output was

verified.

5

Page 6: CP Lab Manual - Updated With CBTS

Ex No: 1(c) TABLE CONVERSION

Date :

AIM

To convert Text to Table by using Microsoft Office Word.

ALGORITHM

Step 1: Start the Application

Step 2: Open the New Document.

Step 3: Select the text, which we want to put in a table.

Step 4: Then, choose Table convert Text to Table option.

Step 5: Now the Convert Text to Table dialog box appears.

Step 6: Specify the Number of Columns and Separate text at option as Tabs, then click Ok to

convert the tabular text to a table.

Step 7: Gridlines are displayed to show the boundaries between rows and columns.

Step 8: Drag the columns width with the mouse to read just the column widths visually.

Step 9: Note that the column separator is a tab. We must be consistent in the way that we use

tabs.

Step 10: Save the document FILE SAVE and press OK.

Step 11: Close the Application.

6

Page 7: CP Lab Manual - Updated With CBTS

OUTPUT

S.No, Subject code, Subject, Name of Faculty 1., ENG, Technical English-1, Dr. G. Shanmugasundaram 2., MAT, Mathematics-1, Mrs. N. Manonmani 3., PHY, Engineering Physics-1, Mr. K. Senthilkumar 4., CHE, Engineering Chemistry-1, Mrs. G. Latha 5., FOC, Fundamentals of Computing and Programming, Mr. R. Lenin Babu

S.No Subject code Subject Name of Faculty

1. ENG Technical English-1 Dr. G. Shanmugasundaram

2. MAT Mathematics-1 Mrs. N. Manonmani

3. PHY Engineering Physics-1 Mr. K. Senthilkumar

4. CHE Engineering Chemistry-1 Mrs. G. Latha

5. FOC

Fundamentals of

Computing and

Programming

Mr. R. Lenin Babu

RESULT

Thus the Text was converted to a Table using Microsoft Office Word and the output was verified.

7

Page 8: CP Lab Manual - Updated With CBTS

Ex No: 1(d) ADVERTISEMENT

Date:

Design the advertisement for our college in Microsoft word file by applying all styles like bold, italic, underlines, colour fonts, bulletins, word art, and tables, line spacing.

AIM: To design the advertisement for a college in MS-WORD file by applying MS-WORD

tools.

ALGORITHM:

Step 1: Start the application

Step 2: Open the new document.

Step 3: Type the details for the advertisement.

Step 4: Choose HOME FONT to make the word or sentence bold, italic, underscore,

color fonts.

Step 5: Choose HOME PARAGRAPH to apply bulletins and line spacing.

Step 6: Select INSERT TABLE to draw

Step 7: Go to INSERT TEXT to apply word art to a word.

Step 8: Save the document.

8

Page 9: CP Lab Manual - Updated With CBTS

OUTPUT: BENIFITS: DEPARTMENTS:

100 % placement. UG COURSES

Excellent Infrastructure

S.NO Department

1 CSE

2 ECE

Hard work leads to success.

RESULT: Thus the Advertisement of a college is designed successfully with given tools using

MS-WORD.

9

Page 10: CP Lab Manual - Updated With CBTS

Ex No: 1(e) MAIL MERGE PRESENTATIONS

Date :

AIM

To produce multiple mails using mail merge wizard in Microsoft Office Word

ALGORITHM

Step 1: Start the Application Step 2: Open the New Document. Step 3: Open an existing letter or creating a new letter Step 4: On the tools menu click mail merge Step 5: Click the option to create for a new document Step 6: Create a new Data Source Step 7: Under mail merge dialog box, data source click Data Source and then click Ger Data,

then click Data Source Step 8: Insert the headers and then data Step 9: To add new record clicks add new Step 10: Inserting merge fields Step 11: Insert the merge fields where we want to merge names, addresses and other data Step 12: Click insert image field on the mail merge tool bar and then specify the fields Step 13: Click inserts all. Save the multiple copies of document Step 14: Close the Application

10

Page 11: CP Lab Manual - Updated With CBTS

OUTPUT From

XXXXXXXX

YYYYYYYY

ZZZZZZZZZ

To

«First_Name» «Collage_Name» «Address_Line_1» «City» «State»

«Country»

Respected Sir,

Subject: Regarding Admission to your collage Iam XXXXXXX. I had finished my school Studies this year and also I scored good

marks in all subjects. Now I am willing to study in your collage. So I request you to send me an application form.

Thanking You,

Date: 09-10-2012, Yours Faithfully,

Coimbatore. XXXXXXXX

11

Page 12: CP Lab Manual - Updated With CBTS

From

XXXXXXXX

YYYYYYYY

ZZZZZZZZZ

To

The Principal, Hindusthan,

Otakal Mandapam,

Coimbatore, Tamil

Nadu, India. Respected Sir, Subject: Regarding Admission to your collage

I am XXXXXXX. I had finished my school Studies this year and also I scored good marks in all subjects. Now i am willing to study in your collage. So I request you to send me an application form.

Thanking You,

Date: 09-10-2012, Yours Faithfully,

Coimbatore. XXXXXXXX.

From

XXXXXXXX

YYYYYYYY

ZZZZZZZZZ

To

The Principal,

Sri Krishna,

Kovai Puthur,

Coimbatore,

Tamil Nadu,

India.

Respected Sir,

Subject: Regarding Admission to your collage I amXXXXXXX. I had finished my school Studies this year and also I scored good

marks in all subjects. Now i am willing to study in your collage. So I request you to send me an application form.

Thanking You,

Date: 09-10-2012, Yours Faithfully,

Coimbatore. XXXXXXXX

RESULT Thus the multiple mails were produced using mail merge wizard and the output

was verified.

12

Page 13: CP Lab Manual - Updated With CBTS

Ex. No: 1(f) PARAGRAPH EDITING Date:

In the pwer tool aisle, pick up a cordless drill or saw from DeWalt and there might well be a futuristic battery pack attached—a battery that promises greater power, longer life, better safety, and shorter recharge time than conventional llithiun ion- batteries. The batery itself looks little diferent to the naked eye, or even under a microscope. The key to the battery's performance is in the diameter of the lithium particles that hold and release electric charge. The so-called nanophosphate lithium-ion batteries. Questions

1. Indent the second paragraph by 1cm on the left

2. Insert the first paragraph into a textbox 3. Put a border around the whole document

4. Format the document with 1.5 Line Spacing 5. Change the font for the whole document to Broadway and font size 10

6. Justify all the text 7. Change the sentence “The battery ……a microscope” to Title Case

8. Put your name and student number into a table at the top of the document

9. Insert the Date into the Header using Date/Time Function 10. Remove the text “conventional lithium-ion batteries” 11. Insert page numbers to your document at the top and center 12. Place the 2nd paragraph into 2 columns 13. Type the heading “Power Points” at the top of the Document and make it

Underline, Bold and centre 14. Fix any spelling mistakes that occur in the document. Make sure the

Language is set to English (South Africa).

AIM:

To modify the given content using Microsoft word. ALGORITHM:

Step 1: Start the application

Step 2: Open a new document.

Step 3: Choose PAGE LAYOUT

INDENT (or double click the in the ruler) to apply

indent.

Step 4: Select INSERT

TEXTBOX to add your content in the text box.

Step 5: To put border in the document use the path PAGE LAYOUT

PAGE

BACKGROUND PAGE BORDERS.

Step 6: Apply the line spacing and given font specifications in the paragraph.

Step 7: To justify use HOME PARAGRAPH

JUSTIFY.

Step 8: Title case (capitalise) the given words by HOME

FONT

CHANGE CASE (ctrl

key+ shift key + a).

Step 9: Create a table INSERT

TABLE and select the rows and columns you need.

Step 10: Delete required sentence or word by select it and RIGHTCLICK

CUT (or)

HOME CLIPBOARD

CUT (ctrl+x)

Step 11: Go to INSERT PAGENUMBER to insert page numbers in your document.

Step 12: Pick PAGELAYOUT PAGESETUP

COLUMN to change the column

setup.

Step 13: Prefer REVIEW

PROOFING

SPELLING & SET LANGUAGE to set the

language and corrections in the paragraph.

Step 14: Save the document

13

Page 14: CP Lab Manual - Updated With CBTS

OUTPUT:

POWER POINTS

ROLL.NO NAME

001 xyxy

THE BATTERY itself looks little diferent

to the naked eye, or even under A

MICROSCOPE. The key to the battery's

performance is in the diameter of the

lithium particles that hold and

release electric charge. The so-called

nanophosphate lithium-ion batteries.

In the power tool aisle, pick up a cordless drill or saw from DeWalt and there

might well be a futuristic battery pack attached—a battery that promises

greater power, longer life, better safety, and shorter recharge time than.

RESULT: Thus the given paragraph is changed with given specifications using MS-WORD.

14

Page 15: CP Lab Manual - Updated With CBTS

Ex. No: 1(g) VISITING CARD PREPARATION

Date:

Create a visiting card for you as per the following specifications using MS-WORD. Size of visiting card is” 4”×”2” office and Residential address separated by a line and insert logo.

AIM: To create a visiting card using MS-WORD.

ALGORITHM:

Step 1: Open a new document. Step 2: Go to PAGE LAYOUT PAGESETUP SIZE MORE PAGE SIZES. Step 3: Change the sizes of the paper width to 4” and height to 2”, also change the

margins bottom and right to 0.15. Step 4: Type the office and Residential address in the Visiting card and separate the address

by a line using borders. Step 5: Use clip arts, shapes if necessary.

Step 6: Do the required changes in your visiting card and save the document.

15

Page 16: CP Lab Manual - Updated With CBTS

OUTPUT:

RESULT: Thus a Visiting card is designed as per the specification given with the help of

MS-WORD.

16

Page 17: CP Lab Manual - Updated With CBTS

MS-EXCEL

17

Page 18: CP Lab Manual - Updated With CBTS

PRESENTATION AND VISUALIZATION – GRAPHS, CHARTS, 2D, 3D

Ex No: 2(a) MARK SHEET PREPARATION USING MS-EXCEL

Date :

AIM

To create students mark sheet using Microsoft Office Excel and to create a chart

ALGORITHM

Step 1: Start the Application Step 2: Open the New Excel Document Step 3: Enter the field name in cells Step 4: Enter the required data for preparing the mark sheet Step 5: From the functions menu choose the function to calculate the total marks of each

student Step 6: Calculate the average mark pf of each student using the formula Step 7: Type the formula in the formula bar to logically check the students mark to calculate

the grade of the student Step 8: To print the Chart

a. Select the data that are to be entered in the chart

b. In the Insert menu click Chart Wizard and specify the details in the chart Step 9: Save the document FILE SAVE and press OK Step 10: Close the Application

18

Page 19: CP Lab Manual - Updated With CBTS

OUTPUT

Name Physics Chemistry Maths Total Average Grade

Arun 80 56 91 227 75.6 B

Bala 70 72 85 227 75.6 B

Chandran 62 80 79 221 73.6 C

Student Mark details

Av

era

ge

76

75.5

75

74.5 Avg

74

73.5

73

72.5

Arun bala Chandran

RESULT Thus the student mark sheet and the chart was created using Microsoft Office

Excel and the output was displayed.

19

Page 20: CP Lab Manual - Updated With CBTS

Ex No. 2(b) SALARY DETAILS

Date:

The following Salaries of 5 employees

Employee no Employee Basic Salary

Name (Rs)

1011 Prasanna 10000

1012 Anitha 14000

1013 Ravi 18000

1014 Saritha 15000

1015 Mallika 17000

a. Calculate DA @ 20%, HRA @ 15%, CCA fixed Rs.200, PF @ 10% b. Calculate Gross salary & Net Salary c. Insert a picture.based on the given table. d. Using Conditional Formatting list out employees in MS- EXCEL who got

i. Less than Rs. 15000 as salary ii. Between Rs. 15000 and Rs. 20000 as Net Salary.

AIM

To calculate salary of the employees and to use conditional formatting in the

Microsoft Office Excel worksheet

ALGORITHM

Step 1: Start the Application

Step 2: Open the New Excel Document

Step 3: Insert the values as per the given table

Step 4: Calculate DA, HRA as per the following formula DA= (Basic Salary * DA %) / 100

HRA= (Basic Salary * HRA %) / 100 PF= (Basic Salary * PF %) / 100

Step 5: Calculate Gross salary & Net salary by using the formulas Gross Salary= (Basic

salary + DA + HRA+CCA) Net Salary= (Gross salary – PF)

Step 6: Then choose conditional formatting form HOME MENU

Step 7: Now choose HIGHLIGHT CELLS LESS THAN, a dialog box opens.

Step 8: Enter the value in dialog box. Then click ok button.

Step 9: similarly select the cells for greater than and between values.

Step 10: Now the selected picture is inserted into the worksheet.

Step 11: Save the document FILE SAVE and press OK

Step 12: Close the Application

20

Page 21: CP Lab Manual - Updated With CBTS

OUTPUT RESULT

Thus the calculation of salary details, conditional formatting and picture insertion was successfully executed in the Microsoft Office Excel work sheet and the output was verified.

21

Page 22: CP Lab Manual - Updated With CBTS

Ex. No: 2(c) FORMULAS IN MS-EXCEL

Date:

The heights of group of an 11 persons are 123, 134, 145, 167, 178, 167, 168, 149, 156,

179, 180, and 175 centimetres. Enter imaginary names for the heights given and arrange

the names in descending order. a. Insert One person with height 189 b. Calculate average, maximum, minimum of heights. c. Change column width of person name as 40. d. Change row height of average, maximum, minimum to 20.

AIM: To calculate average, maximum and minimum heights of various students

ALGORITHM: Step 1: start the application

Step 2: open a new Excel document. Step 3: enter the person’s height. RIGHT CLICK on the COLUMN go to INSERT. Step 4: Enter the person name in the newly inserted column. Step 5: Right click on the row go to INSERT. Now insert a new row. Step 6: calculate average, maximum, minimum by using the following formula Average =

average(num1,num2..) maximum = maximum(num1,num2..) minimum = minimum(num1,num2..)

Step 7: Now right click on person name go to COLUMN WIDTH change as 40 Step 8: Now right click on avg., max., min go to ROW HEIGHT change as 20 Step 9: Close the Application

22

Page 23: CP Lab Manual - Updated With CBTS

OUTPUT:

RESULT

Thus the given values are entered and the average, maximum, minimum heights are

calculated successfully and the output was verified.

23

Page 24: CP Lab Manual - Updated With CBTS

Ex.No:2(d) NUMBER SYSTEM CONVERSIONS Date:

Generate an excel sheet for the conversion of the following using functions: a) Decimal to binary b) Octal to binary c) Binary to decimal d) Decimal to hexadecimal e) Rupees to dollar

AIM:

To create an Excel sheet for the given conversions.

ALGORITHM: Step 1: Start the application

Step 2: open a new Excel document.

Step 3: Enter the required number

Step 4: Go to FORMULAS

MORE FUNCTIONS ENGINEERING

use the

required conversion functions.

Step 5: Save and close the application.

24

Page 25: CP Lab Manual - Updated With CBTS

OUTPUT: RESULT

Thus the given conversions are calculated successfully and the output was verified.

25

Page 26: CP Lab Manual - Updated With CBTS

MS-POWER POINT PERSENTATION

26

Page 27: CP Lab Manual - Updated With CBTS

Ex No: 2(e) POWER POINT PRESENTATION

Date:

AIM: To create a power point presentation using Microsoft office power point

ALGORITHM: Step 1: Start the application

Step 2: open a new power point document.

Step 3: Enter the required information Step 4: Apply design and animation for each slide

Step 5: Save and close the application.

27

Page 28: CP Lab Manual - Updated With CBTS

OUTPUT:

DATA TYPE

Definition Classification

DEFINITION

Data type represents the type of values which can be processed by the programming language.

CLASSIFICATION

Data type

Primary data type User defined

Derived data type data type

PRIMARY DATA TYPE Primary data types are

Integer data type: int Character data type: char Single-precision floating point data type: float Double-precision floating point data type: double

DERIVED DATA TYPE The derived data types are

Arrays Structures Unions Pointers

RESULT

Thus the MS-Power Point Presentation was successfully executed and the output was verified.

28

Page 29: CP Lab Manual - Updated With CBTS

PROBLEM FORMULATION, PROBLEM SOLVING AND

FLOWCHARTS

Ex No: 3(a) FLOW CHART DRAWING

Date :

AIM To draw a flowchart to find the greatest of three numbers using Microsoft Office Word

ALGORITHM

Step 1: Start the Application

Step 2: Open the New Document

Step 3: Open the New Document

Step 4: Draw the require flow chart symbols from the option Auto shapes Flowchart

Step 5: Connect all the symbols using arrows

Step 6: Enter the text inside the flow chart symbols

Step 7: Save the document FILE SAVE and press OK

Step 8: Close the Application

29

Page 30: CP Lab Manual - Updated With CBTS

OUTPUT

Start

Read a, b, c

False True If

a>b

True False False True If If

b>c a>c

B is Largest C is Largest A is Largest

Stop

RESULT Thus a flowchart to find the greatest of the three numbers was drawn using Microsoft

Office Word and the output was verified.

30

Page 31: CP Lab Manual - Updated With CBTS

Ex. No: 3(b) SCIENTIFIC NOTATIONS

Date :

AIM

To type the following equations using Microsoft Office Word

a) Ca(HCO3)2 CaCo3 + Co2 + H2O

b) (A+B) 2 = A

2 + B

2 + 2 AB

c) 2−1

= +

d) (a + b)4 = a

4 + 4a

3b + 6a

2b2 + 4ab

3 + b

4

e) CnH(2n + 1)OH (n ≥ 1)

f) ,

= ,

== ==

ALGORITHM

Step 1: Start the Application

Step 2: Open the New Document.

Step 3: Enter the Equation in document using INSERT SYMBOLS

EQUATION

INSERT NEW EQUATION.

Step 4: Select the symbols, which we want to show as a subscript.

Step 5: For subscript, choose the Font option from the Format menu, the enable and

subscript check box from the Font dialog box.

Step 6: For superscript, choose the Font option from the Format menu, then enable

the superscript check box from the Font dialog box.

Step 7: Save the document FILE SAVE and press OK.

Step 8: Close the Application.

31

Page 32: CP Lab Manual - Updated With CBTS

OUTPUT

Ca(HCO3)2 CaCO3 + CO2 + H2O

(A+B) 2 = A

2 + B

2 + 2 AB

=+

2 − 1

(a + b)4

= a4

+ 4a3b + 6a

2b2 + 4ab

3 + b

4

CnH(2n + 1)OH (n ≥ 1)

,

= ,

= = ==

RESULT Thus the given equations were typed using Microsoft Office Word and the output was

verified.

32

Page 33: CP Lab Manual - Updated With CBTS

C Programs

33

Page 34: CP Lab Manual - Updated With CBTS

C PROGRAMMING USING SIMPLE STATEMENTS AND

EXPRESSIONS

Ex No: 4(a) LARGEST OF THREE NUMBERS

Date :

AIM

To create a C program to find the largest of three numbers

ALGORITHM

Step 1: Start the process.

Step 2: Get the values of a, b, c. Step 3: Compare A & B. IF A is greater than B perform step 4 else perform step 5. Step 4: Compare A & C. IF A is greater, Output “A is largest”.

Perform step 6.

Step 5: Compare B & C. IF B is greater, output “B is largest” else output “C is largest”

Step 6: Stop the process.

FLOWCHART

Start

Read a, b, c

False True If

a>b

True False False True If If

b>c a>c

B is Largest C is Largest A is Largest

Stop 34

Page 35: CP Lab Manual - Updated With CBTS

PROGRAM #include<stdio.h> #include<conio.h> void main() {

int a,b,c; clrscr(); printf("\nEnter the three numbers\n");

scanf("%d%d%d",&a,&b,&c); if(a>b)

{ if(a>c)

printf("%d is largest",a);

}

else

{

if(b>c) printf("%d is largest",b); else printf("%d is largest",c);

}

getch();

}

35

Page 36: CP Lab Manual - Updated With CBTS

OUTPUT Enter the three numbers

8 5 7

8 is largest RESULT

Thus the c program to find the largest of three numbers has been successfully completed and the output was verified.

36

Page 37: CP Lab Manual - Updated With CBTS

Ex No: 4(b) EXPRESSION EVALUATION

Date :

AIM

To calculate arithmetic operations using C program

ALGORITHM Step 1: Start the process.

Step 2: Input the variable a, b, c.

Step 3: Enter the value of the operator. Step 4: Enter the value of the variable a and b.

Step 5: Enter switch operator.

Step 6: Calculate the arithmetic operation based on the operator.

Step 7: Save and execute the program.

Step 8: Display the result.

Step 9: Stop the process.

37

Page 38: CP Lab Manual - Updated With CBTS

FLOWCHART

Start

Read a, b, op

Enter value for op

Op=Case 1

false

Op=Case 2

false

true true

C=a+b

C=a-b

Op=Case 3

false

Op=Case 4 false

Op=Case 5

true

true

true

C=a*b C=a/b C=a%b

false

Invalid result

Print c Stop

38

Page 39: CP Lab Manual - Updated With CBTS

PROGRAM

#include<stdio.h> #include<conio.h>

void main() {

char a,b,c,d; clrscr();

printf("Enter the values of a and b:"); scanf("%d%d" ,&a,&b);

printf(" Enter your choice between 1 to 5 /n"); scanf("%d , &d); switch(d) {

case 1:

c=a+b;

printf(" Addition=%d", c); break;

case 2:

c=a-b;

printf(" Substraction=%d" , c); break;

case 3:

c=a*b;

printf(" Multiplication=%d", c); break;

case 4:

c=a/b;

printf(" Divide=%d", c); break;

case 5: c=a%b;

printf(" Remainder=%d",c ); break: default:

printf(" Invalid Result"); break;

} }

39

Page 40: CP Lab Manual - Updated With CBTS

OUTPUT:

Enter value of a & b:

3 4

Enter choice between 1 & 5: 1 Addition : 7

RESULT Thus the c program to calculate the arithmetic operation using switch case has been

successfully completed and the output was verified.

40

Page 41: CP Lab Manual - Updated With CBTS

SCIENTIFIC PROBLEM SOLVING USING DECISION MAKING AND LOOPING.

Ex No: 5(a) REVERSE THE GIVEN NUMBER

Date :

AIM

To reverse the given number using C program

ALGORITHM Step 1: Start the process.

Step 2: Declare the variables n and digit.

Step 3: Initialize the value 0 to rev (i.e rev=0)

Step 4: Get the value of n to reverse

Step 5: Calculate n MOD 10 to split the last value and equate to digit.

Step 6: Multiply rev by 10 and add the value to digit. Equate the value to rev.

Step 7: Divide n by 10 and equate to n.

Step 8: Repeat step 6 to 8 until n is equal to 0

Step 9: if the condition fails, print sum.

Step 10: Stop the process

FLOWCHART

Start

Read n

rev=0

digit=n%10 rev=(rev*10)+digit

n=n/10

While No

(n!=0)

Yes

Print sum

41

Stop

Page 42: CP Lab Manual - Updated With CBTS

PROGRAM #include<stdio.h> #include<conio.h> void main() {

int n,digit,rev=0; clrscr(); printf("\nenter the number to be reverse\n"); scanf("%d",&n); do

{ digit=n%10;

rev=(rev*10)+digit;

n=n/10;

}

while(n!=0); printf("\nreverse of number is %d",rev); getch();

}

42

Page 43: CP Lab Manual - Updated With CBTS

OUTPUT Enter the number to be reverse 123 Reverse of number: 321

RESULT Thus the c program to reverse the given number has been successfully completed and

the output was verified.

43

Page 44: CP Lab Manual - Updated With CBTS

Ex No: 5(b) GIVEN NUMBER IS PRIME OR NOT

Date :

AIM

To check whether the given number is prime or not by using C program

ALGORITHM

Step 1: Start the process. Step 2: Get the value for num. Step 3: Initialize count to 0 and i to 2 Step 4: Check i is less than equal to num divide by 2 and repeat step 5 until the condition fails Step 5: If step 4 is true, then check num modulo i is equal to zero Step 6: If step 5 condition is true, then increment the value of count Step 7: If step 4 fails, go to step 5. Step 8: stop.

`

44

Page 45: CP Lab Manual - Updated With CBTS

FLOWCHART

Start

Read num

i=2

No If (i <=num-1)

Yes

If (num%i==0)

yes

Not a prime no.

No A

If (i==num)

A

Stop

No

i++ yes

No. is a prime

45

Page 46: CP Lab Manual - Updated With CBTS

PROGRAM #include<stdio.h> #include<conio.h> void main() {

int num,i; clrscr(); printf("\n enter the number\n"); scanf("%d",&num); for(i=2;i<=num-1;i++) {

if(num%i==0)

{ printf("\n given no. is not prime number"); break;

}

}

if(i==num)

{

printf("\n given no. is prime no.");

}

getch();

}

46

Page 47: CP Lab Manual - Updated With CBTS

OUTPUT Enter the number 3 Prime number Enter the number 5 Not a prime

RESULT Thus the c program to find the given number is prime or not has been successfully

completed and the output was verified.

47

Page 48: CP Lab Manual - Updated With CBTS

Ex No: 5(c) ROOTS OF QUADRATIC EQUATION

Date:

AIM

To write c program to calculate the roots of the given quadratic equation.

ALGORITHM

Step 1: Start Step 2: Declare variables a, b, c, D, x1, x2, rp and ip; Step 3: Calculate discriminant

D←b2-4ac Step 4: If D>0

r1←(-b+sqrt(D))/2a r2←(-b-sqrt(D))/2a

Step 5: print the roots are real and unequal. Display r1 and r2 as roots.

Step 6: Elseif D==0

R1

r2

b/2a Step 7: print the roots are real and equal.

Display r1 and r2 as roots. Step 8: else print roots are imaginary. Step 9: Stop

48

Page 49: CP Lab Manual - Updated With CBTS

FLOWCHART:

start

Read a,b,c,D,r1,r2

D=b*b-4*a*c

true Is D>0

false

true Is D==0

false

Print roots are imaginary

r1= (-b+sqrt(D))/(2*a); r2= (-b-sqrt(D))/(2*a); r1 = r2 = -b/(2*a);

Print r1 & r2

stop

49

Page 50: CP Lab Manual - Updated With CBTS

PROGRAM

#include <stdio.h> #include <math.h> int main() {

float a, b, c, D, r1,r2; printf("Enter coefficients a, b and c: "); scanf("%f%f%f",&a,&b,&c); D=b*b-4*a*c; if (D>0) {

r1= (-b+sqrt(D))/(2*a); r2= (-b-sqrt(D))/(2*a); printf("Roots are: %f and %f",r1 , r2);

}

else if (D==0)

{

r1 = r2 = -b/(2*a);

printf("Roots are: %f and %f", r1, r2);

}

else

{

printf("Roots are imaginary”);

}

return 0;

}

50

Page 51: CP Lab Manual - Updated With CBTS

OUTPUT: Enter coefficients a, b and c:

4 1 0

Roots are: 0.00 and -0.25 RESULT:

Thus the c program to find the roots of the quadratic equation was executed and

the output was verified.

51

Page 52: CP Lab Manual - Updated With CBTS

Ex No: 5(d) CONVERSION OF OCTAL TO DECIMAL

Date :

AIM

To convert the given number from octal to decimal using C program

ALGORITHM Step 1: Start the process.

Step 2: Assign values to the required variables n, i=0.

Step 3: Enter the octal number to be converting. Step 4: Convert the given number from octal to decimal.

Step 5: Save and execute the program.

Step 6: Display the result.

Step 7: Stop the process.

FLOWCHART

Start

I=0

Sum=0

Get n

False

While(i<n)

True

d=n%10

sum=sum+d*pow(8,i) n=n/10 i=i+1

Print sum

Stop

52

Page 53: CP Lab Manual - Updated With CBTS

PROGRAM

#include<stdio.h>

#include<math.h> #include<conio.h> void main() {

int n,i=0,sum=0,d; clrscr(); printf("\nenter the octal number\n"); scanf("%d",&n); while(n>0)

{

d=n%10;

sum=sum+d*pow(8,i);

n=n/10;

i=i+1;

} printf("\ndecimal equivalent is %d",sum); getch();

}

53

Page 54: CP Lab Manual - Updated With CBTS

OUTPUT Enter the octal number 10 Decimal equivalent is 8 RESULT

Thus the c program to convert the given octal number to decimal has been successfully completed and the output was verified.

54

Page 55: CP Lab Manual - Updated With CBTS

SIMPLE PROGRAMMING FOR ONE DIMENSIONAL AND TWO DIMENSIONAL

ARRAYS.

Ex No: 6(a) SORTING THE ARRAY ELEMENTS

Date :

AIM: To sort the array of elements in ascending order.

ALGORITHM: Step 1: Start the process.

Step 2: Read the values of an array.

Step 3: Compare the first element of an array with other elements.

Step 4: If the first element is greater the next, then interchange the elements.

Step 5: Continue the process until the elements are arranged in ascending order.

Step 6: Stop the process.

55

Page 56: CP Lab Manual - Updated With CBTS

PROGRAM: #include <stdio.h> void main() {

int i, j, a, n, number[30]; printf("Enter the value of N \n"); scanf("%d", &n); printf("Enter the numbers \n"); for (i = 0; i < n; ++i)

{ scanf("%d", &number[i]);

}

for (i = 0; i < n; ++i)

{

for (j = i + 1; j < n; ++j)

{

if (number[i] > number[j])

{ a = number[i]; number[i] = number[j]; number[j] = a;

}

}

} printf("The numbers arranged in ascending order are given below \n"); for (i = 0; i < n; ++i)

{

printf("%d\n", number[i]);

}

}

56

Page 57: CP Lab Manual - Updated With CBTS

OUTPUT:

Enter the value of N 5 Enter the numbers

23 45 6 34 1

The numbers arranged in ascending order are given

below 1 6 23 34 45

RESULT: Thus the program to arrange the numbers in ascending order using array was

executed successfully and the output was verified.

57

Page 58: CP Lab Manual - Updated With CBTS

Ex No: 6(b) MATRIX MULTIPLICATION

Date :

AIM To perform the matrix multiplication using array concept in C program

ALGORITHM

Step 1: Start the process.

Step 2: Enter the rows and columns for matrix a[i][j] and matrix b[i][j].

Step 3: Enter the elements for matrix a[i][j] and b[i][j].

Step 4: Assign elements of the matrix c[i][j]=0.

Step 5: Multiply the matrix a and matrix b and then store it matrix c

Step 6: Save and execute the program.

Step 7: Display the result.

Step 8: Stop the process.

58

Page 59: CP Lab Manual - Updated With CBTS

PROGRAM #include<stdio.h> #include<conio.h> void main() {

int r1,r2,c1,c2,i,j,k,a[10][10],b[10][10],c[10][10]=0; clrscr(); printf("\nenter the rows and columns of matrix1\n"); scanf("%d%d",&r1,&c1); printf("\nenter the rows and columns of matrix2\n"); scanf("%d%d",&r2,&c2); printf("\nenter the elements of matrix1\n"); for(i=0;i<r1;i++) {

for(j=0;j<c1;j++)

{

scanf("%d",&a[i][j]);

}

} printf("\nenter the elements of matrix2\n"); for(i=0;i<r2;i++) {

for(j=0;j<c2;j++)

{

scanf("%d",&b[i][j]);

}

}

if(r1==c2)

{

for(i=0;i<r1;i++)

{

for(j=0;j<c2;j++)

{

for(k=0;k<c1;k++) {

c[i][j]=c[i][j]+a[i][k]*b[k][j];

}

} } printf("\nresultant matrix:\n"); for(i=0;i<m;i++) {

for(j=0;j<q;j++)

{

printf("%d ",c[i][j]);

}

printf("\n");

}

}

getch();}

59

Page 60: CP Lab Manual - Updated With CBTS

OUTPUT

Enter the rows and columns of

matrix1 2 2

Enter the rows and columns of

matrix2 2 2

Enter the elements of matrix1

5 3 2 1 Enter the elements of matrix2

1 1 1 1 Resultant Matrix

8 8 3 3

RESULT Thus the c program to perform the matrix multiplication has been successfully

completed and the output was verified.

60

Page 61: CP Lab Manual - Updated With CBTS

SOLVING PROBLEMS USING STRING FUNCTIONS

Ex No: 7(a) STRING LENGTH FUNCTION Date :

AIM To write a C program to find the string length and to reverse the given string.

ALGORITHM

Step 1: start the program.

Step 2: get the string.

Step 3: using strrev() fucntion to convert the reverse order of the string.

Step 4: using strlen() function to find the length of the string. Step 5: print the string.

Step 6: stop the program.

61

Page 62: CP Lab Manual - Updated With CBTS

PROGRAM

#include <stdio.h> #include <conio.h> #include <string.h> void main() { char str[50]; clrscr(); printf("\n\t Enter your name : "); gets(str); printf("\nReverse of string: %s",strrev(str)); printf("\nLength of String: %d",strlen(str)); getch(); }

62

Page 63: CP Lab Manual - Updated With CBTS

OUTPUT: Enter your name : Colllege

Reverse of string: EGELLLOC

Length of String: 8

RESULT: Thus the program to reverse the string and to find the length of the string was

executed and the output was verified successfully.

63

Page 64: CP Lab Manual - Updated With CBTS

Ex No: 7(b) COPY TWO STRINGS

Date :

AIM:

To write a C program to copy the strings using strcpy()

ALGORITHM: Step 1: start the program.

Step 2: get the string.

Step 3: copy the string into another string variable by using strcpy() fucntion

Step 4: print the string.

Step 5: stop the program

64

Page 65: CP Lab Manual - Updated With CBTS

PROGRAM:

#include <stdio.h> #include <string.h> main() { char s1[20], s2[20]; printf("\nEnter string into s1: "); gets(s1); strcpy(s2, s1); printf("\ns2: %s", s2); getch(); }

65

Page 66: CP Lab Manual - Updated With CBTS

OUTPUT: Enter string into s1: Engineering s2: Engineering

RESULT: Thus the program to copy the string was executed and the output was verified

successfully.

66

Page 67: CP Lab Manual - Updated With CBTS

Ex No: 7(c) CONCATENATE TWO STRINGS

Date :

AIM:

To write a C program to concatenate two strings using strcat()

ALGORITHM:

Step 1: start the program. Step 2: get the first string. Step 3: get the second string. Step 4: using strcat() function to concatenate the string. Step 5: print the concatenated string.

Step 6: stop

67

Page 68: CP Lab Manual - Updated With CBTS

PROGRAM:

/**** Program to Concatenate Two Strings using strcat() ****/ #include <stdio.h> #include <string.h> main() { char s1[20], s2[20]; printf("\nEnter first string: "); gets(s1); printf("\nEnter second string: "); gets(s2); strcat(s1, s2); printf("\nThe concatenated string is: %s", s1); getch(); }

68

Page 69: CP Lab Manual - Updated With CBTS

OUTPUT: Enter first string: College of Enter second string: Engineering The concatenated string is: College of Engineering

RESULT: Thus the program to concatenate the string was executed and the output was

verified successfully.

69

Page 70: CP Lab Manual - Updated With CBTS

Ex No: 7(d) COMPARE TWO STRINGS

Date :

AIM:

To write a C program to compare two strings using strcmp().

ALGORITHM:

Step 1: start the program. Step 2: get the first string. Step 3: get the second string. Step 4: using strcmp() function compare the two strings. Step 5: else prints not equal. Step 6: stop the program.

70

Page 71: CP Lab Manual - Updated With CBTS

PROGRAM:

/*** Program to Compare Two Strings using strcmp() ***/

#include

<stdio.h>

#include

<string.h> main()

{

char s1[20], s2[20];

int result;

printf("\nEnter first string: ");

gets(s1);

printf("\nEnter second string: ");

gets(s2);

result = strcmp(s1, s2);

if (result == 0)

printf("\nBoth strings are equal");

else

printf("\nBoth strings are not equal");

getch();

}

71

Page 72: CP Lab Manual - Updated With CBTS

OUTPUT: Enter first string: college

Enter second string: engineering

Both strings are not equal RESULT:

Thus the program to compare the string was executed and the output was verified successfully.

72

Page 73: CP Lab Manual - Updated With CBTS

PROGRAMS WITH USER DEFINED FUNCTIONS – INCLUDES

PARAMETER PASSING

Ex No: 8(a) FIBONACCI SERIES

Date :

AIM Write a program to generate Fibonacci series in C program

ALGORITHM Step 1: Start the process. Step 2: Read the number of terms as input.

Step 3: Assign values to the variable f, s, t, i.

Step 4: Calculate the Fibonacci series using for loop.

Step 5: Save and execute the program.

Step 6: Display the result.

Step 7: Stop the process.

FLOWCHART

73

Page 74: CP Lab Manual - Updated With CBTS

PROGRAM #include<stdio.h> #include<conio.h> void fib(int n); void main() {

int num; clrscr(); printf("\nenter the no of terms"); scanf("%d",&num); fib(num); getch();

}

void fib(int n)

{ int x=0,y=1,z,i; printf("\nfibonacci series\n"); printf("%d %d",x,y); for(i=2;i<n;i++) {

z=x+y; printf(" %d",z); x=y; y=z;

}

}

74

Page 75: CP Lab Manual - Updated With CBTS

OUTPUT Enter the no of terms 6 Fibonacci series is

0 1 1 2 3 5

RESULT Thus the c program generate the Fibonacci series has been successfully completed and

the output was verified.

75

Page 76: CP Lab Manual - Updated With CBTS

Ex No: 8(b) CALL BY VALUE

Date :

AIM To write a C program to swap the given number by using call by value.

ALGORITHM Step 1: Start the process. Step 2: Assign values to the variable a and b.

Step 3: Pass the value of the variables to the function swap().

Step 4: Swap the values of the variable in the function swap().

Step 5: Save and execute the program. Step 6: Display the result.

Step 7: Stop the process.

FLOWCHART

76

Page 77: CP Lab Manual - Updated With CBTS

PROGRAM

#include<stdio.h> #include<conio.h> void swap(int a,int b); void main() {

int x=10,y=20; clrscr(); swap(x,y); printf("\nx=%d y=%d",x,y); getch();

}

void swap(int a,int b)

{ int c; c=a; a=b; b=c; printf("\nx=%d y=%d",a,b);

}

77

Page 78: CP Lab Manual - Updated With CBTS

OUTPUT

Before swapping

X=10

Y=20

After swapping

X=10

Y=20

RESULT Thus the c program to swap the two number using call by value has been successfully

completed and the output was verified.

78

Page 79: CP Lab Manual - Updated With CBTS

Ex No: 8(c) CALL BY REFERENCE

Date :

AIM Write a program to swap the given number by using call by reference in C program

ALGORITHM Step 1: Start the process. Step 2: Assign values to the variable a and b.

Step 3: Pass the address of the variable to the function swap().

Step 4: Swap the values of the variable in the function swap().

Step 5: Save and execute the program. Step 6: Display the result.

Step 7: Stop the process.

FLOWCHART

Start

Read x,y

call swap(&x,&y)

print x,y

Stop

call swap(*a,*b)

c=*a

*a=*b

*b=c

Print *a,*b

79

Page 80: CP Lab Manual - Updated With CBTS

PROGRAM

#include<stdio.h>

#include<conio.h> void swap(int *a,int *b); void main() {

int x=10,y=20; clrscr(); swap(&x,&y); printf("\nx=%d y=%d",x,y); getch();

}

void swap(int *a,int *b)

{ int c; c=*a; *a=*b; *b=c; printf("\nx=%d y=%d",*a,*b);

}

80

Page 81: CP Lab Manual - Updated With CBTS

OUTPUT

Before swapping

X=10

Y=20

After swapping

X=20

Y=10

RESULT Thus the c program to swap the two number using call by reference has been

successfully completed and the output was verified.

81

Page 82: CP Lab Manual - Updated With CBTS

PROGRAM USING RECURSIVE FUNCTION AND CONVERSION

FROM GIVEN PROGRAM TO FLOWCHART

Ex No: 9 FACTORIAL USING RECURSION

Date :

AIM Write a program to find the factorial of given number using recursive function in

C program ALGORITHM Step 1: Start the process. Step 2: Assign values to the variable n. Step 3: Read the value for the variable n. Step 4: Check the condition for the variable using if loop Step 5: Calculate the factorial using the formula fact(a-1). Step 6: Save and execute the program. Step 7: Display the result. Step 8: Stop the process.

FLOWCHART

82

Page 83: CP Lab Manual - Updated With CBTS

PROGRAM #include<stdio.h> #include<conio.h> int fact(int); void main()

{ int n; clrscr(); printf("\nenter the number"); scanf("%d",&n); printf("factorial=%d",fact(n)); getch();

}

int fact(int a)

{ int f; if(a==0)

return(1);

else

f=a*fact(a-1);

return(f); }

83

Page 84: CP Lab Manual - Updated With CBTS

OUTPUT

Enter the number 5 Factorial:

120

RESULT Thus the c program to find the factorial of given number using recursive function has been successfully completed and the output was verified.

84

Page 85: CP Lab Manual - Updated With CBTS

PROGRAM USING STRUCTURES AND UNIONS

Ex No: 10(a) STUDENT DETAILS USING STRUCTURES

Date :

AIM Write a program to display the student details using structure in C program

ALGORITHM Step 1: Start the process. Step 2: Create the structure with the name student and declare the variables. Step 3: using for loop get the details of student such as name, roll no, mark1, mark2, and total for Step 4: Swap the values of the variable in the function swap(). Step 5: Save and execute the program. Step 6: Display the result. Step 7: Stop the process.

85

Page 86: CP Lab Manual - Updated With CBTS

PROGRAM #include<stdio.h>

#include<conio.h> #include<string.h> struct student {

char name[20]; int rollno; int mark1,mark2,mark3; int total; int avg; char grade[20];

};

void main()

{

int i,n; struct student s[50]; clrscr(); printf("\enter the no of students"); scanf("%d",&n); for(i=0;i<n;i++) {

printf("\nenter the name");

scanf("%s",s[i].name);

printf("\nenter the rollno");

scanf("%d",&s[i].rollno); printf("\nenter the marks"); scanf("%d%d%d",&s[i].mark1,&s[i].mark2,&s[i].mark3);

s[i].total=s[i].mark1+s[i].mark2+s[i].mark3;

s[i].avg=s[i].total/3;

if(s[i].avg>=75) strcpy(s[i].grade,"distinction"); else if(s[i].avg<75&&s[i].avg>=60) strcpy(s[i].grade,"first class"); else if(s[i].avg<60&&s[i].avg>=50) strcpy(s[i].grade,"second class"); else strcpy(s[i].grade,"third class");

}

printf("\nname\trollno\ttotal\taverage\tgrade");

for(i=0;i<n;i++)

{

printf("\n%s\t%d\t%d\t%d\t%s",s[i].name,s[i].rollno,s[i].total,s[i].avg,s[i].grade);

}

getch();

}

86

Page 87: CP Lab Manual - Updated With CBTS

OUTPUT

Enter the name: Lenin

Enter the roll no: 95202205023

Enter the marks: 90 94 89

Enter the Name: Satheesh

Enter the roll no: 95202205024

Enter the marks: 90 98 85

Enter the Name: Abel

Enter the roll no: 95202205025

Enter the marks: 96 92 86

Name Roll No Total Average Grade Lenin 95202205023 273 91 Distinction Satheesh 95202205024 273 91 Distinction

Abel 95202205025 274 91 Distinction RESULT

Thus the c program to display the student details using structure has been successfully completed and the output was verified.

87

Page 88: CP Lab Manual - Updated With CBTS

Ex No: 10(b) STUDENT DETAILS USING UNION AND STRUCTURES

Date :

AIM

Write a program to display the student details using structure in C program

ALGORITHM

Step 1: Start the process. Step 2: Create the structure with the name student and declare the variables. Step 3: Create union and invoke structure details Step 4: The details of the student. Step 5: Save and execute the program. Step 6: Display the result. Step 7: Stop the process.

88

Page 89: CP Lab Manual - Updated With CBTS

PROGRAM: #include<stdio.h> #include<conio.h> void main() {

struct student

{ char name[30]; char sex; int rollno;

fload percentage;

};

union details

{

struct student st;

}

clrscr(); printf(“Enter the details”); printf(“nEnter the name”); scanf(“%s”, set.st.name); printf(“Enter the details”); scanf(“%s”,& set.st.rollno); flushall(); printf(“nEnter the sex”); scanf(“%c”,& set.st.sex); printf(“Enter the Percentage”); scanf(“%f”,& set.st.Percentage); printf(“n The student details are: n”); printf(“Name : %s”, set.st.name); printf(“Name : %d”, set.st.rollno); printf(“Name : %c”, set.st.sex); printf(“Name : %f”, set.st.percentage); getch();

}

89

Page 90: CP Lab Manual - Updated With CBTS

OUT PUT Enter details:

Enter name : Arull

Enter rollno: 10

Enter sex: M

Enter percentage: 89

The student details are: Name : Arull

Rollno : 10

Sex : M

Percentage : 89.000000

RESULT Thus the c program to display the student details using union and structure has been

successfully completed and the output was verified.

90

Page 91: CP Lab Manual - Updated With CBTS

Ex No: 11(a) ADDING TWO NUMBERS USIGN COMMAND LINE ARGUMENTS

Date :

AIM To write a c program to add two numbers using command line arguments.

ALGORITHM

Step 1: Start the program.

Step 2: Open Command Prompt inside Borland C/C++.

Step 3: Click on DOS Shell.

Step 4: Inside Command Prompt type this command, “add 10 20”.

Step 5: Type “exit” command to return to Turbo C/C++ Screen

Step 6: Stop the process.

91

Page 92: CP Lab Manual - Updated With CBTS

PROGRAM: #include<stdio.h>

void main(int argc, char * argv[])

{

int i, sum = 0;

if (argc != 3)

{

printf("You have forgot to type numbers.");

exit(1);

}

printf("The sum is : ");

for (i = 1; i < argc; i++)

sum = sum + atoi(argv[i]);

printf("%d", sum);

}

92

Page 93: CP Lab Manual - Updated With CBTS

OUT PUT The sum is: 30

RESULT Thus the c program to copy one file to another has been successfully completed

and the output was verified. 93

Page 94: CP Lab Manual - Updated With CBTS

Ex No: 11(b) COPYING ONE FILE TO ANOTHER USING

Date : COMMAND LINE ARGUMENTS

AIM To write a c program to copy one file to another using command line arguments.

ALGORITHM Step 1: Start the program. Step 2: Open two files fp1 and fp2 by passing the file names through command line

arguments. Step 3: Open two files using fopen() function. Step 4: Until end of file reaches copy the contents of fp1 to fp2. Step 5: If fp1 does not have any valid information, terminate the program. Step 6: Close the files. Step 7: Stop the process.

94

Page 95: CP Lab Manual - Updated With CBTS

PROGRAM: #include<stdio.h>

#include<conio.h>

void main (int argc,char *argv[])

{

FILE *fp1,*fp2;

char ch;

clrscr();

if(argc!=3)

{

printf("\n insufficient argument ");

exit(0);

}

fp1=fopen(argv[1],"r");

fp2=fopen(argv[2],"w");

if(fp1==NULL || fp2==NULL)

{

printf("\n unable to open file ");

exit(0);

}

while(!feof(fp1))

{

ch=fgetc(fp1);

fputc(ch,fp2);

}

printf("\n file successfully copied ");

fclose(fp1);

fclose(fp2);

getch();

}

95

Page 96: CP Lab Manual - Updated With CBTS

OUT PUT cc file1.c text1.txt text2.txt

./a.out

file successfully copied

Contents of text1.txt

Computer is an electronic device which gets an input from the user, processes it and gives the

output.

Contents of text2.txt

Computer is an electronic device which gets an input from the user, processes it and gives the

output.

RESULT Thus the c program to copy one file to another has been successfully completed

and the output was verified. 96