Sei sulla pagina 1di 47

1 COMPUTER PRACTICE LABORATORY - I MANUAL For First year B.E/B.Tech.

Students (common to all branches) Anna University Madurai

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING COMPUTER PRACTICE LABORATORY I

2 SYLLABUS UNIT - I Introduction to Application Practical Exercises may be given in the Package application packages to acquire skills in word processing. Spread sheet and Power point. a) Word Processing 1. Document creation, Text manipulation with Scientific notations. 2. To create an advertisement in word 3. To illustrate the concept of mail merging, importing images, tables in Word 4. Drawing - flow Chart 5. Chart - Line, XY, Bar and Pie. 6. Formula - formula editor. b) Spread Sheet 7. Spread sheet - inclusion of object, Picture and graphics, protecting the document and sheet. 8. To create a spread sheet to analyze the marks of the students of a class and also to create appropriate charts. 9. Sorting and Import / Export features. c) Power point 10. To create the presentation for the department with power point using animation, Design Templates and Effective Presentation UNIT - II C Programming Basics Data types, Expression Evaluation, Condition Statements, Operators, and Expressions, IO Formatting, Decision Making, Looping 1. Operators and Expressions. 2. Control Structures. 3. Arrays 4. Functions 5. Pointers 6. Pointers and Functions 7. Structures and Unions 8. Files

3 CONTENTS S.No Date Topics UNIT - I 1 2 3 4 5 6 7 Document creation Text manipulation with Scientific notations Advertisement in Word Mail merge, Importing image, Tables in Word Drawing - Flow Chart Chart - Line, XY, Bar and Pie Formula - formula editor Spread sheet - inclusion of object, Picture and graphics, protecting the document and sheet To analyze the marks of the students and chart creation Sorting and Import / Export features PowerPoint presentation UNIT - II 11 12 13 14 15 16 17 18 19 DataTypes,Expression,Evaluation,Condition 25 Statements, Operators Sales Report Matrix Multiplication Alphabetical orders Fibonacci series & Factorial -functions Accessing array using pointers Pointers and Functions Mark sheet using structures Files 28 30 32 34 37 39 41 44 4 6 7 12 13 16 18 Staff Page Marks No obtained signature

8 9 10

19 20 24

4 Ex.No: 1 Date: DOCUMENT CREATION TEXT MANIPULATION WITH SCIENTIFIC NOTATIONS

Aim To create a document and manipulate text with scientific notations.

Procedure

1. Select StartProgramsMS-Office Microsoft word 2. Now new document window will be opened 3. Type the contents within the document and Perform the operations Like

a) Make some text bold type, underline & make italic b) Correct spellings & save the document with suitable name c) Change the text with different font types & size

(I) COMPUTER Definition Computer is an electronic machine which performs a particular task.

Parts of the Computer It has three components. They are i. ii. iii. CPU Input unit and Output unit.

CPU is the central Processing Unit which consists of three other units like ALU, Memory unit and Control unit. ALU means Arithmetic and Logic Unit which performs all arithmetic and logical operations. Memory unit is to store all programs and data. Control unit controls the overall system.

5 (II) Fundamentals of Computing Fundamentals of computing Fundamentals of computing ABS TEXTILES, 45,Car Street, Tiruchengode-637 204. 04288-233871. 4. Search for the word Computer and replace it with Computer System 5. Type the following at the end of the document: (A+B)2=A2+B2+2AB H2+O2H2O a+b=c 6. Save the document as Filename.doc 7. Close the document

Result Thus the document has been created and manipulated text with scientific notations..

6 Ex.No:2 Date: ADVERTISEMENT IN WORD

Aim To create an advertisement in Microsoft Word.

Procedure 1. Click start button all programs, Microsoft Office and then Microsoft word. 2. Then type the given advertisement. 3. In order to create a document, the text has to be typed in. As the text is typed in, it can be seen in the document window. The texts will automatically word-wrap to the next line in case it does not fit in the current line. 4. Using the alignment keyword center, the words in the documents is aligned center. 5. Using bold, italic and underline, we can highlight certain word which will be perfect for the advertisement. 6. We can also insert the word art to make the heading a little bolder and attractive. 7. Moreover MS-WORD offers a lot of facilities to format our documents like margin adjustment, alignment or text. Changing the text attributes, customizing, paragraphs, changing font styles sizes, inserting bullets and numbering, inserting header and footers, creating a table, inserting a graphic in a documents 8. The above facilities make our advertisement more attractive.

