0% found this document useful (0 votes)
161 views65 pages

CPL Lab Manual

This document provides a list of experiments for the computer practices laboratory course GE6161. The experiments cover topics like using MS Office applications, creating presentations and visualizations, problem formulation and flowcharts, C programming with arrays and strings, scientific problem solving using decision making and looping, and programming with structures and unions. Specific experiments listed include creating and manipulating documents, creating graphs and charts in Excel, drawing flowcharts, integer to float conversion in C, finding the area of a triangle in C, and checking if a number is odd or even in C.

Uploaded by

Subash Saravanan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
161 views65 pages

CPL Lab Manual

This document provides a list of experiments for the computer practices laboratory course GE6161. The experiments cover topics like using MS Office applications, creating presentations and visualizations, problem formulation and flowcharts, C programming with arrays and strings, scientific problem solving using decision making and looping, and programming with structures and unions. Specific experiments listed include creating and manipulating documents, creating graphs and charts in Excel, drawing flowcharts, integer to float conversion in C, finding the area of a triangle in C, and checking if a number is odd or even in C.

Uploaded by

Subash Saravanan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 65

tGE6161 COMPUTER PRACTICES LABORATORY L T P C0 0 3 2

LIST OF EXPERIMENTS:

1. Search, generate, and manipulate data using MS office / Open Office


2. Presentation and Visualization – graphs, charts, 2D, 3D
3. Problem formulation, Problem Solving and Flowcharts
4. C Programming using Simple statements and expressions
5. Scientific problem solving using decision making and looping.
6. Simple programming for one dimensional and two dimensional arrays.
7. Solving problems using String functions
8. Programs with user defined functions – Includes Parameter Passing
9. Program using Recursive Function and conversion from given program to flow chart.
10. Program using structures and unions.
EX.NO : 1 DOCUMENT CREATION, SEARCH, TEXT MANIPULATION

AIM:
To create a document and manipulate the text with specific notations using MS-office.
PROCEDURE :

1. Open a new document using File → New option and type text.
2. For justification, select the entire text in the document then press CTRL+J or select the justify
button on the formatting toolbar.
3. For bold facing, select the particular word then press CTRL +B or select the B on the
formatting toolbar.
4. To make Italic style, select the particular word then press CTRL +I or select the I on the
formatting toolbar.
5. For Underlining , select the particular word then press CTRL +U or select the U on the
formatting toolbar.
6. For spelling corrections, select the particular word, then right click the mouse or click spelling
and grammar button on the standard tool bar.
7. For saving the document, press CTRL+S or click on save button on standard tool bar or select
the save option from the File menu.

The above options are commonly used for creating the document. Apart from these, MS
WORD provides a lot of options for making the document an attractive one.

RESUME
Raghul. V
4/10,Nehru Street, e-mail id : [email protected]
Salem-10. Mobile No.: 9876543210

OBJECTIVE:
To obtain a meaningful and challenging position which will enables me to become a
recognized employee, face the challenges, serve the industry with all my might and to learn and
acquire more practical knowledge.

EDUCATIONAL QUALIFICATION:
 M.E. Computer Science with 8.6 CGPA in V.S.B. Engineering College,Karur.

 B.E. Computer Science with an aggregate of 73% from V.S.B. Engineering College,

Karur.
 HSC 2006, with an aggregate of 68% from Cheran school, Karur
 SSLC 2004, with an aggregate of 72% from Cheran school, Karur

SOFTWARE SKILLS:

LANGUAGES : C, C++, JAVA.


PACKAGES : MS-Office

AREA OF INTEREST:

 Data Structure
 Computer Networks

PERSONAL DETAILS:

NAME : Raghul.V
FATHER’S NAME : Vishnu.R
DATE OF BIRTH : 06-03-1988
COMMUNICATION
ADDRESS : 4/10,Nehru Street,
Salem-10.

DECLARATION

I hereby declare that the above details are true to the best of my knowledge.
Yours
Raghul.V

/* USE OF SCIENTIFIC NOTATIONS*/

PROCEDURE:

1. Open a new document using File → New option.


2. To create Equation using Scientific Notation, choose Insert →Equation.
3. Type the required equation in the Equation tool using the scientific notations found in
Equation tool→ Design.
4. For saving the document, press CTRL+S or click on save button on standard tool bar or select
the save option from the File menu.
EQUATIONS:

1. 2 y−3 tx+a t 3=0

