Sunteți pe pagina 1din 101

Ex.

No:1
SEARCH, GENERATE, MANIPULATE DATA USING MS OFFICE
AIM
To search, generate and manipulate data using ms office.
PROCEDURE
USING MS WORD
I. Justifying the text
1. Select the text you want to justify.
2. On the home tab, in the paragraph group, click justify button or
press CTRL+J
II. Centre the heading and make it bold. Increase the font size
1. Select the heading.
2. On the home tab,in the paragraph group,click Centre button or
press CTRL+E
3. On the home tab,in the font group,click Bold button or press
CTRL+B
4. On the home tab,in the font group,click Font size or
CTRL+SHIFT+p
USING EXCEL
1. Open a new excel blank work sheet
2. Enter the emp name, basic pay, DA, HRA, GS salary
3. To calculate HRA, click the cell and type =basic pay * 18%, likewise
calculate for DA with 15% of basic pay
4. To find GS, click =basic +HRA+ DA
5. Then sort all the employee names in alphabetical order
6. To perform a decimal to binary conversion use =DEC2BIN (NUM) .
likewise calculate Decimal to octal and decimal to hexadecimal using
=DEC2OCT (NUM), DEC2HEX (NUM) respectively.
7. To calculate measurement conversion, perform the following operation
a. For hours to minute conversion , CONVERT (number,hr,mn) .
b. For hours to second conversion, CONVERT (number,hr,sec).
c. For Celsius to Fahrenheit, CONVERT (number,C,F).
d. For Celsius to Kelvin, CONVERT (number,C,K).
e. For meter to centimeter, CONVERT (number,m,cm)
f. For meter to kilometer, CONVERT (number,m,km)
8. To convert the dollar to rupees multiply the dollar value with 55.37
(ex:=4*55.37).To search data->click find from home, then specify the
name to search and click find all.
1

9. Save the Spread sheet and Close it.

TABLE CREATION AND TABLE FORMATTING


PROCEDURE
1. Create the table using Insert-> Table from menu and specify the
required number of rows and columns.
2. Type the required information, to change the text alignment choose the
text and alter the angle properties of the text from choosing Table
tools->layout on the menu bar.
3. To combine two cells, select the cells that are to be merged then
choose table tools, layout from menu and click merge cells.
4. To split cells choose Table tools->layout from menu and click split cells.
5. To convert a table to text and vice versa, choose Table tools- > layout
from menu and click convert accordingly.
6. To Apply Borders, Shading Select the cell, rows, or columns you want to
add borders, shading and color.
7. Either right click within your table and choose Table properties or
click within your table and go to Table on the menu bar and choose
Table properties.
8. Choose the setting style, the color and the width that you want.
9. Click OK then new settings will be added to the table
10.
Save the document and close it.
MAIL MERGE AND LETTER PREPARATION
PROCEDURE
1.
2.
3.
4.

Open the word processor


Go to menu, Mailings->start mail merge wizard.
Start writing a letter
Go to select Recipients->Type new list, create a list of recipients of the
letter.
5. Go to Insert Merge fields; select the appropriate fields matching the
recipient list fields in to the document.
6. To include the recipients into the letter, on the menu select Finish
merge ->edit individual documents->merge all records.
7. Save the letter and close it.

OUTPUT
S EARCH ,

GENERATE , MANIPULATE DATA USING

MS

OFFICE

GENERATING DATA:
Computer is an electronic machine that accepts data from user,
processes data by performing calculations and operations on it and
generates desired output results.

Computers are classified as

Micro computers
Mini computers
Mainframe computers
Super computers

M ANIPULATING D ATA :
S EARCHING

DATA :

Random Access Memory is volatile .Read only Memory is non-volatile.


Computer

MS EXCEL
PAYROLL OF THE COMPANY
BEFORE SORTING
EMP
NAME
SURESH
SATISH
SANJAY
RAM
NARESH

BASIC
PAY
DA
5400
7500
6500
5000
8000

HRA
810
1125
975
750
1200

GS
972
1350
1170
900
1440

7182
9975
8645
6650
10640

AFTER SORTING
EMP
NAME
NARESH
RAM
SANJAY
SATISH
SURESH

BASIC
PAY
8000
5000
6500
7500
5400

DA
1200
750
975
1125
810

HRA
1440
900
1170
1350
972

GS
10640
6650
8645
9975
7182

DECIMAL TO BINARY, OCTAL, HEXADECIMAL CONVERSIONS


Decimal
24

Binary
11000

octal
30
4

Hexadeci
mal
18

45
28
99
31

101101
11100
1100011
11111

55
34
143
37

2D
1C
63
1F

HOURS TO MINUTES AND SECONDS


Hours
1
16
22
18
20

Minute
60
960
1320
1080
1200

Seconds
3600
57600
79200
64800
72000

CELSIUS TO FAHRENHEIT AND KELVIN


Celsius
31
22
40
48
38

Fahrenheit
87.8
71.6
104
118.4
100.4

Kelvin
304.15
295.15
313.15
321.15
311.15

METER TO CENTIMETER AND KILOMETER


Metre
100
1000
423
778
567

Centimetre
10000
100000
42300
77800
56700

Kilometre
0.1
1
0.423
0.778
0.567

DOLLAR TO RUPEES
Dollar
1
56

Rupees
55.37
3100.72
5

100
250
35

5537
13842.5
1937.95

SEARCHING THE DATA


EMP
NAME
SURESH
SATISH
SANJAY
RAM
UMA

BASIC
PAY
DA
5400
7500
6500
5000
8000

HRA
810
1125
975
750
1200

GS
972
1350
1170
900
1440

7182
9975
8645
6650
10640

TABLE CREATION AND TABLE FORMATTING


SAMPLE TABLE FOR ANNUAL RAINFALL
TABLE TO TEXT
PLACE

ANNUAL RAINFALL IN CITIES IN CENTIMETRES


JAN FEB MAR APR MAY JUNE JULY AUG SEP OCT NOV
DEC

DELHI
BANGALORE
147
MUMBAI

22 17

65

211 173 150 31

2 11

13

24

11

70

165 170 101 60

30

107 165 100 59

12
203

20
23 10

47

52

13

HYDERABAD
4
CHENNAI

7
15 17

11

23

35

74

82

113 120 117

13

23

21

27

35

40

41

169 180 110

TEXT TO TABLE
PLACE
DELHI

ANNUAL
JA
FE
N
B
22 17

RAINFALL IN
MA AP
R
R
7
8

BANGALOR 2
E
MUMBAI
23

11

13

24

10

47

11

HYDERABA
D
CHENNAI

11

15

17

13

23

CITIES IN CENTIMETRES
MA JUN JUL AU SE
Y
E
Y
G
P
65
211 173 15
31
0
30
107 165 10
59
0
70
165 170 10
60
1
23
35
74
82
11
3
21
27
35
40
41

OC
T
1

NO
V
5

20
3
52

147 20

12
0
16
9

117 4

13

DE
C
12

180 11
0

APPLYING BORDERS AND SHADING


PLACE

ANNUAL RAINFALL IN CITIES IN CENTIMETRES


JA
N

FE
B

MA
R

AP
R

MA
Y

JUN
E

JUL
Y

AU
G

SE
P

OC
T

NO
V

DE
C

22

17

65

211

173

15
0

31

12

BANGALOR 2
E

11

13

24

30

107

165

10
0

59

20
3

147 20

MUMBAI

23