Result Using MS-Word, an attractive advertisement is created successfully.

7 Ex. No: 3 Date: Aim To prepare letters and send it to multiple recipients by using Mail merge. Procedure 1. Open the new document and type the following letter From The Head of the Department Department of CSE JKK Munrajah College of Technology, T.N.Palayam. To MAIL MERGES AND LETTER PREPARATION

Our Students are interested to visit your company on the first week of Next month. I kindly request you to give permission to us. Thanking You, Yours faithfully, HOD

2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14.

Select ToolsLetters and MailingsMail Merge Wizard Select document type as Letters Select starting document as Use the current document Select recipients as Type a new list Select Create New address list window appears Type the details which you want Save the address list as my address and go to next Select Write your letter Place the cursor at the To address in the document Select the Address block... and click OK Select the Greet line... and click OK Now the document looks like...

From The Head of the Department Department of CSE JKK Munrajah College of Technology, T.N.Palayam. To AddressBlock GreetingLine Our Students are interested to visit your company on the first week of Next month. I kindly request you to give permission to us. Thanking You, Yours faithfully, HOD 15. Select Preview your letters 16. Now the letter is ready for multiple recipients. 17. See all letters by clicking >> in the mail merge window. Output From The Head of the Department Department of CSE JKK Munrajah College of Technology, T.N.Palayam. To Mr. Rajan HCL Corporation Chennai Dear Mr.Rajan,Our Students are interested to visit your company on the first week of Next month. I kindly request you to give permission to us. Thanking You, Yours faithfully, HOD

9 From The Head of the Department Department of CSE JKK Munrajah College of Technology, T.N.Palayam. To Mr. Karthick CTS Technologies Chennai

Dear Mr.Karthick, Our Students are interested to visit your company on the first week of Next month. I kindly request you to give permission to us. Thanking You, Yours faithfully, HOD

Result Thus the letter has been created for multiple recipients using mail merge.

IMORTING IMAGE

Aim To import an image in word processing. Procedure 1. 2. 3. 4. Open the new document Select Insert menu bar Select Picture and choose the required picture Insert the Picture in to the document

10

Result The importing an image in word processing is done successfully. WORKING WITH TABLES Aim To create a table and use table formats and conversion operations. Procedure 1. Open the new document 2. Select Table menu bar, then choose insert table option

3. Type the following contents within the table and use table formats

11

S.No 1 2 3 4 5

Roll No 1001 1002 1003 1004 1005

Name Devika Kavitha Bhuvana Prabu Rani

M1 88 87 90 89 79

M2 84 97 98 88 93

4. Select TableConvert Table to Text option to convert a table into text by separating commas and Select Comma in the Table to Text option. S.No, Roll No, Name, M1, M2 1, 1001, Devika, 88, 84 2, 1002, Kavitha, 87, 97 3, 1003, Bhuvana, 90, 98 4, 1004, Prabu, 89, 88 5, 1005, Rani, 79, 93

5. Reverse the text into table by selecting TableConvert Text to Table option. S.No 1 2 3 4 5 Result Thus the table has been created and conversion operation is performed. Roll No 1001 1002 1003 1004 1005 Name Devika Kavitha Bhuvana Prabu Rani M1 88 87 90 89 79 M2 84 97 98 88 93

12 Ex. No: 4 Date: Aim To draw a flowchart in word processing. Procedure 1. Select InsertshapesFlowchart DRAWING - FLOWCHART

2. Select the Shape and draw the flowchart

Start Read ch Sum=0, sign=1 Ch?

1
Read x,n X=X*3.14/180
For( i=1; i<=n; i+=2)

2
Read x,n
X=X*3.14/180, sum=1, sign=-1

