COMPUTER
PRACTICE LAB - I
LAB MANUAL
PREPARED
By
M.SENTHIL
Lect / CSE
b) Spread Sheet
1. Chart - Line, XY, Bar and Pie.
2. Formula - formula editor.
3. Spread sheet inclusion of object, Picture and graphics, Protecting the
document and sheet.
4. Sorting and Import/Export features.
C) Simple C Programming
1.
2.
3.
4.
Microsoft
Word
Ex no: 1(a)
Text Alignment
1. Select the text for alignment
2. For left alignment press CTRL+L (or) press align left button on
the formatting toolbar
3. For right alignment press CTRL+R (or) press align right button
on the formatting toolbar
4. For center alignment press CTRL+E (or) press align center
button on the formatting toolbar
5. For justify press CTRL+J (or) press align justify button on the
formatting toolbar
(ii)
(iii)
Line spacing
1. Select the paragraphs of the document using the left mouse
button (or) choose select all option from the edit menu (or) by
pressing CTRL+A
2. Choose paragraph option from the format menu. A paragraph
dialogue box appears
3. Select the 1.5 lines from the line spacing list box. Then click
OK
4. Now the 1.5 line spacing is applied to the selected paragraph
(iv)
Select the text you want to change for font types & sizes
Then choose font option from the format menu
It shows the font dialogue box
From that choose required font type from the font list box & the
required size from the size list box on the font dialogue box,
Then click OK
(vi)
For symbols
1. Type the text, then put the cursor where you want to add the
symbol
2. Choose symbols option from the insert menu
3. Shows the symbols dialogue box
4. Then choose required symbol from the symbols dialogue box.
Then click insert
For pictures
1. Click insert->picture->clipart
2. Select the clip from the insert clipart dialogue box, which you
want to insert & click OK.
3. Now the selected clip is inserted into your document
(vii)
Result:
Thus the word document was created & performs above operations
successfully.
Ex no: 1(b)
Procedure:
(i)
1.
2.
3.
4.
OUTPUT:
(i)
Equations
Raja S
Siva
14/12/1982
Male
Single
12, Anna nagar
Chennai
B.E(CSE)
Qualification
Educational details
Class/degree
Institution name
S.S.L.C
H.S.C
B.E
Year of
passing
March
1998
March
2000
2000-2004
Languages known
Tamil, English, Telugu
Computer skills
Ms office
C, C++, Java, VB, oracle
Experience
Working as software engineer in TCS for 2
years in Chennai
Working as software engineer in CTS for 1
year in Chennai
Date :
Place :
Candidate Sign
10
Percentage of
mark
75%
80%
84%
VISITING CARD
V. Ramesh Babu
Managing Director
Mobile: 9756453212
VRB PUBLISHERS
24, Anna nagar, Chennai
E-mail: vrbpub@hotmail.com
Website:www.vrbpub.com
Result:
Thus the word document was created with Equation, Bio data & visiting
card.
11
Exno:2 (a)
Procedure:
For table creation
1.
2.
3.
4.
5.
12
13
OUTPUT:
For total
Rno
10
20
30
Name
Raja
Rani
suji
Sub1
78
90
56
Sub2
23
45
67
Sub3
77
89
45
Sub4
66
78
97
Sub5
45
34
77
Total
289
336
342
Sub1
78
90
56
Sub2
23
45
67
Sub3
77
89
45
Sub4
66
78
97
Sub5
45
34
77
Average
57.8
67.2
68.4
Sub2
23
45
67
Sub3
77
89
45
Sub4
66
78
97
Sub5
45
34
77
Maximum
78
90
97
Sub2
23
45
67
Sub3
77
89
45
Sub4
66
78
97
Sub5
45
34
77
Minimum
23
34
45
For average
Rno
10
20
30
Name
Raja
Rani
Suji
Name
Raja
Rani
suji
Sub1
78
90
56
Name
Raja
Rani
suji
Sub1
78
90
56
Name
suji
Raja
Rani
Sub1
56
78
90
Sub2
67
23
45
Sub3
45
77
89
Sub4
97
66
78
Sub5
77
45
34
Minimum
45
23
34
Result:
Thus the table was created & calculates the total, average, maximum &
minimum marks of the students.
14
Ex no:2 (b)
15
16
OUTPUT:
Before splitting (cell)
Name
Suresh
Ramesh
Age
24
22
Degree
BSC
BE
After splitting (cell) [3rd column of 1st row has splitted with 2 cells]
Name
Suresh
Ramesh
Age
24
22
Degree
BSC
BE
Age
24
22
Degree
BSC
BE
After merging (cell) [2nd, 3rd column of 2nd row has joined with single cell]
Name
Suresh
Ramesh
Age
24
BSC
22
Degree
BE
Age
24
22
Degree
BSC
BE
Age
24
22
Degree
BSC
BE
17
Age
24
22
Degree
BSC
BE
Age
24
22
Degree
BSC
BE
Age
24
22
20
Degree
BSC
BE
MCA
Name
Suresh
Age
24
Degree
BSC
Ramesh
Raju
22
20
BE
MCA
Result:
Thus the table was created & perform all operations successfully
18
Ex no: 3
6.
7.
19
20
11. It will display all the recipients, In that select Type a new list
12. Then click Create, it will display the New Address List dialog box.
13. Enter the Address Information for more than 2 persons, then click
close.
21
15. It will display all the peoples information. Here we can also add or
delete or we can update the information.
22
23
24
Result :
Thus the mail merge method was used to produce letters for each person
successfully.
25
Ex no: 4
Drawing a flowchart
Aim:
(i)
(ii)
(ii)
Procedure:
(i) Draw the basic flowchart symbols & name them in the document
1. Choose the flowchart option in the auto shapes menu of
the drawing tool bar
2. Choose the appropriate flowchart symbol & drag the
symbol in the document
3. Type the text in the symbol, by right click, then choose
add text option
Flow lines
26
Connectors
a
a
27
OUTPUT:
Start
Read
b,c,d,e
A=b+c*e/d
Print A
Stop
28
Start
Read m1 to
m5
Total=
m1+m2+m3+m4+m5
Avg=total/5
yes
Distinction
If
avg>=75
no
yes
If ((avg<75)&&
(avg>=60))
First class
no
yes
If ((avg<60)&&
(avg>=50))
Second
class
yes
no
yes
If ((avg<50)&&
(avg>=35))
Third class
no
print fail
Stop
29
Result:
Thus the flowchart was created & verified successfully
30
MS
EXCEL
31
Ex no:5
Line chart
XY chart
Bar chart
Pie chart
Procedure:
For Line chart
1. Enter the data about student in the worksheet
2. Choose chart option from the insert menu (or) choose the chat
wizard button from the standard tool bar
3. It shows the chart wizard dialogue box
4. From that choose the chart type as line
5. Click next button on the dialogue box & enter the details
6. Then click finish button
For XY chart
(i) Enter the data about student in the worksheet
(ii) Choose chart option from the insert menu (or) choose the
chart wizard button from the standard tool bar
(iii) It shows the chart wizard dialogue box
(iv) From that choose the chart type as XY(Scatter)
(v) Click next button on the dialogue box & enter the details
Then click finish button
For Bar chart
(i) Enter the data about student in the worksheet
(ii) Choose chart option from the insert menu (or) choose
chart wizard button from the standard tool bar
(iii) It shows the chart wizard dialogue box
(iv) From that choose the chart type as Bar
(v) Click next button on the dialogue box & enter the
details
(vi) Then click finish button
32
the
33
34
35
Result:
Thus the charts are created for the student mark analysis.
36
Ex no:6
Formula Editor
Aim:
To create a suitable examination database & find the sum of the marks of
each student & the respective classes secured by the students
Rules
(i)
Pass if marks in each subject >=35
(ii)
Fail if marks in each subject <35
(iii) Distinction if average >=75
(iv) First class if average >=60 but less than 75
(v)
Second class if average >=50 but less than 60
(vi) Third class if average >=35 but less than 50
Display average marks of the class subject wise & pass percentages
Procedure:
1.
2.
3.
4.
37
OUTPUT:
Result:
Thus the suitable examination database & the sum of the marks of each
student are displayed in the worksheet
38
Exno:7
40
Result:
Thus the Excel sheet was created with pictures, protect the sheets
& book successfully
41
Ex no:8
Enter the following data into the worksheet using data>form command
Name
Raja
Anu
Suji
Banu
Kishore
Dept
Computer
Accounts
Marketing
Clerk
Engineering
Salary
12000
11000
8000
5000
24000
42
(ii)
Salesman
Babu
Suresh
Balaji
Raja
Vijay
Product
Keyboard
Cpu
Moniter
CD
Hard disk
Sales
1000
3000
1500
15
800
Procedure:
(i)
1.
2.
3.
4.
43
14. Click settings tab, select list from allow drop down list
15. Type male, female in the source box
16. Click input message tab, in that type select gender please,
then click OK
17. Click on A9, Enter seat number
18. Click C9, click data->validation
19. Click settings tab, select whole numbers from allow drop down
list, between from data, 1 in minimum & 100 in maximum
20. Click input message tab, in that type Enter seat number
21. Select stop from style, in the error message box type. number
selected is out of range, then click OK
22. Click on A11, Enter Class
23. Click C11, choose data->validation
24. Click settings tab, select list from allow drop down list, type
first, second, third in source
25. Click input message tab, in that type please select class, then
click OK
26. Click on A12 enter amount
27. Click C12, type =
if(C11=first,500,if(C11=second,400,300))
(iii)
44
OUTPUT:
Result:
Thus the sorting and import / export features was created successfully.
45
C PROGRAMS
46
Ex no: 9
Start
Read radius value
Give formula A=3.14*r*r
Print a
Stop
Flowchart:
start
Read r
a=3.14*r*r
Print a
Program:
stop
#include<stdio.h>
#include<conio.h>
void main()
{
int r;
float a;
clrscr();
printf("Enter the radius");
scanf("%d",&r);
47
a=3.14*r*r;
printf("Area=%f",a);
getch();
}
OUTPUT:
Enter the radius3
Area=28.260000
9.2 Write a C program to convert Celsius to Fahrenheit temperature
Aim:
1
2
3
4
5
Start
Read Celsius value
Give formula faren=(1.8*cel)+32
Print faren
Stop
Flowchart:
start
Read cel
faren=(1.8*cel)32
Print faren
Program:
stop
#include<stdio.h>
#include<conio.h>
void main()
{
float cel, faren;
clrscr();
printf("enter the celcius value");
scanf("%f",&cel);
faren=(1.8*cel)+32;
48
Start
Enter n, x value
Convert x into radius using x=x*3.1412/180
t<-x, sum<-x
Setup for loop from i<-1, until i<n increment i
t=(t*pow((double)(-1),(double)(2*i1))*x*x)/(2*i*(2*i+1));
Sum=sum+t
Print sum
Stop
Flowchart:
Start
Read x, n
Print x, n
X=x*3.142/180
T=x, sum=x
For I=1;I<n+1;I++
T=(t*pow((double)(-1),(double)
(2*I-1))*x*x)/(2*I*(2*I+1))
sum=sum+t
49
Print sum
Program:
Stop
#include<stdio.h>
#include<math.h>
#include<conio.h>
void main()
{
float x,t,sum,n;
int i;
clrscr();
printf("Enter the value of x,n :");
scanf("%f%f",&x,&n);
printf("%4.2f%f\n",x,n);
x=x*3.1412/180;
t=x;
sum=x;
for(i=1;i<n;i++)
{
t=(t*pow((double)(-1),(double)(2*i-1))*x*x)/(2*i*(2*i+1));
sum=sum+t;
}
printf("the value of SIN(X)=%6.2f\n",sum);
getch();
}
9.3 Write a C program to print the datatype values.
Program:
#include<stdio.h>/* standard input output */
#include<conio.h>/* Console input output */
void main()
{
int x=2;
float y=2.2;
char z='s';
clrscr(); /* clear the screen */
printf("%d\n%f\n%c",x,y,z);
getch();
}
50
Output:
2
s
2.200000
9.4 Write a C program to perform arithmetic operations.
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf("Enter the any two value:");
scanf("%d%d",&a,&b);
c=a+b;
printf("Sum=%d\t",c);
c=a-b;
printf("Sub=%d\t",c);
c=a*b;
printf("mul=%d\t",c);
c=a/b;
printf("Div=%d",c);
getch();
}
OUTPUT:
Enter the any two value:6
3
Sum=9
Sub=3
mul=18
Div=2
9.5 Write a C program to find the average of three numbers.
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
float a,b,c,sum,avg;
clrscr();
printf("Enter the any 3 value:");
scanf("%f%f%f",&a,&b,&c);
sum=a+b+c;
printf("Sum=%f",sum);
avg=sum/3;
printf("\nAverage=%f",avg);
getch();
}
51
OUTPUT:
Enter the any 3 value: 75
Sum=225.000000
Average=75.000000
75
75
9.6 Write a C program to swap the values of two variables without using a
third variable.
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int a=5,b=6;
clrscr();
printf("a=%d \t b=%d\n",a,b);
a=a+b;
b=a-b;
a=a-b;
printf("a=%d \t b=%d",a,b);
getch();
}
OUTPUT:
a=5 b=6
a=6 b=5
9.7 Write a C program to swap the values of two variables using a third
variable.
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int a=5,b=6,c;
clrscr();
printf("a=%d b=%d\n",a,b);
c=a;
a=b;
b=c;
printf("a=%d b=%d",a,b);
getch();
}
OUTPUT:
a=5 b=6
a=6 b=5
52
9.8 Write a C program to find the square root for the given value.
Program:
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int x,y;
clrscr();
printf("Enter the value of x:");
scanf("%d",&x);
y=sqrt(x);
printf("Square root of %d is %d",x,y);
getch();
}
OUTPUT:
Enter the value of x: 81
Square root of 81 is 9
9.9 Write a C program to find the given number is Odd or Even.
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int num;
clrscr();
printf("Enter a number:");
scanf("%d",&num);
if((num%2)==0)
printf("\n The given number is a even number");
else
printf("\n The given number is a odd number");
getch();
}
OUTPUT:
Enter a number:6
The given number is a even number
53
9.10 Write a C program to find the given year is leap year or not
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int year;
clrscr();
printf("Enter a year:");
scanf("%d",&year);
if((year%4)==0)
printf("\nThe given year is a leap year");
else
printf("\nThe given year is not a leap year");
getch();
}
OUTPUT:
Enter a year: 2012
The given year is a leap year
9.11 Write a C program to find the biggest number from the given three
numbers.
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf("Enter any three number:");
scanf("%d%d%d",&a,&b,&c);
if((a>b)&&(a>c))
printf("\n%d is the biggest number",a);
else if((b>a)&&(b>c))
printf("\n%d is the biggest number",b);
else
printf("\n%d is the biggest number",c);
getch();
}
OUTPUT:
Enter any three number:5 2
3
5 is the biggest number
54
55
9.14 Write a C program to check whether the given number is prime or not.
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int i=2,num;
clrscr();
printf("Enter a number:");
scanf("%d",&num);
while(i<=num-1)
{
if((num%i)==0)
{
printf("The given number %d is not a prime",num);
exit(0);
}
i++;
}
if(i==num)
{
printf("The given number %d is a prime",num);
}
getch();
}
OUTPUT:
Enter a number:9
The given number 9 is not a prime
9.15 Write a C program to find the sum of digits of a number.
Program:
/*To find the sum of the digits of a number*/
#include<stdio.h>
#include<conio.h>
void main()
{
int num,sum=0;
clrscr();
printf("Enter a number:");
scanf("%d",&num);
while(num>0)
{
sum+=num%10;
num=num/10;
}
printf("\nThe sum of given digit is %d",sum);
56
getch();
}
OUTPUT:
Enter a number: 1234
The sum of given digit is 10
9.16 Write a C program to find the reverse the digits of a number.
Program:
/*To find the reverse the digits of a number*/
#include<stdio.h>
#include<conio.h>
void main()
{
int num,rn;
clrscr();
printf("Enter a number:");
scanf("%d",&num);
printf("\nThe reverse of the given digit is ");
while(num>0)
{
rn=num%10;
num=num/10;
printf("%d",rn);
}
getch();
}
OUTPUT:
Enter a number: 12345
The reverse of the given digit is 54321
9.17 Write a C program to find the Fibonacci series of a given number.
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,fib[20];
clrscr();
fib[0]=0;
fib[1]=1;
printf("Enter the value of n:\n");
scanf("%d",&n);
printf("The Fibonacci Series are:\n");
printf("\n%d \t%d",fib[0],fib[1]);
for(i=2;i<=n-1;i++)
{
fib[i]=fib[i-1]+fib[i-2];
57
printf("\t%d",fib[i]);
}
getch();
}
OUTPUT:
Enter the value of n: 10
The Fibonacci Series are:
0
13
21
34
9.18 Write a C program to find the sum and difference of two matrices.
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int a[3][3],b[3][3],c[3][3],d[3][3],i,j,n;
clrscr();
printf("\nEnter the size for A and B Matrix:");
scanf("%d",&n);
printf("\nEnter the values for the matrix A:");
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("\nEnter the values for the matrix B:");
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
scanf("%d",&b[i][j]);
}
}
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
c[i][j]=a[i][j]+b[i][j];
d[i][j]=a[i][j]-b[i][j];
}
}
printf("\n Matrix Addition:\n");
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
printf("\t%d",c[i][j]);
58
}
printf("\n");
}
printf("\n Matrix Subtraction:\n");
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
printf("\t%d",d[i][j]);
}
printf("\n");
}
getch();
}
OUTPUT:
Enter the size for A and B Matrix:2
Enter the values for the matrix A:1 2 3 4
Enter the values for the matrix B:4 3 2 1
Matrix Addition:
5
5
5
5
Matrix Subtraction:
-3
-1
1
3
59
}
printf("\nEnter the values for the matrix B:");
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
scanf("%d",&b[i][j]);
}
}
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
c[i][j]=0;
for(k=1;k<=n;k++)
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
}
printf("\n Matrix Multiplication:\n");
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
printf("\t%d",c[i][j]);
}
printf("\n");
}
}
OUTPUT:
Enter the size for A and B Matrix:2
Enter the values for the matrix A: 1
Matrix Multiplication:
6
8
16 21
60
9.20 Write a C program to generate numbers between 1 and 100 which are
divisible by 2 and not divisible by 3 and 5.
Program
/*Generate numbers between 1 and 100 which are divisible by 2 and not
divisible by 3 and 5*/
#include<stdio.h>
#include<conio.h>
void main()
{
int i;
printf("The following numbers are divisible by 2 but not divisible by 3&5:\n");
for(i=1;i<=100;i++)
{
if(((i%2)==0)&&((i%3)!=0)&&((i%5)!=0))
{
printf("\t%d",i);
}
}
}
OUTPUT:
The following numbers are divisible by 2 but not divisible by 3&5:
2
4
8
14 16 22 26 28 32
34 38 44
46 52 56 58 62 64 68 74 76 82 86 88 92
94 98
Result:
Thus the C Program was executed successfully with data types,
expression evaluations and control statements.
61
ARRAYS
Ex.No.10
Write a C program to find the largest and smallest of the given array.
Algorithm:
1. Start
2. Declare variables a[100], i
3. Read total array elements
4. Read the elements of the array using for loop
5. if a[i]>large then large=a[i]
6. else a[i]<small small=a[i]
7. Print the largest & smallest number of given array
8. Stop
Flowchart:
start
Read array
element
For i=0;I<n;i++
Large=a[i]
If
a[i]>large
yes
no
nop
Small=a[i]
no
Print
small,large
end
62
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int a[100],i,small,large,no;
clrscr();
printf("In how many numbers you want to find");
scanf("%d",&no);
printf("\n Enter the elements of the array");
for(i=0;i<no;i++)
scanf("%d",&a[i]);
printf("\n The elements of the array");
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("\n The largest of the given array is %d",large);
printf("\n The smallest of the given array is %d",small);
getch();
}
OUTPUT
In how many numbers you want to find5
Enter the elements of the array8 5 2 1 9
The elements of the array
8
5
2
1
9
The largest of the given array is 9
The smallest of the given array is 1
Result:
Thus the C program to find the largest and smallest of the given array was
executed successfully.
63
11.1 Write a C program to print the student rollno, name, marks using
structures
Algorithm:
1. Start
2. Define the structures with members name, rno, marks
3. Declare structure variable as array s[10]
4. Enter the number of the students, name, mark, rno
5. Access structure members in main using structure variable
6. Print students details
7. Stop
Flowchart:
start
Struct stud
Name:
Mark
rno
For i=0;I<n;i++
Read name,
mark, rno
Print name,
mark, rno
end
64
Program:
#include<stdio.h>
#include<conio.h>
struct stud
{
int rollno;
char name[30];
int cp,math,eng,total;
float avg;
char grade;
}a[5];
main()
{
int i,n;
printf("Enter the number of students:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("Enter the student %d details:",i);
printf("\n RollNo:");
scanf("%d",&a[i].rollno);
printf("\n Name:");
scanf("%s",&a[i].name);
printf("\n CP:");
scanf("%d",&a[i].cp);
printf("\n math:");
scanf("%d",&a[i].math);
printf("\n English:");
scanf("%d",&a[i].eng);
a[i].total=a[i].cp+a[i].math+a[i].eng;
a[i].avg=a[i].total/3;
if(a[i].avg<40)
a[i].grade='D';
else if(a[i].avg<60)
a[i].grade='C';
else if(a[i].avg<80)
a[i].grade='B';
else
a[i].grade='A';
}
printf("\t\t Students mark details:\n");
printf("\n RollNo\tName\tCP\tMath\tEnglish\tTotal\tAverage\tGrade");
for(i=1;i<=n;i++)
printf("\n%d\t%s\t%d\t%d\t%d\t%d\t%f\t
%c",a[i].rollno,a[i].name,a[i].cp,a[i].math,a[i].eng,a[i].total,a[i].avg,a[i].grade);
}
65
OUTPUT
Enter the number of students: 2
Enter the student 1 details:
RollNo:1
Name:sen
CP:90
math:85
English:80
Enter the student 2 details:
RollNo:2
Name:kavi
CP:85
math:65
English:70
Students mark details:
RollNo Name
1
sen
2
kavi
CP
90
85
Result:
Thus the C program to print the student rollno, name, marks using
66
#include<stdio.h>
#include<conio.h>
struct student
{
char name[25];
int rno;
int marks;
}s[10];
void main()
{
int i,n;
clrscr();
printf("\n Enter the number of the students");
scanf("%d",&n);
printf("\n Enter the student details");
printf("\n Enter the Rollno Name Marks");
for(i=1;i<=n;i++)
scanf("%d%s%d",&s[i].rno,&s[i].name,&s[i].marks);
printf("\n");
printf("\n Student details are \n\n");
printf("Rollno \t Name \t\t Marks\n");
for(i=1;i<=n;i++)
printf("%d\t\t%s\t\t%d\n",s[i].rno,s[i].name,s[i].marks);
getch();
}
67
68
FUNCTIONS
Ex no: 12
12.1 Write a C program to perform arithmetic operations using function.
Algorithm:
1.
Start
2.
Declare variables a,b,c,d,e,f
3.
Declare 4 functions add(), sub(), mul(), div()
4.
To get 2 inputs a, b
5.
Call add(). It return value to c
6.
Call sub(). It returns values to d
7.
Call mul(). It returns value to e
8.
Call div(). It returns value to f
9.
Print c, d, e, f values
10.
Stop
Flowchart:
start
Read a,b
Call add()
Call sub()
Call mul()
Call div()
Print c,d,e,f
end
69
add()
Sub()
C=a+b
D=a-b
Return C
Return D
Mul()
Div()
E=a*b
F=a/b
Return E
Return F
70
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,d,e,f;
int add(int a, int b);
int sub(int a, int b);
int mul(int a, int b);
int div(int a, int b);
clrscr();
printf("Enter 2 numbers");
scanf("%d%d",&a,&b);
c=add(a,b);
printf("Addition=%d\n",c);
d=sub(a,b);
printf("Subtraction=%d\n",d);
e=mul(a,b);
printf("Multiplication=%d\n",e);
f=div(a,b);
printf("Division=%d",f);
getch();
}
int add(int a, int b)
{
int z;
z=a+b;
return z;
}
int sub(int a, int b)
{
int z;
z=a-b;
return z;
}
int mul(int a, int b)
{
int z;
z=a*b;
return z;
}
int div(int a, int b)
{
int z;
z=a/b;
return z; }
71
OUTPUT:
Enter 2 numbers: 8
2
Addition=10
Subtraction=6
Multiplication=16
Division=4
12.2 Write a C program to find the factorial of a given number using
recursive function.
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int n;
long int fact();
clrscr();
printf("Enter the number:");
scanf("%d",&n);
printf("\nThe factorial of the given number %d is %ld",n,fact(n));
getch();
}
long int fact(int n)
{
if(n==0)
return(1);
else
return(n*fact(n-1));
}
OUTPUT:
Enter the number:5
The factorial of the given number 5 is 120
Result
Thus the C program to perform Addition, Subtraction, Multiplication, and
Division using function is executed successfully
72