10

47

11

70

165

170

10
1

60

52

13

HYDERABA
D

11

23

35

74

82

11
3

12
0

117 4

CHENNAI

15

17

13

23

21

27

35

40

41

16
9

180 11
0

DELHI

MAIL MERGE AND LETTER PREPARATION

SAMPLE LETTER WITH MERGE FIELDS


FROM
THE PRINCIPAL,
INFO Institute of Engineering,
Coimbatore.
TO
First_Name
Address_Line_1
8

City
State
ZIP_Code
Dear Student,
Sub: Reporting the date of opening.
As we are opening the college the college on 5.08.2013 for
the first semester, we request all students to be here on that day without
fail.
Thanking you.

Yours truthfully,
Principal-INFO.

AFTER MAIL MERGE


FROM
THE PRINCIPAL,
INFO Institute of Engineering,
Coimbatore.
TO
NARESH
VELANDIPALAYAM
COIMBATORE
TAMIL NADU
641017
9

Dear Student,
Sub: Reporting the date of opening.
As we are opening the college the college on 5.08.2013 for
the first semester, we request all students to be here on that day without
fail.
Thanking you.

Yours truthfully,
Principal-INFO.

10

FROM
THE PRINCIPAL,
INFO Institute of Engineering,
Coimbatore.
TO
RAM
ANNUR
COIMBATORE
TAMIL NADU
641000
Dear Student,
Sub: Reporting the date of opening.
As we are opening the college the college on 5.08.2013 for
the first semester, we request all students to be here on that day without
fail.
Thanking you.

Yours truthfully,
Principal-INFO.

Result:
Thus the search, generate and manipulate data using ms office is
executed and the output is verified.

11

Ex.No: 2
PRESENTATION AND VISUALIZATION USING GRAPHS, CHARTS, 2D
AND 3D
AIM
To generate the output for presentation and visualization using graphs,
charts, 2D and 3D
USING EXCEL
PROCEDURE
1. Enter the Data in the Spread Sheet.
2. Choose Chart option from Insert Menu.
3. Chart Type Dialog Box will appear and select the type of Chart needed
to be drawn.
4. To change the chart layout go to Design->chart Layouts on Menu and
Select the layout style needed.
5. To include chart title go to Layout->Chart Title and Select it.
6. To include Horizontal and Vertical Axis in the Chart, go to Layout->Axis
Title and Select the axis.
7. To include Data labels in the chart, go to Layout-> Data Label and
choose its position.
8. To change the Axis Data Range, go to Design ->Select Data, edit in the
Select Data Source Dialog box.
9. Save the Spreadsheet and Close it.
POWERPOINT PRESENTATION
PROCEDURE
1. Open a power point presentation and insert a text box, insert tab->text
box option
2. Add the text computer practices laboratory
3. Increase the font size and change the font style
4. Changing fill color of text box, Select text box->open format tab>shape and fill option
5. Changing text color, select->text box->format tab->text fill option
6. Special text effects, select text box->format tab->text box option
7. Smart art feature, type Microsoft office, Microsoft word, Microsoft excel,
Microsoft power point in your text
8. Inserting shapes, insert tab->shapes option
9. Inserting picture, insert tab->picture
12

10.
Re coloring image, format->picture tools->re color->option
11.
Picture effects, format->picture tools->picture effect
12.
Inserting chart, insert tab->chart option->select chart->ok->fill
the data.
OUTPUT:
PRESENTATION AND VISUALIZATION USING GRAPHS, CHARTS, 2D
AND 3D
USING EXCEL

13

STUDENT MARK LIST

STUDENT
NAME
Anand
Vasanth
Sudha

SUBJECT
PHYSIC COMPUTE
MATHS S
R
75
85
86
86
85
88
55
76
98
2D COLUMN CHART
98

100
90
80

86

86 88

85 85
76

75

70

Anand

55

60

Vasanth

50

Sudha

40
30
20
10
0

3D COLUMN CHART

88
86

76

55

14
0

20

40

60

75
80

98

Anand
Vasanth

85
85

Sudha

86

100

120

POWERPOINT PRESENTATION

15

16

17

18

Result:
Thus the presentation and visualization using graphs, charts, 2D and
3D is executed and the output is verified.
19

Ex.No: 3
PROBLEM FORMULATION, PROBLEM SOLVING AND FLOWCHARTS
AIM
To formulate and solve a problem using flowcharts.
PROCEDURE
1.
2.
3.
4.
5.
6.

Open a new document


On the menu, select Insert->shapes->Flowchart.
Place the shape by clicking anywhere in the document.
Repeat this for each shape that you want to add.
To add the text, click the shape and type the text.
Save the document and close it.

OUTPUT:
PROBLEM FORMULATION, PROBLEM SOLVING AND FLOWCHARTS
FLOWCHART
PRODUCT OF TWO NUMBERS

Start

Read A,B

C=A*B

Print C

Stop
20

MAXIMUM OF THREE NUMBERS

Start

Read A,B,C

Is A>B

No

Yes
MAX=A

MAX=B

Is MAX>C

No

Yes
Print MAX

Print C

Stop

21

ROOTS OF QUADRATIC EQUATION


Start

Read a,b,c

d=b*b4*a*c

Is d>=0

No

Yes
Root1=-b+sqrt(d)/
(2*a)
Root2=-b-sqrt(d)/

Print Root1, Root2

Stop

22

Print Roots are


imaginary

SUM OF FIRST 100 INTEGERS

Start

Sum=0
I=0

I=I+1
Sum=sum

No

Is I>=100

Yes
Print sum

Stop

Result:
Thus the formulate and solve a problem using flowcharts is executed
and the output is verified.

23

Ex.No:4
C PROGRAMMING USING SIMPLE STATEMENTS AND EXPRESSIONS
AIM
To write a c program using simple statements and expressions

ADDITION OF TWO NUMBERS


ALGORITHM
Step 1: Start the program
Step 2: Declare the variables
Step 3: Get the input for the variables
Step 4: Find the sum of given numbers
Step 5: Print the result
Step 6: Stop the program.
PROGRAM
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf("ADDITION OF TWO NUMBERS\n");
printf("Enter the value of a:");
scanf("%d",&a);
printf("\nEnter the value of b:");
scanf("%d",&b);
24

c=a+b;
printf("\nResult of Addition:%d",c);
getch();
}

OUTPUT
ADDITION OF TWO NUMBERS
Enter the value of a:10
Enter the value of b:20
Result of Addition:30

AREA AND CIRCUMFERENCE OF CIRCLE


ALGORITHM
Step 1: Start the program
Step 2: Input the radius of the circle
Step 3: Find the area and circumference of the circle using the formula
area = 3.14*r*r
circumference = 2*3.14*r
Step 4: Print the result
Step 5: Stop the program.
PROGRAM
#include<stdio.h>
#include<conio.h>
void main()
{
25

int r;
float area,circum;
clrscr();
printf("AREA AND CIRCUMFERENCE OF CIRCLE\n");
printf("Enter the radius of circle:\n");
scanf("%d",&r);
area=3.14*r*r;
circum=2*3.14*r;
printf("Area of Circle:%f\n",area);
printf("Circumference of Circle:%f",circum);
getch();
}
OUTPUT
AREA AND CIRCUMFERENCE OF CIRCLE
Enter the radius of circle:
3
Area of Circle:28.260000
Circumference of Circle:18.840000

CELSIUS TO FAHRENHEIT CONVERSION