default
Print invalid choice

For( i=2; i<=n; i+=2)

Sum+=sign*pow(x,i)/fact(i) Sign= - sign

Sum+=sign*pow(x,i)/fact(i) Sign= - sign

Print sum

Print sum

Result

Stop

Thus the flowchart has been drawn using Auto shape tools

13 Ex.No: 5 Date: LINE CHART Aim To create a Line chart in Excel. Procedure 1. Type the following Roll No 1001 1002 1003 1004 1005 2. 3. 4. 5. 6. 7. 8. Output
Weight chart
70 60 50 40 30 20 10 0 aaa 1001 bbb 1002 ccc 1003 ddd 1004 eee 1005

MS-Word -CHART

Name aaa bbb ccc ddd eee

Weight 63 52 46 58 60

Select all data in the document Select InsertChart Choose chart type as Line Type the chart title as Weight chart Type X-axis title as Name and RollNo Type Y-axis title as Weight Click ok

Weight

Weight

Name and Rollno

14 XY CHART Aim To create a XY chart in MS-Word. Procedure 1. 2. 3. 4. 5. 6. 7. Select all data in the Document. Select InsertChart Choose chart type as XY Type the chart title as Weight chart Type X-axis title as Name and RollNo Type Y-axis title as Weight Click OK

Output

Weight chart
80 60 40 20 0 0 2 4 6 Name and RollNo

Weight

Weight

BAR CHART Aim To create a Bar chart in Excel. Procedure 1. 2. 3. 4. 5. 6. 7. Select all data in the worksheet Select InsertChart Choose chart type as Column and select Next and select Next Type the chart title as Weight chart Type X-axis title as Name and RollNo Type Y-axis title as Weight Click OK

15 OUTPUT
Weight Chart 70 60 50 40 30 20 10 0 aaa 1001 bbb 1002 ccc 1003 ddd 1004 eee 1005

Weight

Weight

Name and RollNo

PIE CHART Aim To create a Pie chart in Excel. Procedure 1. 2. 3. 4. 5. Output


Weight chart

Select all data in the worksheet Select InsertChart Choose chart type as Pie Type the chart title as Weight chart Click OK

1001 aaa 1002 bbb 1003 ccc 1004 ddd 1005 eee

Result Thus the charts Line, XY, Bar and Pie were created.

16 Ex. No: 6 Date: MS-WORD FORMULA EDITOR

Aim To perform some calculation in MS-Word by using Formula editor.

Procedure 1. Type the following in MS-Word RollNo 1 2 3 4 5 Total Average Name vimala Priya Divya Sudha Kavi English 63 52 96 84 75 Maths 57 56 89 87 76 Computer 62 54 90 88 74

2. Select layout dataformula

17 Output Name RollNo 1 2 3 4 5 Total Average vimala Priya Divya Sudha Kavi 63 52 96 84 75 370 123.33 57 56 89 87 76 365 121.67 62 54 90 88 74 368 122.67 English Maths Computer

Result Thus the total and average were calculated using Formulas.

18 Ex. No: 7 Date: Aim To include an object, Picture and graphics in a document. Procedure 1. 2. 3. 4. 5. 6. Select InsertObject Choose Object type as Bitmap Image and Click OK Now, Draw an object within the displayed window and Press Esc or click any other cell Select InsertPictureFrom file Type the filename to include as a Picture and Click Insert Now, the picture is included Output SPREAD SHEET INCLUSION of OBJECT, PICTURE and PROTECTION OF DOCUMENTS

PROTECTING THE DOCUMENT AND SHEET Aim To protect a document and worksheet. Procedure 1. 2. 3. 4. 5. 6. Result Thus the object and picture were included and the worksheet is protected. Select ToolsProtectionProtect Sheet Type the Password to protect sheet Choose Insert Rows, Insert Columns, Delete Rows and Delete Columns Reenter the password again Now, the data cant be removed from/inserted into the cell To unprotect the sheet, Select ToolsProtectionUnprotect Sheet

