# Computer

Topics: Linked list, Binary tree, Binary search tree Pages: 37 (6438 words) Published: December 8, 2012
C and Data Structures Lab Manual

Lab Manual
Computer Engineering and Information Technology III Semester /  ‘K’ Scheme Prepared By K.ManiRaj M.Sc.,M.Phil., &  P.Vinitha M.Sc M.Phil Lecturer, Department of  CE/IT, M.S.P.V.L Polytechnic College, Pavoorchatram. M.S.P.V.L Polytechnic College, Pavoorchatram  Page 1

C and Data Structures Lab Manual

1A         Celsius to Fahrenheit Conversion and vice versa  Aim:
To write a ‘C’ program to convert the given temperature in degree centigrade to Fahrenheit and vice versa.

Flow chart:

Start

F=9.0/5.0*c+32

Print F

C=5.0/9.0*(F-32)

Print C

Stop

M.S.P.V.L Polytechnic College, Pavoorchatram

Page 2

C and Data Structures Lab Manual

Algorithm:
1. Read the temperature in degree Centigrade. 2. Convert the Centigrade to Fahrenheit using the formula F=9/5*c+32 3. Print the Celsius and Fahrenheit value. 4. Read the temperature in degree Fahrenheit. 5. Convert the Fahrenheit to Centigrade using the formula C=5/9*(F-32) 6. Print the Fahrenheit and Celsius value. 7. Stop

Program:
/* Program to convert Centigrade to Fahrenheit and vice versa */ #include #include void main() { float c,f; clrscr(); /*To convert Centigrade to Fahrenheit*/ printf("Enter the temperature in centigrade:"); scanf("%f",&c); f=9.0/5.0*c+32; printf("\n\t%.2f Centigrade=%.2f Fahrenheit",c,f); /*To convert Fahrenheit to centigrade*/ printf("\n\nEnter the temperature in Fahrenheit:"); scanf("%f",&f); c=5.0/9.0*(f-32); printf("\n\t%.2f Fahrenheit=%.2f Centigrade",f,c); getch(); }

Output:
Enter the temperature in centigrade:45 45.00 Centigrade=113.00 Fahrenheit Enter the temperature in Fahrenheit:114

M.S.P.V.L Polytechnic College, Pavoorchatram

Page 3

C and Data Structures Lab Manual

1B
Aim:

Simple Interest and Compound Interest Calculation

To write a ‘C’ program to find the simple interest and Compound interest for the Amount (P), Rate of Interest (R) and Number of years (N)

Flowchart:

Start

SI=(P*N*R)/100

CI=P*(1+R/100)^N-P

Print SI,CI

Stop Algorithm:
1. Read Principal (P), Rate of Interest (R) and Number of years (N). 2. Calculate Simple Interest (SI) and Compound Interest using the formula SI=(P*N*R)/100 CI=P * ((1+R)/100)^N –P 3. Display the result. 4. Stop

M.S.P.V.L Polytechnic College, Pavoorchatram

Page 4

C and Data Structures Lab Manual

Program:
/* Program to calculate Simple Interest and Compound Interest */ #include #include #include void main() { double p,n,r,si,ci,x; clrscr(); printf("Enter the principal:Rs "); scanf("%lf",&p); printf("Enter rate of interest:"); scanf("%lf",&r); printf("Enter number of years:"); scanf("%lf",&n); /* To calculate Simple Interest*/ si=p*n*r/100; /* To calculate Compound Interest*/ ci=pow((1+r/100),n)*p-p; /* Display the result*/ printf("\n\nSimple interest =Rs %.2lf\n\n",si); printf("Compound Interest =Rs %.2lf",ci); getch(); } // For pow function

Output:
Enter the principal:Rs 1000 Enter rate of interest:3 Enter number of years:5 Simple interest =Rs 150.00 Compound Interest =Rs 159.27

M.S.P.V.L Polytechnic College, Pavoorchatram

Page 5

C and Data Structures Lab Manual

1C
Aim:

To  perform arithmetic operation of two numbers

To write a program to read two numbers and print the sum, difference, product and quotient of the two numbers.

Algorithm:
1. Read the numbers a,b; 2. Calculate Sum=a+b Difference=a-b Product=a*b Quotient=a/b 3. Print sum, difference, product and the quotient. 4. Stop

Flowchart: Start

Sum=A+B Diff=A-B Pro=A*B Quo=A/B

Print Sum,Diff, Pro,Quo

Stop M.S.P.V.L Polytechnic College, Pavoorchatram

Page 6

C and Data Structures Lab Manual

Program:
/* Program to find sum, difference, product and quotient */ #include #include void main() { float a,b,sum,diff,pro,quo; clrscr(); printf("Enter the value for A:");...