ALGORITHM
Step 1: Start the program
Step 2: Input the Celsius value
Step 3: Calculate the Fahrenheit value using the formula
fahrenheit = (1.8*Celsius)+32
26

Step 4: Print the Fahrenheit vlaue


Step 5: Stop the program.
PROGRAM
#include<stdio.h>
#include<conio.h>
void main()
{
int cel;
float fahren;
clrscr();
printf("CELSIUS TO FAHRENHEIT CONVERSION\n");
printf("Enter the celsius value:\n");
scanf("%d",&cel);
fahren=(1.8*cel)+32;
printf("Fahrenheit value is:%f",fahren);
getch();
}
OUTPUT
CELSIUS TO FAHRENHEIT CONVERSION
Enter the [elsius value:
5
Fahrenheit value is:41.000000

27

ROOTS OF QUADRATIC EQUATION


ALGORITHM
Step 1: Start the program
Step 2: Read the value of a,b,c
Step 3: Find the value of d using the formula d=b*b-4*a*c
Step 4: If d is greater than or equal to zero, then find the two roots
root1=(-b+sqrt(d))/(2*a);
root2=(-b-sqrt(d))/(2*a);
Step 5: Print the root
Step 6: If d is not greater than or equal to zero, then print roots are
imaginary.
Step 7: Stop the program.
PROGRAM
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int a,b,c,d;
float root1,root2;
clrscr();
printf("ROOTS OF QUADRATIC EQUATION\n");
printf("Enter the values of a,b,c:");
scanf("%d %d %d",&a,&b,&c);
d=b*b-4*a*c;
28

if(d>=0)
{
root1=(-b+sqrt(d))/(2*a);
root2=(+b+sqrt(d))/(2*a);
printf("Roots of a=%d,b=%d,c=%d are %f %f",a,b,c,root1,root2);
}
else
{
printf("Roots are Imaginary");
}
getch();
}
OUTPUT
ROOTS OF QUADRATIC EQUATION
Enter the values of a,b,c:1 4 3
Roots of a=1,b=4,c=3 are -1.000000 3.000000

SIZE OF DATA TYPES


ALGORITHM
Step 1: Start the program
Step 2: Declare the variables with different data types
Step 3: print the size values using sizeof(variable)
Step 4: Stop the program
PROGRAM
#include<stdio.h>
#include<conio.h>
29

void main()
{
int i=0;
float f=25.005;
char name[]="Welcome";
clrscr();
printf("SIZE OF DATA TYPES");
printf("Size of Integer:%d\n",sizeof(i));
printf("Size of float:%d\n",sizeof(f));
printf("Size of character:%d\n",sizeof(name));
getch();
}
OUTPUT
SIZE OF DATA TYPES
Size of Integer:2
Size of float:4
Size of character:8

LARGEST OF THREE NUMBERS


ALGORITHM
Step 1: Start the program
Step 2: Read the values of x,y,z
Step 3: Check a >b. If true, then compare a with c.
if conditions is true print a is the biggest value
else print C is the biggest.
30

Step 4: Check a >b. if the result is false, Then compare b with c.


If the condition is true print b is the biggest value
Else print C is the biggest.
Step 5: Print the result
Step 6: Stop the program.
PROGRAM
#include<stdio.h>
#include<conio.h>
void main()
{
int x,y,z,big;
clrscr();
printf("LARGEST OF THREE NUMBERS\n");
printf("Enter the three numbers:");
scanf("%d %d %d",&x,&y,&z);
big=x;
if(y>big)
big=y;
if(z>big)
big=z;
printf("\nBiggest number is:%d",big);
getch();}
OUTPUT
LARGEST OF THREE NUMBERS
Enter the three numbers:5 2 8
31

Biggest number is:8


EVEN OR ODD NUMBER
ALGORITHM
Step 1: Start the program
Step 2: Read the values of n
Step 3: If the value of n%2==0, then print the number is even
Step 4: If the value of n%2 0, then print the number is odd
Step 5: Stop the program.
PROGRAM
#include<stdio.h>
#include<conio.h>
void main()
{
int n;
clrscr();
printf("EVEN OR ODD NUMBER\n");
printf("Enter the number:");
scanf("%d",&n);
if(n%2==0)
printf("\n%d is an even number",n);
else
printf("\n%d is an odd number",n);
getch();
}

32

OUTPUT
EVEN OR ODD NUMBER
Enter the number:6
6 is an even number

LEAP YEAR
ALGORITHM
Step 1: Start the program
Step 2: Read the values of year
Step 3: If the value of year%4==0, then print leap year
Step 4: If the value of year%4==0, then print not leap year
Step 5: Stop the program.
PROGRAM
#include<stdio.h>
#include<conio.h>
void main()
{
int year;
clrscr();
printf("LEAP YEAR OR NOT\n");
printf("Enter the year:");
scanf("%d",&year);
if(year%4==0)
printf("\n%d is a leap year",year);
33

else
printf("\n%d is not a leap year",year);
getch();
}
OUTPUT
LEAP YEAR OR NOT
Enter the year:2000
2000 is a leap year

SIMPLE INTEREST AND COMPOUND INTEREST


ALGORITHM
Step 1: Start the program
Step 2: Read the values of p,n,r
Step 3: Calculate the simple interest using the formula SI=(p*n*r)/100
Step 4: Calculate the value of q using the formula q=1+(r/100)
Step 5: Calculate the compound interest using the formula CI=p*pow(q,n)
Stop 6: Stop the program.
PROGRAM
#include<stdio.h>
#include<conio.h>
void main()
{
int n;
float p,q,r,SI,CI;
clrscr();
34

printf("SIMPLE INTEREST AND COMPOUND INTEREST\n");


printf("Enter the value of p:");
scanf("%f",&p);
printf("\nEnter the value of r:");
scanf("%f",&r);
printf("\nEnter the value of n:");
scanf("%d",&n);
SI=(p*n*r)/100;
printf("Simple Interest SI:%f",SI);
q=1+(r/100);
CI=p*pow(q,n);
printf("\nCompound Interest CI:%f",CI);
getch();
}

OUTPUT
SIMPLE INTEREST AND COMPOUND INTEREST
Enter the value of p:2000
Enter the value of r:12
Enter the value of n:2
Simple Interest SI:480.000000
Compound Interest CI:30980000.000000
Result:
Thus the c programs using simple statements and expressions are
executed and the output is verified.
35

Ex.no 5
SCIENTIFIC PROBLEM SOLVING USING DECISION MAKING AND
LOOPING
AIM
To write a c program for scientific problem solving using decision
making and looping
TRIANGLE OF NUMBERS
ALGORITHM
Step 1: Start the program
Step 2: Read the number of lines in triangle
Step 3: Initialize l to 1
Step 4: Set loop for i=1,j=n to less than or equal to n
Step 5: Set loop for j=1 to less than or equal to i,
Step 6: Stop the program.
PROGRAM
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,j;
clrscr();
printf(TRIANGLE OF NUMBERS);
printf(\nEnter the number of lines in triangle:);
scanf("\t%d",&n);
for(i=1;i<=n;i++)

36

{
for(j=1;j<=i;j++)
printf(" %d ",j);
printf("\n");
}
getch();
}
OUTPUT
TRIANGLE OF NUMBERS
Enter the number of lines in triangle:5
1
1

1 2

1
1 2

2
3

3
4

4
5

