Search for notes by fellow students, in your own course and all over the country.

Browse our notes for titles which look like what you need, you can preview any of the notes via a sample of the contents. After you're happy these are the notes you're after simply pop them into your shopping cart.

My Basket

You have nothing in your shopping cart yet.

Title: Design and Analysis of Algorithms LAB programs Part 1
Description: Q1. Write a C program that will read an array of elements and display the following: i> Duplicate elements present in the array with their frequency ii> The duplicate element with highest frequency of occurrence Example : Input: 1 2 1 3 4 3 4 3 Output: 1 is duplicate with 2 frequency 3 having the highest frequency Q 2. Write a C program that will read an array arr of elements in sorted manner and display the elements at i,j,k index such that arr[i] + arr[j] + arr[k] = key, where key element is given as input. Q 3. Write a C program that will generate random numbers within a value and store the values in an array. Display the second maximum in the array as output. Input: 12, 3, 27, 9,6 Output: 12 Q4. Write a C program WAP that will produce random numbers in any range and store it in a matrix. Convert it to a tri-diagonal matrix and display the new matrix as output. 00 01 02 03 10 11 12 13 20 21 22 23 30 31 32 33 Convert remaining elements as non zero and other elements as zero. Q 5. Write a C program that will read an array consist of positive and negative numbers. Rearrange the numbers in such a way that all positive numbers will be separated from all negative numbers and display it as output. Input : 1,-2,-4,3,6,-9,2 Output: -2,-4,-9,1,3,6,2

Document Preview

Extracts from the notes are below, to see the PDF you'll receive please use the links above


LAB 1 program1
Q1
...
h>
#include ...
h>
int main() {

}

srand(time(0));
int arr[10],max=0,index;
printf("The array elements entered using srand function \n");
for(int i=0;i<10;i++)
{
arr[i] = i + rand()%10;
printf("%d ",arr[i]);
}
int hash[100]={0};
for(int i=0;i<10;i++)
{
hash[arr[i]]++;
}
for(int i=0;i<100;i++)
{
if(hash[i]>1)
printf("\n %d is duplicate with %d frequency",i, hash[i]);
if(hash[i]>max)
{
max=hash[i];
index=i;
}
}
printf("\n%d has highest frequency",index);
return 0;

Output:
The array elements entered using srand function
9 5 4 9 8 13 9 9 8 11
8 is duplicate with 2 frequency
9 is duplicate with 4 frequency
9 has highest frequency

LAB 1 program2
Q 2
...

#include ...
h>
#include ...

enter the size of the array: 10
enter the elements of the sorted array: 2 3 4 5 6 7 8 9 10 11
enter the keysum: 10
the coordinates are:
0
1
3
2
...
Write a C program that will generate random numbers
within a value and store the values in an array
...

Sample :
Input: 12, 3, 27, 9,6
Sample:
Output: 12
Solution:
#include ...
h>
#include ...
Write a C program WAP that will produce random
numbers in any range and store it in a matrix
...

00 01 02 03
10 11 12 13
20 21 22 23
30 31 32 33
Convert remaining elements as non zero

and other elements as zero
...
h>
#include ...
h>
int i =0, j=0;
int main(){
srand(time(0));
int arr[5][5]={0};
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
if(i==j || i-j == 1 || j-i == 1)
arr[i][j] = 1+rand()%25;
else
arr[i][j] = 0;
}
}
printf("The Elements in the matrix is:\n ");
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
printf("\t%d", arr[i][j]);
}
printf("\n");
}

}

Output:
The Elements in the matrix is:
18 2
0
0
0
24 9
8
0
0
0
13 8
18 0
0
0
17 2
4
0
0
0
25 23
LAB 1 Program 5:
Q5
...

Rearrange the numbers in such a way that all positive numbers will be separated from
all negative numbers and display it as output
...
h>
#include
Title: Design and Analysis of Algorithms LAB programs Part 1
Description: Q1. Write a C program that will read an array of elements and display the following: i> Duplicate elements present in the array with their frequency ii> The duplicate element with highest frequency of occurrence Example : Input: 1 2 1 3 4 3 4 3 Output: 1 is duplicate with 2 frequency 3 having the highest frequency Q 2. Write a C program that will read an array arr of elements in sorted manner and display the elements at i,j,k index such that arr[i] + arr[j] + arr[k] = key, where key element is given as input. Q 3. Write a C program that will generate random numbers within a value and store the values in an array. Display the second maximum in the array as output. Input: 12, 3, 27, 9,6 Output: 12 Q4. Write a C program WAP that will produce random numbers in any range and store it in a matrix. Convert it to a tri-diagonal matrix and display the new matrix as output. 00 01 02 03 10 11 12 13 20 21 22 23 30 31 32 33 Convert remaining elements as non zero and other elements as zero. Q 5. Write a C program that will read an array consist of positive and negative numbers. Rearrange the numbers in such a way that all positive numbers will be separated from all negative numbers and display it as output. Input : 1,-2,-4,3,6,-9,2 Output: -2,-4,-9,1,3,6,2