You are on page 1of 14

Computer Practice I

Lab Manual

AIM: To write a program to insert an element to an array in the given


....... position
ALGORITHM
Step-1
Step-2
Step-3
Step-4
Step-5

Start the program


Enter the size of the array
Enter the elements of the array
Print the elements of the array
Enter the element to be inserted and its position in the
array
Step-6
Set a loop up to the position you enter
Step-7
Push the order of the position by one, which are greater,
t h e n t h e p o s i t i o n yo u e n t e r e d
Step-8
I n s e r t t h e e l e m e n t i n t h e p o s i t i o n e n t e r e d b y yo u
Step-9
Print the array after insertion of the element
Step-10 St op
FLOWCHART

(Stop)
alif=ari-1/ 24
posi=iterri

i=1

PROGRAM
/*INSERTING AN ELEMENTS INTO THE VECTOR*/
#inelude<stdio.h>
main()

I
int 41001,no,i,pos,item;
printf("tnEnter the size of the an array");

Computer Practice I

Lab Manual

scanf(" %d", &no);


p r intf ("i nE nte r t he ele me nt s t o a n a rray") ;
fora= 0;i < no;i+ + )
scanfr %d", &Win;
printf("lnEntered elements of an a rray") ;
for(i =0;i < no;i + + )
printfr ln%d",afil);
printf("inEnter the element and its position in the array");

seanf(" %dLn%d", &item, &pos);


no+ +;
for(i =no;i> =pos,-i--)
afi afi-11;
afpos] =item;
printf(" In");
printfrInArray after the insertion"
fora = 0;i < noii + + )
printf(" In%d",afil);

SAMPLE. OUTPUT:
Enter the size of an array
5
Enter the elements to an array
1 2 4 5 6
Entered elements of an array
1 2 4 5 6
Enter the element and its position in the array
3
A r r a y a f t e r t he i nse rt i o n
1 2 3 4 5 6

2.

AIM: To write a program to print the ascending and descending


o r d e r o f th e g i v en a r r a y .

A-roam
Step-I

S t art t he program .

S t e p 2 Eater 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.
Step-6' _Er not greater than then go to tie loop.
-

Computer Practice I

Lab Manual

Step-9
After the execution of the inner loop the outer loop is executes
Step-10 Print the ascending order of the given array.
Step-11 Print the descending order of the given array.
Step-12 Stop.

a=numiii
nunifij--numtij
nurniji=a

*AS .I
AND DESCENDING ORDER OF THE GIVEN U1 BE
#include < stdio.h>
main()