FACTORIAL OF A NUMBER
ALGORITHM
Step 1: Start the program
Step 2: Read the number
Step 3: Set a loop to find factorial of given number using the formula
fact=fact*i
Step 4: Print the factorial of given number
Step 5: Stop the program.
PROGRAM
37

#include<stdio.h>
#include<conio.h>
void main()
{
int fact=1,i,num;
clrscr();
printf("FACTORIAL OF A NUMBER\n");
printf("Enter the number:");
scanf("%d",&num);
for(i=1;i<=num;i++)
{
fact=fact*i;
}
printf("\nFactorial of %d is %d",num,fact);
getch();
}
OUTPUT
FACTORIAL OF A NUMBER
Enter the number:5
Factorial of 5 is 120.

FIBONACCI SERIES
ALGORITHM
Step 1: Start the program
Step 2: Read the number
38

Step 3: Check whether the number is zero or not


Step 4: If zero, print zero value or go further
Step 5: Set a loop on the given number
fib=fib+a
a=b
b=fib
Step 6: Every increment in the loop prints the value of fib
Step 7: Stop the program.
PROGRAM
#include<stdio.h>
#include<conio.h>
void main()
{
int num,fib=0,a=0,b=1,i;
clrscr();
printf("FIBONACCI SERIES\n");
printf("Enter the number:");
scanf("%d",&num);
if(num==0)
printf("0");
else
{
for(i=0;i<num;i++)
{
fib=fib+a;
a=b;
39

b=fib;
printf("%d\t",fib);
}
}
getch();
}

OUTPUT
FIBONACCI SERIES
Enter the number:5
0

MENU DRIVEN CALCULATOR


ALGORITHM
Step 1: Start the program
Step 2: Display the menu
Step 3: Read the values of a,b
Step 4: Use switch to evaluate with case constants
Step 5: If case=1, c=a+b, print c and goto step 11
Step 6: If case=2, c=a-b, print c and goto step 11
Step 7: If case=3, c=a*b, print c and goto step 11
Step 8: If case=4, c=a/b, print c and goto step 11
Step 9: If case=0, exit(0) and goto step 11
Step 10: If case is invalid, print invalid using default case and goto step 11
Step 11: Stop the program.

40

PROGRAM
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,n,ch;
clrscr();
printf("MENU DRIVEN CALCULATOR\n");
printf("Menu\n");
printf("1 Addition\n");
printf("2 Subtraction\n");
printf("3 Multiplication\n");
printf("4 Division\n");
printf("5 Exit\n");
printf("Enter two numbers:");
scanf("%d %d",&a,&b);
do
{
printf("Enter your choice:");
scanf("%d",&n);
switch(n)
{
case 1:
c=a+b;
printf("Addition:%d\n",c);
41

break;
case 2:
c=a-b;
printf("Subtraction:%d\n",c);
break;
case 3:
c=a*b;
printf("Multiplication:%d\n",c);
break;
case 4:
c=a/b;
printf("Division:%d\n",c);
break;
case 5:
//exit(0);
break;
default:
printf("Invalid");
}
printf("\nDo you want to continue:");
scanf("%s",&ch);
}while(ch!='N');
getch();
}
OUTPUT
MENU DRIVEN CALCULATOR
Menu
42

1 Addition
2 Subtraction
3 Multiplication
4 Division
5 Exit
Enter two numbers:20 10
Enter your choice:1
Addition:30
Do you want to continue:y
Enter your choice:2
Subtraction:10
Do you want to continue:y
Enter your choice:3
Multiplication:200
Do you want to continue:y
Enter your choice:4
Division:2
Do you want to continue:y
Enter your choice:0
Invalid
Do you want to continue:N

SUM, REVERSE AND PALINDROME OF A NUMBER


ALGORITHM
Step 1: Start the program
Step 2: Read the number
Step 3: Set a loop upto number not equal to zero
43

rem=num%10
sum=sum*10+rem
rnum=rnum*10+rem
num=num/10
Step 4: After end of loop, print sum of digits and reverse number of digit
Step 5: Find whether the reverse number is equal to given number or not
Step 6: If equal, print number is palindrome
Step 7: If not equal, print number is not palindrome
Step 8: Stop the program.
PROGRAM
#include<stdio.h>
#include<conio.h>
void main()
{
int a,num,sum=0,rnum=0,rem;
clrscr();
printf("SUM,REVERSE AND PALINDROME OF A GIVEN NUMBER\n");
printf("Enter the number:");
scanf("%d",&num);
a=num;
while(num!=0)
{
rem=num%10;
sum=sum+rem;
rnum=rnum*10+rem;
num=num/10;
44

}
printf("\nSum of digits:%d",sum);
printf("\nReverse of a number:%d",rnum);
if(a==rnum)
printf("\nGiven number is a palindrome number");
else
printf("\nGiven number is not a palindrome number");
getch();
}
OUTPUT
SUM,REVERSE AND PALINDROME OF A GIVEN NUMBER
Enter the number:121
Sum of digits:4
Reverse of a number:121
Given number is a palindrome number

PRIME NUMBER OR NOT


ALGORITHM
Step 1: Start the program
Step 2: Read the number
Step 3: Set a loop until value of I is less than umber
Step 4: Inside the loop num%i==0, give break statement
Step 5: If value of i==num, print number is prime
Step 6: If value of I is not equal to num, print number is not prime
Step 7: Stop the program.

45

PROGRAM
#include<stdio.h>
#include<conio.h>
void main()
{
int num,i=2;
clrscr();
printf("PRIME NUMBER OR NOT\n");
printf("Enter the number:");
scanf("%d",&num);
while(i<=num-1)
{
if(num%i==0)
{
printf("\nNumber is not prime");
break;
}
i++;
}
if(i==num)
printf("\nNumber is prime");
getch();
}
OUTPUT
PRIME NUMBER OR NOT
46

Enter the number:5


Number is prime.

RESULT

47

Thus a c program for scientific problem solving using decision making


and looping is executed and the output is verified.

Ex.No 6
SIMPLE PROGRAMMING FOR ONE DIMENSIONAL AND TWO
DIMENSIONAL ARRAYS
AIM
To write a c program for one dimensional and two dimensional arrays.

SUM AND AVERAGE OF GIVEN NUMBERS


ALGORITHM
Step 1: Start the program
Step 2: Enter the size of the array
Step 3: Enter the elements of the array
Step 4: Set a loop up to the size of the array
Step 5: Find the sum of the array
Step 6: After the execution of the loop, print the sum and average of the
array
Step 7: Stop the program.
PROGRAM
#include<stdio.h>
#include<conio.h>
void main()
{
int a[100],i,no,sum=0;
float avg=0;
48

clrscr();
printf("SUM AND AVERAGE OF GIVEN NUMBERS\n");
printf("Enter the number of elements:");
scanf("%d",&no);
printf("\nEnter the numbers:");
for(i=0;i<no;i++)
{
scanf("%d",&a[i]);
sum=sum+a[i];
}
avg=(float)sum/no;
printf("Sum=%d\nAverage=%f",sum,avg);
getch();
}

OUTPUT
SUM AND AVERAGE OF GIVEN NUMBERS
Enter the number of elements:5
Enter the numbers:1 2 3 4 5
Sum=15
Average=3.000000

INSERTING AN ELEMENT IN AN ARRAY


ALGORITHM
Step 1: Start the program
49

Step 2: Enter the size of the array


