Wednesday 9 December 2015

LBEPS lab@Home 10

1. Write a pseudocode to display the following matrix.

11 15 12
6 9 32 12
34 23 54 78
 9 8 7 5 3
(Duration: 15 Minutes)


Ans


begin
numeric row , col
numeric array [4][4] = {
{11,15,12,6},
{9,32,12,34},
{23,54,78,9},
{8,7,5,3}
}

display "The matrix is:"
for (row=0;row<4;row=row+1)
begin
display newline
for (col=0;col<4;col=col+1)
begin
display array [row][col]
display ''
end
end
end


2.Write a pseudocode to print the element that occurs most frequently in a given array. (Duration: 15 Minutes)



Ans  

begin
numeric arr[]={1,3,4,5,1}
numeric i, counter=0,MostFrequent, val, j, maxfrequency=0

for(i=0;i<5;i=i+1)
begin
counter=0
val=arr[i]
for(j=i+1;j<5;j=j+1)
begin
if(arr[j]==val)
begin
counter=counter+1
end
end
if( counter>maxFrequency)
begin
maxFrequency=counter
Mostfrequent=val
end
end
display "The element that occurs most frequent is"
display Mostfrequent
end



3.Write a pseudocode to find the largest number from the following array: {2,8,4,3,7} (Duration: 10 Minutes)



Ans   begin
numeric array[5]= {2,8,4,3,7}
numeric maximum, size, c, lopcation=1;
maximum=array[0];
for ( c=1;c<5;c++)
begin
if( array[c]>maximum)
begin
maximum=arra[c];
location=c+1;
end
end
display "maximum element is present at location number"
display location
display "The value of the maximum element is"
display maximum
end




4.Write a pseudocode to count the duplicate values in an array of size 10. (Duration: 10 Minutes)



Ans     begin
numeric a[]={1,2,3,4,5,6,6,8,9,9}
numeric count=0
numeric i,k;
for( i=0;i<10,i++)

begin
for (k=i+1;k<10;k++)
begin
if(a[k]==a[i])
begin
display "duplicate element;"
dispaly a[k]
count=count+1
end
end
end
display "The number of duplicate values in the array are"
display count
end



5.Write a pseudocode to find the average of the elements in the following array: {3,4,5,6,7} (Duration: 10 Minutes)




Ans  begin
numeric array[5]={3,4,5,6,7}
numeric sum, average

for(i=0;i<5;i=i+1)
begin
sum=sum+array[i]
end
average=sum/5
display "The average of the elements in the given array is:"
display average
end



6.Write a pseudocode to display the fifth element of an array of size 10. (Duration: 10 Minutes)


Ans  begin
numeric array[10],i

display "Enter the elements of the array"
for(i=0;i<10;i=i+1)
begin
accept array[i]
end

display " The fifth element of the array is:"
display array[4]
end



7.Write a pseudocode to print all the numbers greater than the average of the numbers given in an array of size 10. (Duration: 15 Minutes)



Ans   begin
numeric array[10]
numeric sum, average,i

display "Enter the elements of the array"
for (i=0;i<10;i=i+1)
begin
accept array [i]
end
for (i=0;i<10;i=i+1);
begin
sum=sum+array[i];
end
average=sum/10;
display "The numbers greater than the average of the given array are:"
for (i=0;i<10;i++)
begin
if (array[i]>average)
begin
display array[i]
end
end
end



8.Write a pseudocode to concatenate two arrays containing elements in ascending order to create a new array containing elements in ascending order. (Duration: 15 Minutes)



Ans   begin
numeric x=0, y=0, z=0, i
numeric array1[]={1,2,3,4}
numeric array2[]={5,6,7,8}
numeric concatarray[8]
while(x<=3 && y<=3)
begin
if(array1[x]< array2[y])
begin
concatarray[z]=array1[x];
x=x+1
end
else
begin
concatarray[z]=array2[y],
y=y+1
end
z=z++
end
while(x<4)
begin
concatarray[z]=array1[x]
x++
Z++
end
while(y<4)
begin
concatarray[z]=zrray2[y]
y++
z++
end
display " The concatenated array is:"
for(i=0;i<8;i++)
begin
display concatearray[i]
end
end

No comments:

Post a Comment