19 Ex. No: 8 Date: LINE CHART Aim To create a Line chart in Excel. Procedure 9. Type the following Roll No Name Weight 1001 1002 1003 1004 1005 10. 11. 12. 13. 14. 15. 16. 17. Output
Weight chart
70 60 50 40 30 20 10 0 aaa 1001 bbb 1002 ccc 1003 ddd 1004 eee 1005

SPREADSHEET-CHARTS

aaa bbb ccc ddd eee

63 52 46 58 60

Select all data in the worksheet Select InsertChart Choose chart type as Line and select Next and select Next Type the chart title as Weight chart Type X-axis title as Name and RollNo Type Y-axis title as Weight Click Next Click Finish

Weight

Weight

Name and Rollno

20 XY CHART Aim To create a XY chart in Excel. Procedure 8. 9. 10. 11. 12. 13. 14. 15. Output Select all data in the worksheet Select InsertChart Choose chart type as XY and select Next and select Next Type the chart title as Weight chart Type X-axis title as Name and RollNo Type Y-axis title as Weight Click Next Click Finish

Weight chart
80 60 40 20 0 0 2 4 6 Name and RollNo

Weight

Weight

BAR CHART Aim To create a Bar chart in Excel. Procedure 8. 9. 10. 11. 12. 13. 14. 15. Select all data in the worksheet Select InsertChart Choose chart type as Column and select Next and select Next Type the chart title as Weight chart Type X-axis title as Name and Roll No Type Y-axis title as Weight Click Next Click Finish

21 Output
Weight Chart 70 60 50 40 30 20 10 0 aaa 1001 bbb 1002 ccc 1003 ddd 1004 eee 1005

Weight

Weight

Name and RollNo

PIE CHART Aim To create a Pie chart in Excel. Procedure 6. 7. 8. 9. 10. 11. Output
Weight chart

Select all data in the worksheet Select InsertChart Choose chart type as Pie and select Next and select Next Type the chart title as Weight chart Click Next Click Finish

1001 aaa 1002 bbb 1003 ccc 1004 ddd 1005 eee

Result Thus the charts Line, XY, Bar and Pie were created.

22 Ex.No. 9 Date: SPREAD SHEET SORTING & IMPORT/EXPORT FEATURES

Aim To Sort the given data in the Excel worksheet.

Procedure 1. Type the following in Excel 5 4 3 2 1 vimala Priya Divya Sudha Kavi 500 400 300 200 100

2. Select the typed text 3. Choose DataSort 4. Choose Sort by as Column A and Ascending 5. Click OK Now it appears in the sorted order.

Output

1 2 3 4 5

Kavi Sudha Divya Priya Vimala

100 200 300 400 500

23 IMPORTING FEATURES Aim To Import the given data into Excel.

Procedure 1. Create a text file named text.txt and type the following 1001 aaa 10 1002 bbb 20 1003 ccc 30 1004 ddd 40 1005 eee 50

2. 3. 4. 5. 6. 7. 8. 9. 10.

Start Microsoft Excel: Go to StartProgramsMicrosoft Excel Click on FileOpen Open Text file text.txt The text Input Wizard will now appear with two choices: Delimited or Field width Select Delimited and Click Next Select Space as the delimiter and none as the Text qualifier and Click Next Click Finish. File is now in Excel Save the file in Excel format

Result Thus the given data are sorted and imported a text file into Excel.

24 Ex. No: 10 Date: Aim: To create a power point presentation for the department using animation, design templates and effective presentation Algorithm: 1. Start the power point presentation Go to start programs Microsoft office PowerPoint 2007 2. Open a new presentation and save it under some names. Go to file new presentation new slide 3. I) create a new slide with text and images. ii) Implement using the text box and insert image option to achieve these. iii) Add several slides with some text, images, sound etc (multimedia). 4. Use the design templates to make the presentation an effective one. Use the design templates option to make it effective one 5. Use the transition techniques to make that presentation in an graphical view 6. Save it and run the show using f5 key. OUTPUT POWER POINT PRESENTATIONS

Result: Thus the presentation created for the department with power point using animation, design templates and effective presentation.