Step 3: Enter the elements of the array
Step 4: Print the elements of the array
Step 5: Enter the element to be inserted and its position in the array
Step 6: Set a loop up to the position entered
Step 7: Push the order of the position by one, which are greater than the
position entered
Step 8: Insert the element in the position entered
Step 9: Print the array after insertion of the element
Step 10: Stop the program.
PROGRAM
#include<stdio.h>
#include<conio.h>
void main()
{
int a[100],no,i,pos,item;
clrscr();
printf("INSERTING ELEMENT IN AN ARRAY\n");
printf("Enter the size of the array:");
scanf("%d",&no);
printf("\nEnter the elements of array:");
for(i=0;i<no;i++)
scanf("%d",&a[i]);
printf("\nEntered elements of array:");
for(i=0;i<no;i++)
50

printf("\n%d",a[i]);
printf("\nEnter the position and the element to be inserted:");
scanf("%d%d",&pos,&item);
no++;
for(i=no;i>=pos;i--)
a[i]=a[i-1];
a[pos]=item;
printf("\n");
printf("\nArray after insertion:");
for(i=0;i<no;i++)
printf("\n%d",a[i]);
getch();
}

OUTPUT
INSERTING ELEMENT IN AN ARRAY
Enter the size of the array:5
Enter the elements of array:1 2 3 4 5
Entered elements of array:
1
2
3
4
5
Enter the position and the element to be inserted:3 10
51

Array after insertion:


1
2
3
10
4
5

ASCENDING OR DESCENDING ORDER OF THE GIVEN ARRAY


ALGORITHM
Step 1: Start the program
Step 2: Enter the size of the array
Step 3: Enter the elements of the array
Step 4: Set a loop up to the array size minus one
Step 5: Set a inner loop up to the size of the array
Step 6: Check whether the next array element is greater than or not
Step 7: If greater than exchange their position and if not greater then go to
the loop
Step 8: After the execution of the inner loop the outer loop is executed
Step 9: Print the ascending and descending order of the given array
Step 10: Stop the program.
PROGRAM
#include<stdio.h>
#include<conio.h>
void main()
52

{
int num[100],no,i,j,a;
clrscr();
printf("ASCENDING AND DESCENDING ORDER OF GIVEN ARRAY\n");
printf("Enter the number of elements in array:");
scanf("%d",&no);
printf("\nEnter the elements:");
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("\nDescending Order:");
for(i=0;i<no;i++)
printf("\n%d",num[i]);
printf("\nAscending Order:");
53

for(j=no-1;j>=0;j--)
printf("\n%d",num[j]);
getch();
}

OUTPUT
ASCENDING AND DESCENDING ORDER OF GIVEN ARRAY
Enter the number of elements in array:5
Enter the elements:6 2 1 3 8
Descending Order:
8
6
3
2
1
Ascending Order:
1
2
3
6
8

LARGEST AND SMALLEST OF THE GIVEN ARRAY


ALGORITHM
Step 1: Start the program
54

Step 2: Enter the size of the array


Step 3: Enter the elements of the array
Step 4: Print the array elements
Step 5: Initialize the large and small is equal to the first element of the array
Step 6: Set a loop up to the array size
Step 7: Check the next element greater than the large, if greater assign
next element to large
Step 8: Check the next element smaller than the large, if smaller assign
next element to small
Step 9: Print the value of large and small after execution of the loop
Step 10: Stop the program.
PROGRAM
#include<stdio.h>
#include<conio.h>
void main()
{
int a[100],i,small,large,no;
clrscr();
printf("LARGEST AND SMALLEST NUBMER OF A GIVEN ARRAY\n");
printf("Enter the number of elements in the array:");
scanf("%d",&no);
printf("\nEnter the elements of the array:");
for(i=0;i<no;i++)
scanf("%d",&a[i]);
printf("\nElements of the array are:");

55

for(i=0;i<no;i++)
printf("\n%d",a[i]);
small=a[0];
large=a[0];
for(i=1;i<no;i++)
{
if(a[i]>large)
large=a[i];
else if(a[i]<small)
small=a[i];
}
printf("\nLargest element of the array:%d",large);
printf("\nSmallest element of the array:%d",small);
getch();
}
OUTPUT
LARGEST AND SMALLEST NUBMER OF A GIVEN ARRAY
Enter the number of elements in the array:5
Enter the elements of the array:10 20 30 40 50
Elements of the array are:
10
20
30
40
50
56

Largest element of the array:50


Smallest element of the array:10

ADDITION OF TWO MATRIXES


ALGORITHM
Step 1: Start the program
Step 2: Enter the row and column of the matrix
Step 3: Enter the elements of A matrix
Step 4: Enter the elements of B matrix
Step 5: Print A and B matrix in matrix form
Step 6: Set a loop up to the row
Step 7: Set a inner loop up to the column
Step 8: Add the elements of A and B in column wise and store the result in C
matrix
Step 9: After the execution of two loops, print the value of C matrix
Step 10: Stop the program.
PROGRAM
#include<stdio.h>
#include<conio.h>
void main()
{
int a[25][25],b[25][25],c[25][25],i,j,m,n;
clrscr();
57

printf("ADDITION OF TWO MATRIXES\n");


printf("Enter the number of rows and columns of two matrix:");
scanf("%d %d",&m,&n);
printf("\nEnter the elements of A matrix:");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
}
printf("\nEnter the elements of B matrix:");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
scanf("%d",&b[i][j]);
}
printf("\nElements of A matrix:");
for(i=0;i<m;i++)
{
printf("\n");
for(j=0;j<n;j++)
printf("\t%d",a[i][j]);
}
printf("\nElements of B matrix:");
for(i=0;i<m;i++)
{

58

printf("\n");
for(j=0;j<n;j++)
printf("\t%d",b[i][j]);
}
printf("\nAddition 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]);
}
}
getch();
}

OUTPUT
ADDITION OF TWO MATRIXES
Enter the number of rows and columns of two matrix:3 3
Enter the elements of A matrix:1 2 3 4 5 6 7 8 9
Enter the elements of B matrix:1 2 3 4 5 6 7 8 9
Elements of A matrix:
1

9
59

Elements of B matrix:
1

Addition of two matrixes:


2

10

14

16

6
12
18

SUBTRACTION OF TWO MATRIXES


ALGORITHM
Step 1: Start the program
Step 2: Enter the row and column of the matrix
Step 3: Enter the elements of A matrix
Step 4: Enter the elements of B matrix
Step 5: Print A and B matrix in matrix form
Step 6: Set a loop up to the row
Step 7: Set a inner loop up to the column
Step 8: Subtract the elements of A and B in column wise and store the result
in C matrix
Step 9: After the execution of two loops, print the value of C matrix
Step 10: Stop the program.
PROGRAM
#include<stdio.h>
#include<conio.h>
60

void main()
{
int a[25][25],b[25][25],c[25][25],i,j,m,n;
clrscr();
printf("SUBTRACTION OF TWO MATRIXES\n");
printf("Enter the number of rows and columns of two matrix:");
scanf("%d %d",&m,&n);
printf("\nEnter the elements of A matrix:");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
}
printf("\nEnter the elements of B matrix:");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
scanf("%d",&b[i][j]);
}
printf("\nElements of A matrix:");
for(i=0;i<m;i++)
{
printf("\n");
for(j=0;j<n;j++)
printf("\t%d",a[i][j]);
61

}
printf("\nElements of B matrix:");
for(i=0;i<m;i++)
{
printf("\n");
for(j=0;j<n;j++)
printf("\t%d",b[i][j]);
}
printf("\nSubtraction 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]);
}
}
getch();
}
OUTPUT
SUBTRACTION OF TWO MATRIXES
Enter the number of rows and columns of two matrix:3 3
Enter the elements of A matrix:9 8 7 6 5 4 3 2 1
Enter the elements of B matrix:1 2 3 4 1 2 3 4 0
Elements of A matrix:

62

Elements of B matrix:
1

Subtraction of two matrixes:


8

-2

MULTIPLICATION OF TWO MATRIX


ALGORITHM
Step 1: Start the program
Step 2: Enter the row and column of A matrix
Step 3: Enter the row and column of B matrix
Step 4: Enter the elements of A and B matrix
Step 5: Print the elements of A and B matrix in matrix form
Step 6: Set a loop up to row
Step 7: Set a inner loop up to column
Step 8: Set another inner loop up to column
Step 9: Multiply A and B matrix and store the element in C matrix
Step 10: Print the resultant matrix
Step 11: Stop the program.
63

PROGRAM
#include<stdio.h>
#include<conio.h>
void main()
{
int a[25][25],b[25][25],c[25][25],i,j,k,r,s;
int m,n;
clrscr();
printf("MULTIPLICATION OF TWO MATRIXES\n");
printf("Enter the number of rows and columns of A matrix:");
scanf("%d %d",&m,&n);
printf("Enter the number of rows and columns of B matrix:");
scanf("%d %d",&r,&s);
if(m!=r)
printf("\nMatrix cannot be multiplied");
else
{
printf("\nEnter the elements of A matrix:");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
}
printf("\nEnter the elements of B matrix:");
for(i=0;i<m;i++)
64

{
for(j=0;j<n;j++)
scanf("%d",&b[i][j]);
}
printf("\nElements of A matrix:");
for(i=0;i<m;i++)
{
printf("\n");
for(j=0;j<n;j++)
printf("\t%d",a[i][j]);
}
printf("\nElements of B matrix:");
for(i=0;i<m;i++)
{
printf("\n");
for(j=0;j<n;j++)
printf("\t%d",b[i][j]);
}
for(i=0;i<m;i++)
{
printf("\n");
for(j=0;j<n;j++)
{
c[i][j]=0;
for(k=0;k<m;k++)
65

c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
}
}
printf("\nMultiplication of two matrixes:");
for(i=0;i<m;i++)
{
printf("\n");
for(j=0;j<n;j++)
printf("\t%d",c[i][j]);
}
getch();
}
OUTPUT
MULTIPLICATION OF TWO MATRIXES
Enter the number of rows and columns of A matrix:3 3
Enter the number of rows and columns of B matrix:3 3
Enter the elements of A matrix:1 2 3 4 5 6 7 8 9
Enter the elements of B matrix:1 2 3 4 5 6 7 8 9
Elements of A matrix:
1

Elements of B matrix:
1

3
66

Multiplication of two matrixes:


30

36

42

66

81

96

102

126

150

TRANSPOSE OF A MATRIX
ALGORITHM
Step 1: Stop the program
Step 2: Enter the row and column of the matrix
Step 3: Enter the elements of the matrix
Step 4: Print the elements of the matrix in matrix format
Step 5: Set the loop up to row
Step 6: Set the inner loop up to column
Step 7: Print the matrix elements in row wise
Step 8: Stop the program.

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

int a[25][25],i,j,m,n;
clrscr();
printf("TRANSPOSE OF A MATRIX\n");
printf("Enter the number of rows and columns of the matrix:");
scanf("%d %d",&m,&n);
printf("\nEnter the elements of the matrix:");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
}
printf("\nElements of the matrix:");
for(i=0;i<m;i++)
{
printf("\n");
for(j=0;j<n;j++)
printf("\t%d",a[i][j]);
}
printf("\nTranspose of the matrix:");
for(i=0;i<m;i++)
{
printf("\n");
for(j=0;j<n;j++)
{
printf("\t%d",a[j][i]);
68

}
}
getch();
}

OUTPUT
TRANSPOSE OF A MATRIX
Enter the number of rows and columns of the matrix:3 3
Enter the elements of the matrix:1 2 3 4 5 6 7 8 9
Elements of the matrix:
1

Transpose of the matrix:


1

69

RESULT
Thus a c program for one dimensional and two dimensional arrays is
executed and the output is verified successfully.
Ex.No:7
SOLVING PROBLEMS USING STRING FUNCTIONS
AIM
To write a c program using string functions
STRING PALINDROME OR NOT
ALGORITHM
Step 1: Start the program
Step 2: Declare the variables
Step 3: Read the string in str
Step 4: Use strcpy function to copy the string from str to str1 and reverse
the string using strrev
function
Step 5: Compare the two strings using strcmp and if the value is equal to
zero, display string is
palindrome
Step 6: If the value is not equal to zero, display the string is not a
palindrome
Step 7: Stop the program.

70

PROGRAM
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char str[20],str1[20];
clrscr();
printf("STRING PALINDROME OR NOT\n");
puts("Enter a string:");
gets(str);
strcpy(str1,str);
strrev(str1);
puts("After reversal string is:");
puts(str1);
if(strcmp(str,str1)==0)
puts("\nString is a palindrome");
else
puts("\nString is not palindrome");
getch();
}

OUTPUT1
STRING PALINDROME OR NOT
Enter a string:
71

malayalam
After reversal string is:
malayalam
String is a palindrome

OUTPUT2
STRING PALINDROME OR NOT
Enter a string:
hai
After reversal string is:
iah
String is not palindrome

STRING LENGTH, STRING CONCATENATION, STRING COPY


ALGORITHM
Step 1: Start the program
Step 2: Declare the variables
Step 3: Calculate the length of the string using strlen function and display it
Step 4: Use strcat function to concatenate the two strings src and dest and
the result will be
stored in dest string
Step 5: Display the result stored in dest string
Step 6: Use strcpy function to copy the string src to dest1 and the result will
be

72

stored in dest1 string


Step 7: Display the result stored in dest1 string
Step 8: Stop the program.
PROGRAM
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char *ptr="Dear";
char dest[50]="Hello";
char src[50]="Reader";
char dest1[50];
clrscr();
printf("STRING LENGTH,STRING CONCATENATION,STRING COPY\n");
printf("\nString length\n");
printf("Hello is %d\n",strlen("Hello"));
printf("Dear is %d\n",strlen(ptr));
printf("Reader is %d\n",strlen(src));
printf("\nString concatenation\n");
printf("The strings are:\n");
puts(dest);
puts(src);
printf("Strings after concatenation\n");
strcat(dest,src);
73

puts(dest);
printf("\nString copy\n");
printf("Sorce String is:");
puts(src);
strcpy(dest1,src);
puts("Destination String is:");
puts(dest1);
getch();
}

OUTPUT
STRING LENGTH,STRING CONCATENATION,STRING COPY
String length
Hello is 5
Dear is 4
Reader is 6
String concatenation
The strings are:
Hello
Reader
Strings after concatenation
HelloReader
String copy
Sorce String is:Reader
Destination String is:
74

Reader
REVERSE OF A STRING
ALGORITHM
Step 1: Start the program
Step 2: Declare the variables
Step 3: Read the string using str variable
Step 4: Use strrev function to reverse the string and the result will be stored
in str
Step 5: Display the result in str
Step 6: Stop the program.