x y
2. + =1
a b

3. x 2+ y 2+ z 2 +2 x−4 y+ 2 z−3=0

4. h [ γ −γ 1 ] =0

sin( A + D)/2
5. μ=
sin A /2

1
6. σ =
ρ

RESULT:

Thus, the given document has been created and manipulated using MS-office.
EX.NO:02 PRESENTATION AND VISUALIZATION – GRAPHS AND CHARTS

AIM:
To prepare the Line, XY, Bar and Pie Charts in MS-Excel.
Create examination databases and find the total and average of each student.

RULES:

1. PASS if marks in each subject >= 35.


2. FAIL if marks in any subject < 35.
3. Distinction if average >= 75.
4. First class if average >= 60 but less than 75.
5. Second class if average >= 50 but less than 60.
6. Third class if average >= 35 but less than 50.

PROCEDURE:

1. Enter the given data in worksheet.


2. Choose the chart option from the insert menu, or choose the chart wizard button
from the standard toolbar.
3. Shows the chart wizard step 1 of 4 chart type dialog box.
4. Choose the appropriate chart type from the chart type list box then click next.
5. Shows the chart wizard step 2 of 4 chart source data dialog box, then click next.
6. Shows the chart wizard step 3 of 4 chart options dialog box, here you can give the
Chart title. (i) X and Y axis title etc., then click next.
7. Shows the chart wizard step 4 of 4 chart location dialog box then click finish.
BAR CHART:
OUTPUT:
LINE CHART:
OUTPUT:
XY CHART:
OUTPUT:
PIE CHART:
OUTPUT:
EX.NO : 3 PROBLEM SOLVING AND FLOWCHARTS

AIM:
To draw a flowchart using drawing toolbar in MS-WORD.
PROCEDURE :

1. Choose flowchart options in the auto shapes menu of the Drawing Toolbar.
2. Choose the appropriate flowchart symbol and then drag the symbol in the document.
3. Type the text in the symbol, by right click then choose Add Text.
4. Using the Arrow button, Line style button and Arrow Style in the Drawing Toolbar the lines
onnecting to the different flowchart symbols.
5. Select all the flowchart symbols and lines in the document using the Select Objects button,
then right choose Grouping, then click on Group.
6. Now all the Flowchart symbols are grouped into one.
SAMPLE FLOWCHART:

start
Start

Read a,b
Read a,b

No
yes If a>b

Read a Read b

Stop
EX:NO:4(a) INTEGER TO FLOAT CONVERSION
AIM:
To write a c program to convert a value of one data type into another data type.

ALGORITHM:
Step1:Start
Step 2: Declare the necessary variables a and b as integer and float.
Step 3: Read the input of the integer a.
Step 4: Assign the value of the integer to a float variable and a double
variable.
Step 5: Display the value of the float variable and the double variable.
Step6:Stop.
PROGRAM:
#include<stdio.h>
#include<conio.h>
void main()
{
float b;
int a;
clrscr();
printf("\n enter an integer\n");
scanf("%d",&a);
b=(float)a;
printf("\n the converted float value is %f",b);
getch();
}
OUTPUT:
EX:NO:4(b) AREA OF A TRIANGLE
Date:

AIM:
To write a program in C to find the area of a given triangle of sidesa,b,c.

ALGORITHM:

Step1: Start
Step2: read the input values of sides of a triangle a,b,c
Step3: compute s=(a+b+c)/2
Step4: compute d=(s*(s-a)*(s-b)*(s-c))
Step5: compute the area of triangle area=sqrt(d)
Step6: print area
Step7: Stop

PROGRAM:

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int a,b,c;
float s,d,area;
clrscr();
printf("enter three sides:");
scanf("%d%d%d,&a,&b,&c");
s=(a+b+c)/2;
d=(s*(s-a)*(s-b)*(s-c));
area=sqrt(d);
printf("area of triangle=%f sq units \n",area);
getch();
}

OUTPUT:

EX:NO:4(c) SIZE OF OPERATOR

PROGRAM:
#include<stdio.h>
#include<conio.h>
void main()
{
int num=1234567890;
float dec=0.123456;
double ext=0.123456789;
char ltr='A';
clrscr();
printf("size of num int is %d bytes\n",sizeof num);
printf("size of dec float is %d bytes\n",sizeof dec);
printf("size of ext double is %d bytes\n",sizeof ext);
printf("size of ltr char is %d bytes\n",sizeof ltr);
getch();
}

