Set-1 Automata Fix MCQs
Set-1 Automata Fix MCQs
Automata Fix
Q1. Anita is given a task to find number of digits in a given array .For example
number of digits in 235 is three. She
writes a code in order to get desired result. Point out the Logical error in the
code and also suggest what should be in
A) a[i]/10; a++;
B) a[i]=a[i]/10; a++;
C) a[i] /= 10; ++a;
D) None of these
Q2. The following code is of Single Linked List Whose task is to detect the
loop. Lets list has 5 elements:
2->14->6->18->9, and a loop from 9 to 6.
Finally I have removed the loop and my list look like 2->14->6->18->9, but due
to some Logical error code is still
Q3. Given code of bubble sort there are two Missing codes you need to fill these
Missing and correct the code.
INCORRECT CODE:
int main()
{
int arr[]={10,20,30,40,50},I,j, isSwap;
int n=sizeof(arr)/sizeof(*arr);
isSwap=1;
for(i=0;i<n-1 && Missing-1 ; i++)
{
Missing-2;
for(j=0;j<n-i-1;++j)
{
if(arr[j]>arr[j+1])
{
swap(&arr[j], &arr[j+1])
isSwap=1;
}
}
}
Q4. Find the Errors in the given C function which tries to find out the common
elements in three sorted arrays A,B
and C have p,q, and r elements. Note that arrays are sorted in ascending
1.void common(int A[],int B[],int C[],int p,int q, int r){
2.int i,j,k;
3.for(i=0;i<p;i++){
4. for(j=0;j<q;j++){
5. for(k=0;k<r;k++){
6. if(A[i]==B[j] && B[j]==C[k]){
7. printf("%d",A[i]);
8. i++;
9. j++;
10. K++;}
11. else if(A[i]<B[j])
12. i++;
13. else if(B[j]<C[k])
14. j++;
15. else
16. k++;
17. }
18. }
19. }
20.}
A:Lines 3,4,5,7
B:Lines 4,11,15
C:Lines 4,5,6,7
D:Lines 5,11,13
C function finds the value of X .Identify the erroneous Line/Lines in the code.
A: Line 1, Line 2
B: Line 3, Line 6
C: Line 9, Line 6
D: Line 1, Line 4
Q6. The following C Function Takes a array sorted in ascending order which
was rotated a few times and then find the
first element of the original order. You need to identify the line/lines having
error/errors in the code
Q7. In the given pseudocode of sorting an array ,there are two blank spaces at
Line 6 and 15 , according to you which
option will make this code complete and produce the resultant array in sorted
form . a[]={77,22,44,11,88,33,66,55}
1.sort()
2. Integer a [],i,j=1,k,min,temp,flag;
3. Repeat while(j<=length a[])
4. min =a[j];
5. Repeat for i=j+1 to length a[]
6. if(min__ a[i])
7. min=a[i];
8. k=i;
9. flag=1;
10. End of if loop
11. End of for Loop
12. if(flag==1)
13. swap(a[j] and a[k])
14. j++;
15. -----------
16. end of while loop
17.end of sort()
Q8. In an array, the majority element refers to an element that appears more
than half of the array's size. In other
words, if an array has N elements, the majority element occurs more than N/2
times. A majority element may not
A. Line1, Line4
B. Line4, Line5
C. Line5
D. Line8.
Q9. Given an array A of n positive numbers. The task is to find the first
Equilibrium Point in an array.
An equilibrium point in an array is a position at which the sum of elements on
the left side of the point is equal to
the sum of elements on the right side. In other words, it is a position where the
array can be split into two parts,
and the sum of elements on both sides is the same.
Ex: n = 5
A[] = {1,3,5,2,2}
A[0]+A[1] = A[3]+A[4] = 4 so element at index 2 is equilibrium point and
Ans is 2.
1.int equilibriumPoint(long long a[], int n) {
2. int s=0,ls=0;
3. for(int i=0;i<n;i++)
4. s+=a[i];
5. for(int i=0;i<n;i++){
6. s-=a[i];
7. if(ls==s){
8. return i+1;
9. ls+=a[i];
10. }//end if
11. }//end for
12. return -1;
13. }
A. Line8, Line9
B. Line4, Line5
C. Line5, line8
D. Line8
Q 10. Given a function binarySearch() where few lines are not correct and
produce incorrect results, you need to
A: Line 9 and 10
B: Line 5
C: Line 3
D: Line 12
Q11.Raj wants to write a clever program which takes a string input from the
user prints both the input string and its
length.
1.#include<stdio.h>
2.int main(){
3. int n;
4. char string[20];
5. scanf("%s", string);
6. printf("%c",printf("%s",string));
7. return 0;
8 }
Choose all Logical Errors from list below that may apply to program
A: The format specifier used is wrong
B: The string does not accept space characters
C: Extra variable n is used
D: May exceed storage allocated
Q12. The Program below tries to find the second most frequent character
.Identify the errors in program below.
1.#include<stdio.h>
2. int main(){
3. chr str[100]=="okay fine Hello";
4. int i, word;
5. i=0;
6. word=1;
7. while(str[i]!='\0'){
8. if(str[i]==''){
9. word++;
10. i++;
11. }
12. }
13. printf("words: %d\n",word);
14.}
Note: Choose All the Logical Errors from list below that may apply to program
A: Line 8
B: Line 9
C: Line 10
D: No error
Q14. A person wants to Print the individual character of the given input string
separated by space .Identify the
1.#include<stdio.h>
2. int main(){
3. char str[100];
4. int len=0;
5. printf("Input the string :");
6. scanf("%c",str);
7. for(int i=0;str[i]!='\0';i++)
8. len++;
9. printf("String characters in reverse order:");
10. for(str[len]='\0'; len<=0; len++)
11. printf("%c",str[len]);
12. return 0;
13.}
A. Line 7, Line 10
B. Line 6 ,Line 7
C. Line 6, Line 10
D. Line 6, Line 7, Line 10
Q15. Below is the code to check whether the input strings are equal or not . Find
the Problem in the Given Code.
1. int main(){
2. char s1[100],s2[100],*str1,*str2;
3. int flag=0,i=0;
4. printf("Input two Strings :");
5. scanf("%[^\n]*%c %[^\n]%c*c",s1,s2);// Enter the String which may have
space
6. str1 = s1; str2=s2;
7. while(*str1==*str2);{
8. if(*str1=='\0' || *str2=='\0')
9. break;
10. str1++,str2++;}
11. if(*str1=='\0' || *str2=='\0')
12. printf("\n Both Strings are equal");
13. else
14. printf("\nBoth Strings are Not Equal");
15. return 0;
A. Line 7 ,Line 10
B. Line 11, Line 7
C. Line 11, Line 10
D. No Error
A: Line 5
B: Line 6
C: Line 7
D: Line 8
A. Line 3, Line 4
B. Line 3, Line 6
C. Line 4, Line 6
D. Line 3, Line 5, Line 6
Q18. The given function wants to print the sum of all the elements of the array
but there are some logical errors in the
Q19. A peak element is an element that is strictly greater than its neighbors.
on a given 0-indexed integer array, the following code tries to find a peak
element, and return its index.
The peakElement() takes array and number of elements in the array as input
parameter and returns the index
of peak element.
Find out the erroneous lines of code.
A: Line 4
B: Line 6
C: Line 8
D: no error
Q20. Anita is given a task to find the number of digits in a given array . For
example, the number of digits in 235 is
three. She writes a code in order to get desired result.point out the logical error
in the code and also suggest what
1. Int main(void)
2. int arr[5]={120,76,85,45,56},i,a=0;
3. for(i=0;i<5;i++){
4. a=0;
5. while(arr[i]/10>=0)
6. a++;
7. MISSING CODE
8. printf("%d",++a);
9. return 0;}
A. 5, arr[i]=arr[i]/10;
B. 8, arr[i]=arr[i]/10;
C. 5, arr[i]=arr[i]%10;
D. 8, arr[i]=arr[i]%5;