25 Ex. No: 11 Date: Aim To write a C program to print the data types, expression evaluation and conditional statements. Algorithm Step-1: Step-2: Step-3: Step-4: Step 5; Step 6: Step-7: Data Types Program #include<stdio.h> #include<conio.h> void main () { int a, b, c, d; float average; printf(\n Enter the values:); scanf(%d%d%d, &a,&b,&c); d=a+b+c; printf(\n Total Value = %d,d); average=d/3; printf(\n Average of 3 numbers = %f, average); getch(); } Start the program Enter the values of a,b,c Calculate d=a+b+c Read the value of d Calculate avg=d/3 Print the values: avg,d Stop DATA TYPES, EXPRESSION EVALUATION AND CONDITIONAL STATEMENTS

26 OUTPUT Enter the values: 2 4 7 Total value =13 Average of three numbers=4.3333 EXPRESSION EVALUATION AND CONDITIONAL STATEMENTS Algorithm Step-1: Step-2: Step-3: Start the program Enter the values of a,b,c Calculate add e=a+b+c Calculate multi f=(a*b)*c Calculate div g=a/b Calculate total=e+f+g Calculate ans=((a+b)/c)*a Step-4: Step:5 Print the values: e,f,g,total,ans If total>ans Print total greater ans\ Else Print ans greater total Step-6: PROGRAM #include<stdio.h> #include<conio.h> void main() { float a,b,c,add,multi,div,total,ans,d; clrscr(); printf(\n Enter the values:); scanf(%f%f%f,&a,&b,&c); add=a+b+c; Stop

27 multi=(a*b)*c; div=a/b; total=add+multi+div; ans=((a+b)/c)*a; if(total>ans) { printf(\n Total is greater than ans); else printf(\n Ans is greater than total): } printf(\n Addition = %f,add); printf(\n Multiplication = %f,multi); printf(\n Division = %f, div); printf(\n Total = %f,total); printf(\n Answer = %f, ans); getch(); } Output: Enter the values 3.2,8,4 Addition = 15.2 Multiplication = 102.4 Division = 0.4 Total = 118 Answer = 8.96 Total is greater than ans Result Thus the program to print data types,expression evaluation and conditional statements were written and executed successfully.

28 Ex.No. 12 Date. Aim To write a C program to prepare and print the sales report. Algorithm Step-1: Step-2: Step-3: Step-4: Step-5: Step-6: Step-7: Step-8: Step-9: Step-10: Step-11: Step-12: Start the program Read the number of products n Setup a loop for n products Read the productID, qty and price totalqty*price Check if qty<=100 then calculate commtotal*5/100 Check if qty>100 or qty<=250 then calculate commtotal*10/100 Check if qty>250 or qty<=500 then calculate commtotal*20/100 Check if qty>500 or qty<=1000 then calculate commtotal*25/100 Check if qty>1000 then calculate commtotal*30/100 Setup a loop and print the results Stop SALES REPORT

Program #include<stdio.h> main() { int i,j,pid[10],price[10],qty[10],n,total[10],comm[10]; clrscr(); printf("Enter the number of products : "); scanf("%d",&n); printf("Enter Product ID, Quantity and Price : "); for(i=0;i<n;i++) { scanf("%d%d%d",&pid[i],&qty[i],&price[i]); total[i]=qty[i]*price[i]; if(qty[i]<=100) comm[i]=total[i]*5/100; else if(qty[i]>100||qty[i]<=250) comm[i]=total[i]*10/100; else if(qty[i]>250||qty[i]<=500)

29 comm[i]=total[i]*20/100; else if(qty[i]>500||qty[i]<=1000) comm[i]=total[i]*25/100; else comm[i]=total[i]*30/100; } printf("\nPID Quantity\tPrice\tTotal\tCommission\t\n"); printf("---------------------------------------------"); for(i=0;i<n;i++) printf("\n %d \t %d \t %d \t %d \t %d ",pid[i],qty[i],price[i],total[i],comm[i]); getch(); } Output Enter the number of products : 5 Enter Product ID, Quantity and Price : 1 10 10 2 20 20 3 30 30 4 40 40 5 50 50 PID Quantity Price Total Commission --------------------------------------------------1 2 3 4 5 10 20 30 40 50 10 20 30 40 50 100 400 900 5 20 45