PROGRAM
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char str[20];
clrscr();
printf("REVERSE OF A STRING\n");
puts("Enter a string:");
gets(str);
strrev(str);
puts("After reversal,the string is:");
puts(str);
75

getch();
}
OUTPUT
REVERSE OF A STRING
Enter a string:
hello
After reversal,the string is:
olleh

LOWERCASE AND UPPERCASE OF A STRING


ALGORITHM
Step 1: Start the program
Step 2: Declare the variables
Step 3: Read the string using str variable
Step 4: Use strlwr function to find the lowercase of a string and display it
Step 5: Use strupr function to find the uppercase of a string and display it
Step 6: Stop the program.
PROGRAM
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
76

char str[20];
clrscr();
printf("LOWERCASE AND UPPERCASE OF A STRING\n");
puts("Enter a string:");
gets(str);
strlwr(str);
puts("Lowercase string:");
puts(str);
puts("Uppercase string:");
strupr(str);
puts(str);
getch();
}

OUTPUT
LOWERCASE AND UPPERCASE OF A STRING
Enter a string:
HELLO
Lowercase string:
hello
Uppercase string:
HELLO
77

RESULT
Thus a c program using string functions is executed and the output is
verified.

Ex.no:8
PROGRAMS WITH USER DEFINED FUNCTIONS
AIM
To write a c program with user defined functions
AREA AND CIRCUMFERENCE OF CIRCLE
ALGORITHM
Step 1: Start the program
Step 2: Declare the variables
Step 3: Declare two functions area and circumference
Step 4: Read the radius of the circle
Step 5: Call the function area and circumference
Step 6: In the function area calculate the area of circle using formula
3.14*radius*radius

78

Step 7: In the function circumference calculate the circumference of circle


using formula
2*3.14*radius
Step 8: Return the result back to main function and display the result
Step 9: Stop the program.
PROGRAM
#include<stdio.h>
#include<conio.h>
float area(int);
float circumference(int);
void main()
{
int radius;
float cir,circum;
clrscr();
printf("AREA AND CIRCUMFERENCE OF CIRCLE\n");
printf("Enter the radius of the circle:");
scanf("%d",&radius);
cir=area(radius);
printf("Area of circle:%f\n",cir);
circum=circumference(radius);
printf("Circumference of circle:%f\n",circum);
getch();
}
float area(int radius)
79

{
return 3.14*radius*radius;
}
float circumference(int radius)
{
return 2*3.14*radius;
}

OUTPUT
AREA AND CIRCUMFERENCE OF CIRCLE
Enter the radius of the circle:3
Area of circle:28.260000
Circumference of circle:18.840000

ADDITION, SUBTRACTION, MULTIPLICATION AND DIVISION


ALGORITHM
Step 1: Start the program
Step 2: Declare the variables
Step 3: Declare functions add, sub, mul and div
Step 4: Read two variables a and b
Step 5: Call the function add and in that function perform addition operation
a+b and return the
result to main function and display it
Step 6: Call the function sub and in that function perform subtraction
operation a-b and return

80

the result to main function and display it


Step 7: Call the function mul and in that function perform multiplication
operation a*b and
return the result to main function and display it
Step 8: Call the function div and in that function perform division operation
a/b and return
the result to main function and display it
Step 9: Stop the program.
PROGRAM
#include<stdio.h>
#include<conio.h>
int add(int,int);
int sub(int,int);
int mul(int,int);
float div(int,int);
void main()
{
int a,b;
int res1,res2,res3;
float res4;
clrscr();
printf("ADDITION,SUBTRACTION,MULTIPLICATION,DIVISION\n");
printf("Enter the value of a:");
scanf("%d",&a);
printf("Enter the value of b:");

81

scanf("%d",&b);
res1=add(a,b);
printf("\nAddition:%d\n",res1);
res2=sub(a,b);
printf("Subtraction:%d\n",res2);
res3=mul(a,b);
printf("Multiplication:%d\n",res3);
res4=div(a,b);
printf("Division:%f\n",res4);
getch();
}
int add(int a,int b)
{
return a+b;
}
int sub(int a,int b)
{
return a-b;
}
int mul(int a,int b)
{
return a*b;
}
float div(int a,int b)
{
82

return a/b;
}

OUTPUT
ADDITION,SUBTRACTION,MULTIPLICATION,DIVISION
Enter the value of a:10
Enter the value of b:5

Addition:15
Subtraction:5
Multiplication:50
Division:2.000000

CALL BY VALUE
ALGORITHM
Step 1: Start the program
Step 2: Declare the variables
Step 3: Declare the function swap
Step 4: Call the function swap by passing the value

83

Step 5: In function swap perform swap operation without using temporary


variable and display
the result
Step 6: In call by value, the result when passed to main function leaves the
formal parameters
and takes the actual parameters and display it
Step 7: Stop the program.
PROGRAM
#include<stdio.h>
#include<conio.h>
void swap(int,int);
void main()
{
int a=10,b=20;
clrscr();
printf("CALL BY VALUE\n");
printf("Before swap values are %d %d\n",a,b);
swap(a,b);
printf("After swap values are %d %d\n",a,b);
getch();
}
void swap(int x,int y)
{
x=x+y;
y=x-y;

84

x=x-y;
printf("In swap function values are %d %d\n",x,y);
}
OUTPUT
CALL BY VALUE
Before swap values are 10 20
In swap function values are 20 10
After swap values are 10 20

CALL BY REFERENCE
ALGORITHM
Step 1: Start the program
Step 2: Declare the variables
Step 3: Declare the function swap
Step 4: Call the function swap by passing the reference
Step 5: In function swap perform swap operation without using temporary
variable and display
the result
Step 6: In call by reference, the result will be passed to main function as
reference and
swapping is done and display it
Step 7: Stop the program.
PROGRAM
#include<stdio.h>

85

#include<conio.h>
void swap(int*,int*);
void main()
{
int a=10,b=20;
clrscr();
printf("CALL BY REFERENCE\n");
printf("Before swap values are %d %d\n",a,b);
swap(&a,&b);
printf("After swap values are %d %d\n",a,b);
getch();
}
void swap(int *x,int *y)
{
*x=*x+*y;
*y=*x-*y;
*x=*x-*y;
printf("In swap function values are %d %d\n",*x,*y);
}

OUTPUT
CALL BY REFERENCE
86

Before swap values are 10 20


In swap function values are 20 10
After swap values are 20 10

RESULT
Thus the c programs with user defined functions are executed and the
output is verified.
Ex.No:9
PROGRAM USING RECURSIVE FUNCTION
AIM
To write a c program using recursion
FACTORIAL OF A NUMBER
ALGORTIHM
Step1: Start the program
Step2: Enter a number

87

Step3: Set a loop to find the factorial of a given number using formula
fact=fact*i
Step4: Print the factorial of the given number
Step5: Stop the program.
PROGRAM
#include<stdio.h>
#include<conio.h>
int fact(int);
void main()
{
int num,f;
clrscr();
printf("FACTORIAL OF A NUMBER USING RECURSION\n");
printf("\nEnter a number: ");
scanf("%d",&num);
f=fact(num);
printf("\nFactorial of %d is: %d",num,f);
getch();
}

int fact(int n)
{
if(n==1)
return 1;
else
88

return(n*fact(n-1));
}
OUTPUT
FACTORIAL OF A NUMBER USING RECURSION
Enter a number: 5
Factorial of 5 is: 120