OUTPUT:

EX:NO:4(d) CONVERSION OF CELCIUS INTO FAHRENHEIT AND


Date:

AIM:
Write a program in C to coversion of celcius into Fahrenheit and .

ALGORITHM:

Step1: Start
Step2: Read the Celsius value
Step3: Calculate the fahrenhiet value by using the formula f=(1.8*c)+32
Step4: Print the fahrenhiet value
Step5: Read the fahrenhiet value
Step6: Calculate the Celsius value by using the formula c=(f-32)/1.8
Step7: Print the Celsius value
Step8: Stop

PROGRAM:

#include<stdio.h>
#include<conio.h>
void main()
{
float c,f;
//float a,b;
clrscr();
printf("\n\nEnter the value of temp in Celcius\n");
scanf("%f",&c);
f=(1.8*c)+32;
printf("\nThe equivalent farenhiet value is%f\n",f);
printf("\nEnter the value of temp in Farenhiet");
scanf("%f",&f);
c=(f-32)/1.8;
printf("\nThe equivalent celcius value is%f\n",c);
getch();
}

OUTPUT:

EX:NO:4(e) SWAPING THE VARIABLE WITHOUT USING OTHER VARIABLE


PROGRAM:

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("\nEnter the value of a & b\n");
scanf("%d%d",&a,&b);
a=a+b;
b=a-b;
a=a-b;
printf("The values of a & b after swapping are \n%d\n%d",a,b);
getch();
}

OUTPUT:
Result:
Thus the above programs was written and executed successfully.

SCIENTIFIC PROBLEM SOLVING USING DECISION MAKING


AND LOOPING
EX:NO:5(a) ODD OR EVEN
AIM:
To write a c program to check whether given Number is odd or even.

ALGORITHM:

Step 1: Declare a variable to get a Number


Step 2: Read the input
Step 3: Get the remainder of given number using modulo operator
Step 4: If remainder is 0 prints “Even Number”, else print “Odd Number”.
PROGRAM:
#include<stdio.h>
#include<conio.h>
void main()
{
int a,rem;
clrscr();
printf("enter a number\n");
scanf("%d",&a);
rem=a%2;
if(rem==0)
printf("the given number is even");
else
printf("the given number is odd");
getch();
}

OUTPUT:
EX:NO:5(b) ARITHMETIC CALCULATOR

AIM:
To write a menu driven c program to implement an Arithmetic Calculator.

ALGORITHM:

Step 1: Get the two numbers


Step 2: Enter the choice
Step 3: Pass the choice into switch case
Step 4: In case 1, add the two numbers and print the result
Step 5: In case 2, subtract the two numbers and print the result
Step 6: In case 3, multiply the two numbers and print the result
Step 7: In case 4, divide the two numbers and print the result

PROGRAM:
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,ch;
float c;
clrscr();
printf("\n enter the number:\n");
scanf("%d",&a);
printf("\n enter the number:\n");
scanf("%d",&b);
printf("\n 1. add \n 2. subtract \n 3. multiply \n 4. divide \n");
printf("\n enter the choice:\n");
scanf("%d",&ch);
switch(ch)
{
case 1:
c=a+b;
printf("\nThe addition of two numers are%f",c);
break;
case 2:
c=a-b;
printf("\nThe difference b/w two nos are %f",c);
break;
case 3:
c=a*b;
printf("\nThe multiplication of two nos are%f",c);
break;
case 4:
c=a/b;
printf("\nthe division is%f",c);
break;
}
getch();
}
OUTPUT:

EX:NO:5(C) ARMSTRONG OR NOT

PROGRAM:

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,d;
clrscr();
printf("enter the number");
scanf("%d",&a);
b=a;
c=0;
while(a>0)
{
d=a%10;
c=c+(d*d*d);
a=a/10;
}
if(b==c)
printf("%d is an armstrong number",b);
else
printf("%d is not an armstrong number",b);
getch();
}

OUTPUT:
EX:NO:5(d) BIGGEST OF 3 NUMBERS

AIM:
To write a c program to examine the biggest of given three numbers.

ALGORITHM:
Step 1: Declare three integer variables
Step 2: Read the 3 inputs
Step 3: Compare first two numbers and go to Step4
Step 4: If first number is greater than second number then compare first
number with third number else go to step 6
Step 5: If first number is greater than third number print first number as
biggest number else print third number as biggest
Step 6: Compare second number with third number
Step 7: If second number is greater than third number print second number
as biggest number else print third number as biggest