1600 80 2500 125

Result Thus the program for preparing sales report was written and executed successfully.

30 Ex.No. 13 Date. Aim To write a C program to perform matrix multiplication. MATRIX MULTIPLICATION

Algorithm Step-1: Step-2: Start the program Read the number of rows and columns of matrices A and B (r1,c1) & (r2,c2) Step-3: If c1 = r2 then do the following Step-3.1: Setup a loop and read the elements of matrix A Step-3.2: Setup a loop and read the elements of matrix B Step-3.3: Multiply two matrices by C[i][j] C[i][j] + A[i][k] * B[k][j]; Step-3.4: Print the resultant matrix C Step-4: else Print c1 and r2 are not equal Step-5: Stop.

Program #include<stdio.h> main() { int r1,c1,r2,c2,i,j,k; int a[5][5],b[5][5],c[5][5]; clrscr(); printf("Enter the size of the A matrix : "); scanf("%d%d",&r1,&c1); printf("Enter the size of the B matrix : "); scanf("%d%d",&r2,&c2); if(c1==r2) { printf("Enter the elements of A matrix : \n"); for(i=0;i<r1;i++) for(j=0;j<c1;j++) scanf("%d",&a[i][j]); printf("Enter the elements of B matrix : \n"); for(i=0;i<r2;i++)

31 for(j=0;j<c2;j++) scanf("%d",&b[i][j]); for(i=0;i<r1;i++) for(j=0;j<c1;j++) { c[i][j]=0; for(k=0;k<c2;k++) c[i][j]=c[i][j]+a[i][k]*b[k][j]; } printf("Multiplication of A & B matrix : \n"); for(i=0;i<r1;i++) { for(j=0;j<c1;j++) printf("%5d",c[i][j]); printf("\n"); } } else printf("The number of rows and columns should be equal\n"); getch(); } Output Enter the size of the A matrix : 2 2 Enter the size of the B matrix : 2 2 Enter the elements of A matrix : 12 34 Enter the elements of B matrix : 12 34 Multiplication of A & B matrix : 7 10 15 22

Result Thus the program to print matrix multiplication was written and executed successfully.

32 Ex.No. 14 Date. ALPHABETICAL ORDERS

Aim To write a C program to arrange names in alphabetical order.

Algorithm Step-1: Step-2: Step-3: Step-4: Step-5: Step-6: Step-7: Step-8: Step-9: Step-10: Start the program Read the number of names n Setup a loop for n times Read the names Setup a loop i from 0 to n-1 Setup a loop j from i+1 to n-1 If (name[i] > name[j]) then swap them. Setup a loop for n times Print the sorted names Stop.

Program #include<stdio.h> main() { int i,j,k,n; char name[10][20],temp[10]; clrscr(); printf("Enter the number of names : "); scanf("%d",&n); printf("Enter %d names : \n",n); for(i=0;i<n;i++) scanf("%s",name[i]); for(i=0;i<n;i++) for(j=i+1;j<n;j++) if(strcmp(name[i],name[j])>0) { strcpy(temp,name[i]); strcpy(name[i],name[j]);

33 strcpy(name[j],temp); } printf("The sorted names are : "); for(i=0;i<n;i++) printf("\n%s",name[i]); getch(); } Output Enter the number of names : 5 Enter 5 names : calcutta bombay chennai delhi madurai The sorted names are : bombay calcutta chennai delhi Madurai

Result Thus the program for arranging names in alphabetical order was written and executed successfully.

34 Ex.No. 15 Date. FIBONACCI SERIES & FACTORIAL -FUNCTIONS

Aim To write a C program to print the Fibonacci series and to calculate the factorial of the given number using functions. Algorithm Step-1: Step-2: Step-3: Start the program Print the menu 1. Fibonacci 2. Factorial Read the choice

Step-4: If choice=1 Step-4.1 : Read the number of terms n Step-4.2 : Call the function fibonacci(n) Step-5: If choice=2 Step-5.1 : Read the number to compute factorial n Step-4.2 : Call the function factorial(n) Step-6: Stop.