FIBONACCI SERIES
ALGORITHM
Step1: Start the program
Step2: Declare the variables
Step 3: Read the number of terms num
Step 4: Call the function fib(num)
Step 5: In fib(num), check if num==0 print 0
Step 6: Else use for loop and give
fib=fib+a;
a=b;
b=fib;
Step 7: Print the Fibonacci series of the given number
Step 8: Stop the program.
PROGRAM
#include<stdio.h>
#include<conio.h>
void fib();
void main()
{

89

int num;
clrscr();
printf("FIBONACCI OF A NUMBER USING RECURSION\n");
printf("\nEnter the number of terms: ");
scanf("%d",&num);
printf("\nFibonacci series upto %d terms:");
fib(num);
getch();
}
void fib(int num)
{
int a=0,b=1,fib=0,i;
if(num==0)
printf("0");
else
{
for(i=0;i<num;i++)
{
fib=fib+a;
a=b;
b=fib;
printf("%d\t",fib);
}
}
}
90

OUTPUT
FIBONACCI OF A NUMBER USING RECURSION
Enter the number of terms: 5
Fibonacci series upto 5 terms: 0

RESULT
Thus a c program using recursive function is executed and the output
is verified.

Ex.No:10
PROGRAM USING STRUCUTRES AND UNIONS
AIM
To write a c program using structures and unions
STUDENT GRADE USING STRUCTURE
ALGORITHM
Step 1: Start the program

91

Step 2: Define the structure stud with the members


rollno,name,mark1,mark2,mark3,total,avg,
grade
Step 3: Read the number of students
Step 4: Use for loop to get record details
Step 5: Read the data using structure variables as
a[i].rollno,a[i].name,a[i].mark1,a[i].mark2,
a[i].mark3
Step 6: Calculate the total and average of the marks
Step 7: If a[i].grade<40, then assign it to D
Step 8: If a[i].grade<60, then assign it to C
Step 9: If a[i].grade<80, then assign it to B, else assign it to A
Step 10: Print rollno, name, mark1, mark2, mark3, total, avg and grade
Step 11: Stop the program.
PROGRAM
#include<stdio.h>
#include<conio.h>
struct stud
{
int rollno;
char name[30];
int mark1,mark2,mark3,total;
float avg;
char grade;
}a[25];

92

void main()
{
int i,n;
clrscr();
printf("STUDENT GRADE USING STRUCTURE\n");
printf("Enter the number of students:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\nEnter the student %d details:",i+1);
printf("\nRollNo:");
scanf("%d",&a[i].rollno);
printf("\nName:");
scanf("%s",a[i].name);
printf("\nMark1:");
scanf("%d",&a[i].mark1);
printf("\nMark2:");
scanf("%d",&a[i].mark2);
printf("\nMark3:");
scanf("%d",&a[i].mark3);
a[i].total=a[i].mark1+a[i].mark2+a[i].mark3;
a[i].avg=a[i].total/3;
if(a[i].avg<40)
a[i].grade='D';
else if(a[i].avg<60)
93

a[i].grade='C';
else if(a[i].avg<80)
a[i].grade='B';
else
a[i].grade='A';
}
printf("\t\tStudent Mark Details:\n");
printf("\n RollNo\t Name\t Mark1\t Mark2\t Mark3\t Total\t Average\t Grade");
for(i=0;i<n;i++)
printf("\n%d\t%s\t%d\t%d\t%d\t%d\t%.2f\t
%c",a[i].rollno,a[i].name,a[i].mark1,a[i].mark2,
a[i].mark3,a[i].total,a[i].avg,a[i].grade);
getch();
}
OUTPUT
STUDENT GRADE USING STRUCTURE
Enter the number of students:2
Enter the student 1 details:
RollNo:10
Name:hari
Mark1:90
Mark2:80
Mark3:100
Enter the student 2 details:
RollNo:20
Name:priya
Mark1:50
94

Mark2:70
Mark3:60
Student Mark Details:
RollNo

Name

Mark1

Mark2

Mark3

Total Average

Grade
10

hari

90

80

100

270

90.00

20

priya

50

70

60

180

60.00

EMPLOYEE DETAILS USING UNION


ALGORITHM
Step 1: Start the program
Step 2: Declare the union variables
Step 3: Enter the employee name, number and salary
Step 4: Call the union function using union variables
Step 5: Print the details of the employees
Step 6: Stop the program.
PROGRAM
#include<stdio.h>
#include<conio.h>
union uemf
{
char name[10];
int number;
float sal;
};
void main()
{
95

union uemf u1;


clrscr();
printf("EMPLOYEE DETAILS USING UNION\n");
printf("Enter the employee name...");
scanf("%s",u1.name);
printf("%s",u1.name);
printf("\nEnter the employee number...");
scanf("%d",&u1.number);
printf("%d",u1.number);
printf("\nEnter the salary...");
scanf("%f",&u1.sal);
printf("\%f",u1.sal);
getch();
}

OUTPUT
EMPLOYEE DETAILS USING UNION
Enter the employee name...priya
priya
Enter the employee number...100
100
96

Enter the salary...20000


20000.000000

RESULT
Thus a c program using structures and unions are executed and the
output is verified.
Ex.No:11
POINTERS
AIM
To write a C program for finding the sizeof pointer variables.
SIZEOF POINTER VARIABLES
ALGORITHM
Step 1: Start the program
Step 2: Declare the pointer variables
97

Step 3: Calculate the sizeof char, int and float pointer variables
Step 4: Print the values
Step 5: Stop the program
PROGRAM
#include<stdio.h>
#include<conio.h>
void main()
{
char *cptr;
int *iptr;
float *fptr;
clrscr();
printf("POINTER\n");
printf("Pointer to char:%d bytes",sizeof(cptr));
printf("\nPointer to int:%d bytes",sizeof(iptr));
printf("\nPointer to float:%d bytes",sizeof(fptr));
getch();
}
OUTPUT
POINTER
Pointer to char:2 bytes
Pointer to int:2 bytes
Pointer to float:2 bytes.

98

RESULT
Thus a c program using pointers is executed and the output is verified.

Ex.No:12
FILE HANDLING
AIM
To write a C program to read name and marks of n number of students
from user and store them in a file.
STUDENT NAMES AND MARKS
ALGORITHM
Step 1: Start the program
99

Step 2: Declare the pointer for the file.


Step 3: Enter the Students name and marks
Step 4: Details will be stored in student.txt file.
Step 5: Stop the program
PROGRAM
#include <stdio.h>
int main(){
char name[50];
int marks,i,n;
printf("Enter number of students: ");
scanf("%d",&n);
FILE *fptr;
fptr=(fopen("C:\\student.txt","w"));
if(fptr==NULL){
printf("Error!");
exit(1);
}
for(i=0;i<n;++i)
{
printf("For student%d\nEnter name: ",i+1);
scanf("%s",name);
printf("Enter marks: ");
scanf("%d",&marks);
fprintf(fptr,"\nName: %s \nMarks=%d \n",name,marks);
}
fclose(fptr);
return 0;
100

}
OUTPUT
Enter number of students: 3
For student1
Enter name: saveetha
Enter marks: 99
For student2
Enter name: anusha
Enter marks: 90
For student3
Enter name: varathu
Enter marks: 45
The file with data will be created in the specified location.

RESULT
Thus a c program using files is executed and the output is verified.

101

S-ar putea să vă placă și