PROGRAM:

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf("enter 3 numbers\n");
scanf("%d%d%d",&a,&b,&c);
if(a>b)
{
if(a>c)
{
printf("the first nummber %d is biggest\n",a);
}
}
else if(b>c)
{
printf("the second number %d is biggest\n",b);
}
else
printf("the third number %d is biggest\n",c);
getch();
}

OUTPUT:
EX:NO:5(e) FACTORIAL OF THE GIVEN NUMBER

AIM:

To write a program to find the factorial of the given number


ALGORITHM:

Step-1 Start the program


Step-2 Enter a number
Step-3 Set a loop to find the factorial of the given number using the
formula
Fact=Fact*I
Step-4 Print the factorial of the given number
Step-5 Stop

PROGRAM:

#include<stdio.h>
#include<conio.h>
void main()
{
int fact=1,i,num;
clrscr();
printf("enter the number");
scanf("%d",&num);
for(i=1;i<=num;i++)
{
fact=fact*i;
}
printf("the factorial is %d",fact);
getch();
}

OUTPUT:

EX:NO:5(f) SUM OF N NATURAL NUMBERS

AIM:
To write a c program to find the sum of “N‟ natural numbers for given range.

ALGORITHM:
Step 1: Initialize the sum as 0
Step 2: Read the range as input
Step 3: Initialize a counter with 1
Step 4: Overwrite the sum by adding counter value & sum
Step 5: Increment the counter value by 1
Step 6: Repeat the steps 4 & 5 until the counter is less than or equal to range
Step 7: Print the sum

PROGRAM:

#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,sum=0;
clrscr();
printf("enter the range\n");
scanf("%d",&n);
i=1;
while(i<=n)
{
sum=sum+i;
i++;
}
printf("\n the sum of first %d numbers is %d\n",n,sum);
getch();
}
OUTPUT:
EX:NO:5(g) SUM OF DIGITS

AIM:
To write a c program to find the sum of digits for a given number.

ALGORITHM:

Step 1: Declare a integer variable and initialize the sum as 0


Step 2: Read the input
Step 3: Take the remainder of given number while dividing 10
Step 4: Overwrite the sum by adding above remainder with available sum
Step 5: Overwrite the number by divide with 10
Step 6: Repeat the steps 3 to 5 until the number is greater than 0
Step 7: Print the sum

PROGRAM:

#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,sum=0;
clrscr();
printf("enter a number\n");
scanf("%d",&n);
do
{
i=n%10;
sum=sum+i;
n=n/10;
}
while(n>0);
printf("the sum of digit is %d\n",sum);
getch();
}

OUTPUT:
EX:NO:5(h) NUMBER CHECKING

AIM:
To write a menu driven c program to check whether the given number is Palindrome,
Armstrong and Prime.

ALGORITHM:

Step 1: Get a number from the user


Step 2: Enter the choice
Step 3: Pass the choice into switch case
Step 4: In case 1,
a. Copy the given number into a variable
b. Initialize a counter to 1 and sum to 0
c. Extract the remainder of given number while dividing 10
d. Multiply the sum by 10
e. Overwrite the sum by adding above remainder with available sum
f. Overwrite the number by divide with 10
g. Repeat the steps a to f until the number is greater than 0
h. Compare the sum and copy of the number
i. If they are equal print as “Palindrome” else print “Not Palindrome”
Step 5: In case 2,
a. Copy the given number into a variable
b. Initialize a counter to 1 and sum to 0
c. Extract the remainder of given number while dividing 10
d. Calculate the value of remainder by assigning power 3
e. Overwrite the sum by adding above result with available sum
f. Overwrite the number by divide with 10
g. Repeat the steps a to e until the number is greater than 0
h. Compare the sum and copy of the number
i. If they are equal print as “Armstrong” else print “Not Armstrong”
Step 6: In case 3,
a. Initialize a flag value with 5
b. Initialize a counter to 2
c. Extract the remainder of given number by dividing with counter value
d. If the remainder is 0 changes the flag value to 0 and go to step g else go to next step.
e. Increment the counter value by 1
f. Repeat the steps a to e until counter is less than or equal to square root of the given
number
g. Check the flag value
h. If flag value is 0 then print as “Prime Number” else print as “Not Prime”

PROGRAM:

#include<stdio.h>
#include<conio.h>
void main()
{
int a,i,sum=0,n,ch,m;
clrscr();
printf("\n enter a number\n");
scanf("%d",&a);
printf("\n 1.palindrome\n 2.Armstrong\n 3.prime\n");
printf("\n enter the choice:\n");
scanf("%d",&ch);
switch(ch)
{
case 1:
n=a;
while(a>0)
{
i=a%10;
sum=(sum*10)+i;
a=a/10;
}
if(n==sum)
printf("given number is palindrome\n");
else
printf("given number is not palindrome\n");
break;
case 2:
n=a;
do
{
i=a%10;
sum=sum+(i*i*i);
a=a/10;
}while(a>0);
if(n==sum)
printf("given number is armstrong\n");
else
printf("given number is not armstrong\n");
break;
case 3:
m=5;
n=sqrt(a);
for(i=2;i<=n;i++)
{
if(a%i==0)
{
m=0;
break;
}
}
if(m==0)
printf("given number is prime\n");
else
printf("given number is not prime\n");
break;
}
getch();
}

OUTPUT:

Result:
Thus the above programs was written and executed successfully.
SIMPLE PROGRAMMING FOR ONE DIMENSIONAL AND TWO
DIMENSIONAL ARRAYS
EX:NO:6(a) LARGEST AND SMALLEST ELEMENT OF THE GIVEN ARRAY
AIM:
To write a program to find the largest and smallest of the given array.
ALGORITHM:

Step-1 Start the program


Step-2 Enter the size of 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 then the larger.
If greater then as sign next element to the large
Step-8 Check the next element smaller then the larger. If smaller
then assign next element to the small
Step-9 Print the value of large and small after the execution of the loop
Step-10 Stop
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(“Enter the elements of the array....”);
for(i=0;i<no;i++)
scanf(“%d”,&a[i]);
printf(“\nThe 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(“\nThe largest of the given array is %d”,large);
printf(“\nThe smallest of the given array is %d”,small);
getch();
}

OUTPUT:

EX:NO:6(B) ADDITION OF TWO MATRIXES

AIM:
To write a program to give the 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 the A matrix
Step-4 Enter the elements of the B atrix Step-5
Print the A matrix in the matrix form
Step-6 Print the B matrix in the matrix form
Step-7 Set a loop up to the row
Step-8 Set a inner loop up to the column
Step-9 Add the elements of A and B in column wise and store the result
in C matrix
Step-10 After the execution of the two loops. Print the value of C
matrix
Step-11 Stop
PROGRAM:

#include<stdio.h>
#include<conio.h>
Void main()
{
int a[25][25],b[25][25],c[25][25],i,j,m,n;
printf(“Enter the rows and column of two matrixes...\n”);
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(“\nThe elements of A matrix”);
for(i=0;i<m;i++)
{
printf(“\n”);
for(j=0;j<n;j++)
printf(“\t%d”,a[i][j]);
}
printf(“\nThe elements of B matrix”);
for(i=0;i<m;i++)
{
printf(“\n”);
for(j=0;j<n;j++)
printf(“\t%d”,b[i][j]);
}
printf(“\nThe addition 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]);
}}
}
OUTPUT:

EX:NO:6(c) MULTIPLICATION OF 3*3 MATRIXES

PROGRAM:

#include<stdio.h>
#include<conio.h>
void main()
{
int a[3][3],sum,b[3][3],c[3][3],i,j,k;
clrscr();
printf("enter the 1st matrix");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("enter the 2nd matrix");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
scanf("%d",&b[i][j]);
}
}
printf("\n the 1st matrix is:\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
printf("%d\t",a[i][j]);
}
printf("\n");
}
printf("\n the 2nd matrix is:\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
printf("%d\t",b[i][j]);
}
printf("\n");
}
printf("the multiplication of two matrix is:");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
sum=0;
for(k=0;k<=2;k++)
{
sum=sum+a[i][k]*b[k][j];
c[i][j]=sum;

}
}
}
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
printf("%d\t",c[i][j]);
}
printf("\n");
}
getch();
}

OUTPUT:

EX:NO:6(d) ADDITION OF 3*3 MATRIXES

PROGRAM:

#include<stdio.h>
#include<conio.h>
void main()
{
int a[3][3],b[3][3],c[3][3],i,j;
clrscr();
printf("enter the 1st matrix");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("enter the 2nd matrix");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
scanf("%d",&b[i][j]);
}
}
printf("\n the 1st matrix is:\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
printf("%d\t",a[i][j]);
}
printf("\n");
}
printf("\n the 2nd matrix is:\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
printf("%d\t",b[i][j]);
}
printf("\n");
}
printf("the sum of two matrix is:");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
c[i][j]=a[i][j]+b[i][j];
}
}
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
printf("%d\t",c[i][j]);
}
printf("\n");
}
getch();
}

OUTPUT:

Result:
Thus the above programs was written and executed successfully.
SOLVING PROBLEMS USING STRING FUNCTIONS

EX:NO:7(a) STRING PALINDROME


AIM:
To write a c program to check whether the given string is palindrome or not

ALGORITHM:

Step 1: Create a character array with necessary size


Step 2: Read the String
Step 3: Copy the String into another character array
Step 4: Get reverse string of input by using strrev function
Step 5: Compare the above result with copied string
Step 6: If two string s are same print “Palindrome” else print “Not Palindrome”

PROGRAM:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char s[20],s1[20];
clrscr();
printf("enter a string\n");
scanf("%s",s);
strcpy(s1,s);
strrev(s1);
if(strcmp(s,s1)==0)
printf("the given string is palindrome\n");
else
printf("the given string is not palindrome\n");
getch();
}
OUTPUT:

EX:NO:7(b) COMPARE TWO STRINGS


AIM:
To write a C program to compare two strings using strcmp().
ALGORITHM:
Start 1: start the progrm.
Start 2: get the first string.
Start 3: get the second string.
Start 4: using strcmp () function compare the two strings.
Start 5: else prints not equal.
Start 6: stop the program.
PROGRAM:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char name[80],name1[80];
int result;
clrscr();
printf("enter the 1st string\n");
gets(name);
printf("enter the 2nd string\n");
gets(name1);
result=strcmp(name,name1);
if(result==0)
printf("\n both strings are equal");
else
printf("\n both string are not equal");
getch();
}

OUTPUT:
EX:NO:7(c) COPY THE STRING
AIM:
To write a C program to copy the strings using strcpy()
ALGORITHM:

Start 1: start the program.


Start 2: get the string.
Start 3: copy the string into another string variable by using strcpy() fucntion
Start 4: print the string.
Start 5: stop the program
PROGRAM:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char name[160],name1[80];
clrscr();
printf("\n enter string into name:");
gets(name);
strcpy(name1,name);
printf("\nname1:%s",name1);
getch();
}
OUTPUT:

EX:NO:7(d) STRING CONVERTION TO LOWER CASE,UPPERCASE, STRING


LENGTH
AIM:
To write a C program to convert the strings to lower case, upper case, find string length.
ALGORITHM:
Start 1: start the program.
Start 2: get the string.
Start 3: using strlwr() fucntion to convert the lower case of the string.
Start 4: print the lower string.
Start 5: using strupr() fucntion to convert the upper case of the string.
Start 6: print the upper string.
Start 7: using strrev() fucntion to convert the reverse order of the string.
Start 8: using strlen() function to find the length of the string.
Strat 9: print the string.
Start 10: stop the program.
PROGRAM:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char str[80];
clrscr();
printf("\n enter the string");
gets(str);
printf("\n lower case of string:%s",strlwr(str));
printf("\n uppercase of string:%s",strupr(str));
printf("\n reverse of string:%s",strrev(str));
printf("\n the length of string is:%d",strlen(str));
getch();
}

OUTPUT:
EX:NO:7(e) STRING CONCATENATION

AIM:
To write a c program to find the length of given two strings and concatenate
them

ALGORITHM:

Step 1: Create two character arrays with necessary size


Step 2: Read the Strings
Step 3: Calculate the string lengths using strlen function
Step 4: Print the string lengths
Step 5: Join the two strings using strcat function
Step 6: Print the concatenated string

PROGRAM:

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char s[20],s1[20];
clrscr();
printf("enter a 1st string\n");
scanf("%s",s);
printf("enter a 2nd string\n");
scanf("%s",s1);
strcat(s,s1);
printf("the concatenated string is\n%s",&s);
getch();
}

OUTPUT:
Result:
Thus the above programs was written and executed successfully.
PROGRAMS WITH USER DEFINED FUNCTIONS

EX: NO: 08 (a) FUNCTIONS WITHOUT ARGUMENTS & RETURN TYPE

AIM:
To write a c program to check whether the given year is leap or not using functions.

ALGORITHM:

Step 1: Create a function isleap()


Step 2: Inside the function
a. Read the year as input
b. Extract the remainder from division operation of year by 4
c. If remainder is 0 print “Given year is Leap year” else print
“Given year is not a Leap year”
Step 3: Inside the main function call the isleap()

PROGRAM:
#include<stdio.h>
#include<conio.h>
void is_leap()
{
int yr;
clrscr();
printf("enter a year\n");
scanf("%d",&yr);
if(yr%4==0)
printf("given year is leap year");
else
printf("given year is not a leap year");
getch();
}
main()
{
is_leap();
}

OUTPUT:
EX: NO: 08 (b) FUNCTIONS WITHOUT ARGUMENTS & WITH RETURN TYPE

AIM:
To write a c program to calculate the area of triangle using functions.

ALGORITHM:

Step 1: Create a function area()


Step 2: Inside the function
a. Read the 3 sides of triangle
b. Calculate the sum of 3 sides
c. Divide the sum by 2 and store it into s
d. Subtract the sides from sand store them into variables
e. Multiply s with above 3 results
f. Take the square root of above result
g. Return the above result as area
Step 3: Inside the main function call the function area()
Step 4: Print the area by obtaining the return value of area()

PROGRAM:
#include<stdio.h>
#include<conio.h>
#include<math.h>
float area()
{
int a,b,c;
float s,r;
clrscr();
printf("enter 3 sides\n");
scanf("%d%d%d",&a,&b,&c);
s=(a+b+c)/2;
r=sqrt(s*(s-a)*(s-b)*(s-c));
return r;
}
main()
{
float a;
a=area();
printf("the area of triangle is%f\n",a);
getch();
}

OUTPUT:
EX: NO: 08 (c) FUNCTIONS WITH ARGUMENTS & WITHOUT RETURN TYPE

AIM:
To write a c program to sort the given array of elements using functions.

ALGORITHM:

Step 1: Create a function sort()


Step 2: Inside the function
a. Initialize a index to 0
b. Initialize the sub index to counter + 1
c. Compare the two numbers which are available in array index value and array sub
index value
d. If the first number is greater than second number swap them
e. Increment the sub index by 1
f. Repeat the steps c to e until sub index less than total number of elements
g. Increment the index by 1
h. Repeat the steps b to g until sub index less than total number of elements
i. Print the array elements
Step 3: Inside the main function
a. Create an integer array with necessary size
b. Get the total number of elements
c. Read the array elements one by one
d. Call the sort() function by passing array and no. of elements as arguments

PROGRAM:
#include<stdio.h>
#include<conio.h>
void sorting(int a[],int n)
{
int i,j,t;
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(a[i]>a[j])
{
t=a[i];
a[i]=a[j];
a[j]=t;
}
}
}
printf("array elements before sorting\n");
for(i=0;i<n;i++)
printf("%d\t",a[i]);
}
main()
{
int i,a[10],n;
clrscr();
printf("enter total no.of elements\n");
scanf("%d",&n);
printf("enter array elements one by one\n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("array elemets before sorting\n");
for(i=0;i<n;i++)
printf("%d\t",a[i]);
printf("\n");
sorting(a,n);
getch();
}

OUTPUT:
EX: NO: 08 (d) FUNCTIONS WITH ARGUMENTS & RETURN TYPE

AIM:
To write a c program to find the smallest element of given array of elements
using functions.

ALGORITHM:

Step 1: Create a function small()


Step 2: Inside the function
a. Store the 0th index value into base
b. Initialize a index to 1
c. Compare the array index value with base
d. If the array index value is smaller than base store the array index value into base
e. Increment the index by 1
f. Repeat the steps c & e until index reaches total no. of elements
g. Return the base value
Step 3: Inside the main function
a. Create an integer array with necessary size
b. Get the total number of elements
c. Read the array elements one by one
d. Call the small() function by passing array and no. of elements as arguments

PROGRAM:

#include<stdio.h>
#include<conio.h>
int small(int a[],int n)
{
int s,i;
s=a[0];
for(i=0;i<n;i++)
{
if(a[i]<s)
s=a[i];
}
return s;
}
main()
{
int i,a[10],n,s;
clrscr();
printf("enter total no of elements\n");
scanf("%d",&n);
printf("enter array elements one by one\n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("array elements:\n");
for(i=0;i<n;i++)
printf("%d\t",a[i]);
printf("\n");
s=small(a,n);
printf("the smallest element of given array is%d",s);
getch();
}

OUTPUT:

Result:
Thus the above programs was written and executed successfully.
EX.NO:9(a) RECURSIVE FUNCTIONS –FACTORIAL OF A NUMBER

AI M:
To write a C program to find the factorial of a given number

ALGORITHM:

1. Start the program.


2. Declare the necessary variables.
3. Get the number from user to find the factorial.
4. Write a user defined function for factorial using the formula n*fact (n-1).
5. Print the factorial of the given number.
6. Stop the program.

PROGRAM:

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int num,a;
clrscr();
printf("enter the number");
scanf("%d",&num);
a=recur(num);
printf("the factorial of the number %d is %d",num,a);
getch();
}
recur(int no)
{
int fact=1;
if(no==1)
return(1);
else
fact=no*recur(no-1);
return fact;
}
OUTPUT:
EX:NO:9(b) FIBONACCI SERIES

AIM:
To write a program in C to print the Fibonacci series.

ALGORITHM:

Step-1: Start
Step-2: Read the input variable ‘n’
Step-3: Call function fib(n)
Step-4: Stop.

FUNCTION:

Step-1: a=0,b=1
Step-2: print a, b
Step-3: for(i=0;i<n;i++)
Step-3-1: c=a+b
Step-3-2: a=b
Step-3-3: b=a
Step-3-4: print c
Step-4: stop
PROGRAM:

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,n;
clrscr();
printf("enter the fibonacci series limit\n");
scanf("%d",&n);
fib(n);
getch();
}
int fib(int n)
{
int a,b,c,i;
a=0;
b=1;
printf("\n fibonacci series\n");
printf("\n%d\n%d",a,b);
for(i=0;i<n;i++)
{
c=a+b;
a=b;
b=c;
printf("\n%d",c);
}
return 0;
}