Function fibonacci() Step-1: Step-2: Initialize 0 to f1 and 1 to f2 if n<2 then f10 and f21 else Step-2.1: call the function Fibonacci(n-1). Step-2.2: tf2; f2f1+f2; f1t; Step-2.3: Print f1 Step-3: Return to the main program

Function factorial() Step-1: if n=0 or 1 return 1

35 else return n*factorial(n-1)

Program #include<stdio.h> void fibonacci(int n) { static int f1=0,f2=1; int t; if(n<2) { f1=0; f2=1; } else { fibonacci(n-1); t=f2; f2=f1+f2; f1=t; } printf("%d\t",f1); return; } int fact(int n) { if(n==1 || n==0) return 1; else return n*fact(n-1); } main() { int n,ch; clrscr(); while(1) { printf("\n1.Fibonacci series\n2.Factorial\n3.Exit\n"); printf"Enter the choice : \n"); scanf("%d",&ch); switch(ch) { case 1: printf("Enter the number of terms : "); scanf("%d",&n); printf("Fibonacci sequence : \n",n); fibonacci(n);

36 break; case 2: printf("Enter the number to compute factorial : "); scanf("%d",&n); printf("Factorial of %d is : %d\n",n,fact(n)); break; case 3: exit(0); break; default: printf("Invalid choice!!!"); } } getch(); } Output 1.Fibonacci series 2.Factorial 3.Exit Enter the choice : 1

Enter the number of terms : 10 Fibonacci sequence : 0 1 1 2 3 5 8 13 21 34

1.Fibonacci series 2.Factorial 3.Exit Enter the choice : 2 Enter the number to compute factorial : 5 Factorial of 5 is : 120

Result Thus the program for printing Fibonacci series and computing of factorial for a given number was written and executed successfully.

37 Ex.no: 16 Date: Aim To print the elements of an array pointers Algorithm Step-1: Start the program Step-2: Read the numbers using for loop and store it in an array Step-3: Assign a pointer variable Step-4: Assign pointer_variable=&x[0] Step-5: Print *(pointer_variable+i) using for loop Step-6: End the program. Program #include<stdio.h> #include<conio.h> void main() { int i,n,a[10]; Int *ipa; clrscr(); printf(enter the number of elements:); scanf(%d,&n); printf(enter the elements one by:); for(i=0;i<n;i++) { scanf(%d,&a[i]); } printf(the elements present in the array is:\n); for(ipa=a;ipa<a+n;ipa++) { PRINTING THE ELEMENT OF AN ARRAY USING POINTERS

38 printf(%d\n,*ipa); } getch(); }

Output: Enter the number of elements: 5 Enter the elements one by one: 12 21 26 58 78 The elements present in the array are: 12 21 26 58 78

Result Thus the array of an elements are printed successfully.

39 Ex.No: 17 Date: SWAP TWO NUMBERS USING POINTERS AND FUNCTIONS

AIM To write a program to swap two number using pointer and functions

ALGORITHM Step-1 Step-2 Step-3 Step-4 Step-5 Step-6 Step-7 Step-8 Start the program Enter the two numbers Call the display function Pass the address of the two numbers of the Calling Get the address in the Calling function in the pointer swap the number using temporary variable Print the swamped values in the main function Stop

PROGRAM // SWAP THE NUMBER USING FUNCTIONS AND POINTERS #include<stdio.h> main() { int x,y; printf( nEnter the two numbers ); 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,x,y); } Display(int *a,int *b)

40 { int t; t=*a; *a=*b; *b=t; } OUTPUT: Enter the two numbers10 20 The entered number for x and y are, x=10 y=20 After the swapping the value of, x=20 y=10

Result The elements are swapped using arrays and functions successfully.

41 Ex.No. 18 Date. Aim To write a C program to print the mark sheet of n students using structures. MARK SHEET USING STRUCTURES

