Documente Academic
Documente Profesional
Documente Cultură
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
OUTPUT
S EARCH ,
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.
Micro computers
Mini computers
Mainframe computers
Super computers
M ANIPULATING D ATA :
S EARCHING
DATA :
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
Binary
11000
octal
30
4
Hexadeci
mal
18
45
28
99
31
101101
11100
1100011
11111
55
34
143
37
2D
1C
63
1F
Minute
60
960
1320
1080
1200
Seconds
3600
57600
79200
64800
72000
Fahrenheit
87.8
71.6
104
118.4
100.4
Kelvin
304.15
295.15
313.15
321.15
311.15
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
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
DELHI
BANGALORE
147
MUMBAI
22 17
65
2 11
13
24
11
70
30
12
203
20
23 10
47
52
13
HYDERABAD
4
CHENNAI
7
15 17
11
23
35
74
82
13
23
21
27
35
40
41
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
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
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.
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
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.
OUTPUT:
PROBLEM FORMULATION, PROBLEM SOLVING AND FLOWCHARTS
FLOWCHART
PRODUCT OF TWO NUMBERS
Start
Read A,B
C=A*B
Print C
Stop
20
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
Read a,b,c
d=b*b4*a*c
Is d>=0
No
Yes
Root1=-b+sqrt(d)/
(2*a)
Root2=-b-sqrt(d)/
Stop
22
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
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
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
27
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
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
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
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
b=fib;
printf("%d\t",fib);
}
}
getch();
}
OUTPUT
FIBONACCI SERIES
Enter the number:5
0
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
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
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
RESULT
47
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.
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
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
{
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
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
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
10
14
16
6
12
18
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
-2
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
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
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
72
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
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
{
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
80
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
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
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
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
OUTPUT
EMPLOYEE DETAILS USING UNION
Enter the employee name...priya
priya
Enter the employee number...100
100
96
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
}
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