OUTPUT:
Result:
Thus the above programs was written and executed successfully.
EX:NO:10(a) PROGRAM USING STRUCTURES AND UNIONS
STUDENT STRUCTURE
PROGRAM:

#include<stdio.h>
#include<conio.h>
struct student
{
char name[10];
int rollno,m1,m2,m3,total;
};
void main()
{
int num,i,j;
struct student s1[10];
clrscr();
printf("enter the no of students\n");
scanf("%d",&num);
for(i=0;i<num;i++)
{
printf("enter the roll number");
scanf("%d",&s1[i].rollno);
printf("enter the name");
scanf("%s",&s1[i].name);
printf("enter the mark1");
scanf("%d",&s1[i].m1);
printf("enter the mark2");
scanf("%d",&s1[i].m2);
printf("enter the mark3");
scanf("%d",&s1[i].m3);
s1[i].total=s1[i].m1+s1[i].m2+s1[i].m3;
}
printf("\n the details of the mark list is as follows\n");
printf("\n roll no");
printf("\t name");
printf("\t mark1");
printf("\t mark2");
printf("\t mark3");
printf("\t total");
printf("\n");
for(i=0;i<num;i++)
{
printf("\n%d",s1[i].rollno);
printf("\t%s",s1[i].name);
printf("\t%d",s1[i].m1);
printf("\t%d",s1[i].m2);
printf("\t%d",s1[i].m3);
s1[i].total=s1[i].m1+s1[i].m2+s1[i].m3;
printf("\t%d",s1[i].total);
}
getch();
}

OUTPUT:
PROGRAM FOR SIZE OF UNION
AIM:
To write a c program to store the book information using union.

ALGORITHM:

Step 1: Create an union book


Step 2: Declare one integer and a character array inside the union for book name and book price
Step 3: Get the book name and price
Step 4: Print the book name and price
Step 5: Get the Book name alone
Step 6: Print the Book name
Step 7: Get the Book Price
Step 8: Print the Book price
PROGRAM:
#include<stdio.h>
#include<conio.h>
union book
{
int price;
char bname[20];
};
void main()
{
union book b;
clrscr();
printf("enter the book details:\n");
printf("enter the book name:\n");
scanf("%s",&b.bname);
printf("enter the book price:\n");
scanf("%d",&b.price);
printf("book details:\n");
printf("%s\t%d\n",b.bname,b.price);
printf("enter the book name:\n");
scanf("%s",b.bname);
printf("book name=%s\n",b.bname);
getch();
}
OUTPUT:

Result:
Thus the above programs was written and executed successfully.

You might also like