Sunday, December 6, 2020

ECE FINAL YR TT 2020


 1-D Array:

13.Longest palindrome in an array
14.Non-repeating elements of an array
15.Minimum scalar product of two vectors
16.Check if two arrays are the same or not
17.Sum range of elements in an array
18.Array is a subset of another array or not

2-D Arrays

19.Matrix operations (Addition, subtraction and multiplication)
20.Transpose of a matrix
21.Upper triangular matrix or not
22.The maximum element in a row
23.The maximum element in a column
24.Saddle point coordinates of a given matrix
25.Matrix printing in a spiral form
26.Matrix rotation by 90 degrees clockwise and anticlockwise
27.Maximum binary sum  of matrix row with all 1s in a binary matrix
28.Number of even and odd elements in an array
29Write a program in C to merge two arrays of same size sorted in descending order
30 Write a program in C to insert New value in the array (sorted list ).
31 Write a Program to Find the Sum of Contiguous Subarray within a 1 – D Array of Numbers which has the Largest Sum.
   If we are entering 8 elements (N = 8), with array element values as -1,-5,5,3,-2,5,4 and 1 then,
The largest contiguous subarray is: 5 3 -2 5 4 1
The sum of the largest contiguous subarray is: 16

32 Program to Split an Array from Specified Position & Add First Part to the End.
33 Program to identify missing Number in a given Array
34   Program to Segregate 0s on Left Side & 1s on right side of the Array
35 Program to Find 2 Elements in the Array such that Difference between them is Largest
36 Program to Find the two Elements such that their Sum is Closest to Zero
37  Program to Find if a given Integer X appears more than N/2 times in a Sorted Array of N Integers
38 Program to Find Ceiling & Floor of X given a Sorted Array & a value X
STRINGS
39.program that reads a string and find the frequency of character for case insensitive.
40.program to remove special character in the given string.
41.program to find longest word in the given string.
42.program to reverse each word in the given string.
43.program to find highest frequency character in string.
44.program to replace a substring in a given string.
 45.  Read a string which contains only lowercase alphabets and position. Find the character at given position and print the number of occurrence of same alphabet preceding the given position.
Sample Input:
abacsddaa
9
Sample Output:
3


46.Read an expression and remove parenthesis.
Sample Input
(A*B)+(C/D)-E
Sample Output
A*B+C/D-E

47.Read an expression and count number of valid parenthesis.
Sample Input
((A*B)+(C/D)-E)
Sample Output
3


48.Read an expression and check whether expression contains valid parenthesis or not.
Sample Input1
((A*B)+(C/D)-E)
Sample Output1
Valid
Sample Input2
((A*B)+(C/D-E)
Sample Output2
Invalid

 2-D Array's

49.Write a program to sort set of strings in alphabetical order.

50.Write a program to concatenate set of strings.

51.Write a program that find and print substring in set of strings. If no substring found print ‘NULL’.

52.Write a program to search for a string in set of strings.

53.Write a program that find and print same length strings in array of strings.
















Missing elements in range: 

// Print all elements of range [low, high] that
// are not present in arr[0..n-1]
void printMissing(int arr[], int n, int low,
                  int high)
{
    // Sort the array
    sort(arr, arr + n);
  
    // Do binary search for 'low' in sorted
    // array and find index of first element
    // which either equal to or greater than
    // low.
    int* ptr = lower_bound(arr, arr + n, low);
    int index = ptr - arr;
  
    // Start from the found index and linearly
    // search every range element x after this
    // index in arr[]
    int i = index, x = low;
    while (i < n && x <= high) {
        // If x doesn't math with current element
        // print it
        if (arr[i] != x)
            cout << x << " ";
  
        // If x matches, move to next element in arr[]
        else
            i++;
  
        // Move to next element in range [low, high]
        x++;
    }
  
    // Print range elements thar are greater than the
    // last element of sorted array.
    while (x <= high)
        cout << x++ << " ";
}
  
// Driver program
int main()
{
    int arr[] = { 1, 3, 5, 4 };
    int n = sizeof(arr) / sizeof(arr[0]);
    int low = 1, high = 10;
    printMissing(arr, n, low, high);
    return 0;
}


31 solution:
  1. int main()
  2. {
  3.     int size,m=0,l=0;
  4.  
  5.     printf("Type the length of the array\n");
  6.     scanf("%d",&size);
  7.     int array[size];
  8.     printf("type the elements of the array\n");
  9.  
  10.     for(int i=0;i<size;i++)
  11.     {
  12.         scanf("%d",&array[i]);
  13.  
  14.     }
  15.      int largest=array[0];
  16.     for(int i=0;i<size;i++)
  17.     {
  18.         int sum=0;
  19.         for(int j=i;j<size;j++)
  20.         {
  21.             sum=sum+array[j];
  22.             if(sum>largest)
  23.             {
  24.                 m=i;l=j;
  25.                 largest=sum;
  26.             }
  27.         }
  28.     }
  29.      printf("\n The largest contigous subarray is");
  30.     for(int z=m;z<=l;z++)
  31.     {
  32.         printf(" %d ",array[z]);
  33.     }
  34.     printf("\n The sum of the largest contigous subarray is");
  35.     printf(" %d",largest);
  36.     return 0;
  37. }

Program to identify missing Number in a given Array solution

/* getMissingNo takes array and size of array as arguments*/
int getMissingNo(int a[], int n)
{
    int i, total;
    total = (n + 1) * (n + 2) / 2;
    for (i = 0; i < n; i++)
        total -= a[i];
    return total;
}
 
/*program to test above function */
int main()
{
    int a[] = { 1, 2, 4, 5, 6 };
    int miss = getMissingNo(a, 5);
    printf("%d", miss);
    getchar();
}
















No comments:

Post a Comment