I
int numil 00j, no,i,j,a ;
p r int f("En te r Uppe r Li mit .. . " );
seanf("%d",&no);
p r a t ( " E n t e r` t h e n u mb e rs" ) ;
f o r a = 0 ; i < n o ; i )
s c a n f ( ` % d " , &n u m f i j )
0,1 <no-1;i + )

I
f o r( i = r I < n o ; f -t - + )

I
if(numfil <num[fi)

I
numfijr;
-= numb);

Computer Practice I

Lab Manual

numb:1=a;

I
ptintf("1nThe ascending order of the given numbers");
for(1- - =0;i<no;i )
ptintfr in%d",nurniril);
printf("in The descending number of t he given numbers");
for(i=no-1;j> =0;j- -)
printf(" In%d",numbl);

I
SAMPLE OUTPUT
Enter Upper Limit.5
Enter the numbers
10 30 50
60 20
The ascending order of the given numbers
10
20
30
50
60
T h e d e s c e n d i n g n um b e r o f t he g i v e n n um b e r s
60
50
30
20
10

AIM: To write a program to find the largest and smallest of the


given array.

,41kLpoRri
Step-1
Step-2
Step-3
Step-4
Step-5

Start the program.


Enter the size of array.
Enter the elements of the array.
Print the array elements.
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 assign 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 ex ecution of the
loop.
Step -10 Stop.

Computer Practice I

large = ajar
small = al 01

Lab Manual

print large i srnan

//FIND THE LARGEST AND SMALLEST OF THE GIVEN ARRAY


#inelude <stdio.h>
main()

I
jut a[1001,i,small,large,no;
printf("In how many numbers you want to find....
scarf( `{%d",&no);
printf("Enter the elements of the array....");
fora =0;i<no;i )
scanf("%d",&afil);
printf("tnThe elements of the array ");
for(i=0;i<no;i+ )
pri nt f (" i n%d" ,af i l );
small=a[0] ;
large=af0j;

stisn

Computer Practice

Lab Manual

f o r ( i = 1 ; i< no ; i 4 - )
{

if(afil> large)
large = a/if;
else if(afil < small)
small ----=a111;
printf("InThe largest of the given array is %d",large);
printfrInThe smallest of the given array is %d",small);

I
SAMPLE OUTPUT:
In how many nutnbers you want to nd....5
Enter the elements of the array..
34
56 87 43
The elements of the array
12 34
56 87 43
The largest of the given array is 87
The smallest of the given array is 12

4.

AIM: To write a program to add two matrices.


ALCORITII
Step-1
Step-2

Start the program.


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 matrix,

Step-5

Print the A matrix in the matrix form.

Step-6

Print the 13 matrix in the matrix form.

Step-7
Step-8
Step-9

Set a loop up to the row.


Set a inner loop up to the column.
Add the elements of A and B in column wise and store the
r e su l t i n C ma t r i x .

Step-10 After the execution of the two loops. Print the value of C
matrix.
Step-11 Stop.

Computer Practice I

Lab Manual

for i = 0 to n >

Start )
/Read m, rn, n

/ P ri n t (" \ n " ) !

for i= 0 to In
f o r j = 0 to n >
for j = 0 to n

>

t i l f i l =

4.

/
Read aptly

Print Olin

Read

Stop

7/ FIND THE ADDITION OF IWO MATRIXES


#include<stdio.h>
main()

int a[.51125j,025 #25 ],4251125j,i,f,m,71;


p r i nt f ( "E nt e r t he ro w s a n d c o l um n o f t w o m a t ri x e s i n" ) ;
scanf("%d %d",&m,&n);
p t i nt f ( " i n E nt e r t he e l e m e nt s o f A m a t ri x . . . ") ;
for(i=0;i<m;i )

forGi=0;j<n;j+ 4-)
scanf("%d",&aftV7);
}

p r i nt f ( "InE nt e r t he e l em e nt s o f B m a t ri x. . . ") ;
fortfi=0;i<m;i

for(i=0;j<n;j++)
scanf("%d",&bfiffil);
}

p r intf ("WT he ele ment s o f A m at ri x");


for(i=0;i<m;i

Printirtn ");
for(j=0;j<nd+ +)

Computer Practice I

Lab Manual

printf("terod",afil111);

1
printf("inThe elements of B matrix");
fora= 0;i < nt;i + +)
Printf( " in ");
for(1=- - -04 <n;j+ +)
printf("It%d",bfillip;
}

printf("InThe addition of two matrixes");


fora --=0;i<m;i+ +)
Plinti("kn");
for(P=0;j<n;j++)

+
p ri n t f (" I t %d " ,c fi l 0 7 );

I
SAMPLE OUTPUT:
Enter the rows and column of two matrixes...
Enter the elements of A matrix... 1 2 3 4 5
Enter the elements of B matrix... 1 2 3 4 5
The elements of A matrix
1
2
3
4
5
6
7
8
9
The elements of B matrix
2
3
4
5
6
7
8
9
The addition of two matrixes
2
4
6
8
10
12
14
16
18
5.

3 3
6 7 8 9
6 7 8 9

A I M : T o w r i t e a p r o g r a m t o mu l t i p l y t w o ma t r i x e s .

Step-1
Step-2
Step-3
Step-4
Step-5
Step-6

Start the program


Enter the row and column of the A matrix
Enter the row and column of the B matrix
Enter the elements of the A matrix
Enter the elements of the B matrix
Print the elements of the A matrix in matrix form

Computer Practice I

Lab Manual

Step-7 Print the elements of the B matrix in matrix form


Step-8 Set a loop up to row
Step-9 Set a inner loop up to column
Step-10 Set another inner loop up to column
Step-11 Multiply the A and B matrix and store the element in the C
matrix

S t e p 1 2 P r i n t t h e r e su l t a n t ma t r i x
Step - 13 Stop
-

0 CAA - RT

PROGRAM
/7 MULTPLICATION OF TWO MATRIX
#include<stdio.h>
main()

1
int a12.511251,b12511251,c12511257,ij,k,r,s;
int in, n;
pr i n t f (" i nEn t e r t h e Row s a nd C ol um ns of A mat ri x.. ." );
scan f("%d %d",&m,&n);
printf("inEnter the Rows and Columns of B matrix..." );