Algorithm Step-1: Step-2: Step-3: Step-4: Step-5: Step-6: Step-7: Step-8: Step-9: Step-10: Step-11: Program #include<stdio.h> struct class { int rno,m[6],tot; char name[10], grade[12]; float avg; }s[10]; main() { int i,j,n; clrscr(); printf("Enter the number of students : "); scanf("%d",&n); for(i=1;i<=n;i++) { printf("Enter the details for student %d : ",i); printf("\nRollno " ); Start the program Read the number of students n Setup a loop for n students Read Rollno, Student name and six subject marks Calculate the total and average If any one subject mark is less than 50 then grade = fail If average>=75 then grade=Distintction If average<75 and >=60 then grade=Firstclass If average<60 and >=50 then grade=Secondclass Print all the student details Stop.

42 scanf("%d",&s[i].rno); printf("\nStudent name "); scanf("%s",s[i].name); printf("Enter 6 subject marks : "); scanf("%d%d%d%d%d%d",&s[i].m[1],&s[i].m[2],&s[i].m[3],&s[i].m[4],&s[i].m[5],&s[i].m[6]); s[i].tot=s[i].m[1]+s[i].m[2]+s[i].m[3]+s[i].m[4]+s[i].m[5]+s[i].m[6]; s[i].avg=s[i].tot/6; if(s[i].m[1]<50||s[i].m[2]<50||s[i].m[3]<50||s[i].m[4]<50||s[i].m[5]<50||s[i].m[6]<50) strcpy(s[i].grade,"Fail"); else { 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"); } } printf("\n\t\t\t Student Mark List \n"); printf("R.No\tName\tTotal\tAverage\tGrade\n"); printf("============================================="); for(i=1;i<=n;i++) printf("\n %d\t%s\t%d\t%f\t%s",s[i].rno,s[i].name,s[i].tot,s[i].avg,s[i].grade); getch(); }

Output
Enter the number of students : 3 Enter the details for student 1 : Rollno 1 Student name kavi Enter 6 subject marks : 67 78 89 98 87 76

Enter the details for student 2 : Rollno 2 Student name prabu Enter 6 subject marks : 87 83 93 99 96 91

43 Enter the details for student 3 : Rollno 3 Student name suji Enter 6 subject marks : 45 56 67 76 72 56

Student Mark List R.No Name Total Average Grade

==================================== 1 2 3 kavi 495 82.000000 91.000000 62.000000 Distinction Distinction Fail

prabu 549 suji 372

Result Thus the program for printing students mark list using structures was written and executed successful.

44 Ex.No:19 Date: EMPLOYEE DETAILS USING FILES

AIM : To write a program of employee details handling file by using fscanf() and fprintf(). ALGORITHM Step-1 Step-2 Step-3 Step-4 Step-5 Step-6 Step-7 Step-8 Step-9 Start read filename open a file, filename read n Set a loop to get name, salary and age read name, salary, age from a file print name, salary, and age into the file close file fp1 End

PROGRAM #Include <studio.h> #Include <conio.h> void main() { FILE *fpl; int age,i,n; char filename[25],name[25]; float salary; clrscr(); printf(Enter the file name : ); scanf(%s,filename); fp1=fopen(filename,w);

45 printf(Enter the Number of employee : ); scanf(%d,&n); printf(Enter the Nae, Salay and Age:\n); for(i=1;i< =n;i++) { fscanf(stdin,%s%fd,&name,&salary,&age); fprintf(fp1,%s\t%f%d\n,name,salary,age); } fclose(fp1) fprintf(stdout, \n\n) fp1 =fopen(filename,r); printf(name salary age \n); printf(\n); for(i-1;i< =;i++); { fscanf(fp1,%s %f %d,name,&salary,age); fprintf(stdout,%s\t %8.2f\t %d\n,name,salary,age); } getch(); fclose(fp1) }

OUTPUT: Enter the filename : vrb Enter the Number of employee : 3 Enter the Name, Salary and Age: Venkat 10000 24 Ragu 15000 29 Shankar 20000 32

46 Name Venkat Ragu Shankar salary 10000 15000 20000 age 24 29 32

Result: The employment details given using files successfully.

47

Potrebbero piacerti anche