Computer Practice I

10

&cant(' %d %d", &r, &&);


ift ( In! =r)
printf("InThe matrix cannot multiplied");
else

1
printf("lnEnter the elements of A matrix");
f o ra = 0 ; i < m; i + )
for(
< nd +)
sconfrIt%d ", &aft JO);
printfrinEnter the elements of B matrix"
for(i= 0;i < In;i
)
for(/' =0,7* <
--F
scont("it%d",&141107);
printf("InThe elements of A matrix"
f o r( i = 0 ;i < m; i 4 )
-

I
printf("In");
for( =0,j <nj )
printf("It%d

El);

prim,
The, elements of B matrix");
for(i = 0;i < m;i
)

I
pri ntf("in");
for( j= 0,] < nj 4 1 .)
p ri n t f (" I t %d " , bf il f fl );
- -

fora =-- 0;i < m;i

I
printf("In ");
for(i =0;:j <

duty = 0;
for(k = 0;k < in;k -i- )

printf("The multiplication of two matrixes ");


fora = 0; i < ;i+ ---)
I printif

Lab Manual

Computer Practice I

11

Lab Manual

for(j=0;j <17
-F-)
printf("lt%d",cfilfil);

I
SAMPLE INPUT AND OUTPUT
Enter the Rows and Columns of A matrix... 3
Enter the Rows and Columns of B matrix... 3
Enter the elements of A matrix 1 2 3 4 5 6
Enter the elements of B matrix 1 2 3 4 5 6
The elements of A matrix
2
3
4
5
6
7
8
9
The elements of B matrix
1
2
3
4
5
6
7
8
9
The multiplication of two matrixes
30
36
42
66
81
96
102
126
150

6.

3
3
7 8 9
7 8 9

AIM: To write a program to find whether the string is palindrome or not.

Step 1

Start the program

Step 2

Enter the string

Step 3
-

Step 4
-

Find the string length using the strlen() function


Print the string length

Step 5

Set a loop up to the half of the string length

Step 6

Compare every character above the middle character with the


below character of the middle character

Step 7

if any character equal prints the given string is palindrome

Step 8

If the character is not equal then print the given string is not
a palindrome

Step-9

Stop

12

Computer Practice I

Lab Manual

Yes
print not a
palindrome

C s t o p

print palindrome/
Yes

Stop )

RAM TO FIND WHETHER THE GIVEN STRING IS P.ALINDROME OR NOT


ffinclude <stdio.h>
#include<stdlib.h>
main()

int len=0,i,j;
char name[251;
printf("Enter the string...");
scanf("%s",name);
while(namellenj! =109
len+ -;
p r i n t f (" I n g o d" , l e n ); f o r ( i = 0 , j = 1en-1;i<lent2;i j- -)

iffnamerill =nameffl)

p r i n t f (" I n T h e g i v e n s t r i ng i s n o t a p a l i nd r o m" );
exit(0);

13

Computer Practice I

Lab Manual

printf("tn The given string is a palindrome");

SM/I PLE OUT PUT


Enter the String . malayalam
9
T h e g i v e n st r i n g i s a p a l i n d r o m e

7.

AIM: To write a program to find the number of consonants and


vow els present in the string.
Itte
Step-1
Step-2
Step-3
Step-4
Step-5
Step-6

Start the program


Enter the string
C o n st r u c t t h e sw i t h st a t e me n t
Print the number of vowels present in the given string
Print the number of consonents present in the given string
Stop
C S ta r t

print v,

ART
read str

Stop

c=c-FI

i=
c a s e ia','AIV'Et,iii, ;o
e111., CY
T,Tte'LP

ssn

Computer Practice I

14

Lab Manual

PROGRAM
//T O F IN D TH E N o . VO WL E S A ND N o . O F CO N SO NA N T S IN A G IVE N S T R IN G

#include<stdio.h>
main()

int v=0,c=-0,i=0;
char str1251;
printf("Enter the string...
scanf("%s",str);
while(strfill =10')

"1.

switch(strfij)

case 'a':
case 'A':
ease 'E.':
case
case V':
case 'II':
case 'e':
case
case V;
case 'a':
v+ +;
break;

default: c+ +;

Ii+ +;

printf("tnThe number of vowels is %d",v);


printf("1nThe number of consonants is %d",c);
getch();

SAMPLE OUTPUT:
Enter the string... RAJA
The number of vowels is 2
The number of consonants is 2