/> M3-R4: PROGRAMMIMG & PROBLEM SOLVING THROUGH ‘C’ LANGUAGE JAN 2015

M3-R4: PROGRAMMIMG & PROBLEM SOLVING THROUGH ‘C’ LANGUAGE JAN 2015


M3-R4: PROGRAMMIMG AND PROBLEM SOLVING
THROUGH ‘C’ LANGUAGE JAN 2015

Q.1. Multiple Choice of Answers.


1.1 The two type of file structures existing in VSAM file are
A) Key sequenced structures, entry sequenced structures
B) Key sequenced structure, exit sequenced structures
C) Entry sequenced structures, exit sequenced structures
D) None of the above

1.2 In a multilist organisation
A) records that have an equivalent value for a given secondary index item are linked together to
    form a list
B) records are loaded in ordered sequence defined by collating sequence by content of key
C) records are directly accessed by records key field
D) none of the above

1.3 *ptr ++ is equivalent to
A) ptr++
B) *ptr
C) ++ptr
D) ++*ptr

1.4 Declaration int *(*p) int(*a) is
A) A pointer to function that accept an integer argument and return an integer
B) A pointer to a, which returns an integer
C) A pointer to subroutine which returns an integer
D) None of the above

1.5 The output of following program would be
main()
{ printf(“d%d%d%” sizeof(3.14f), sizeof(3.14l);
}
is
A) 4,8,10
B) 8,4,10
C) 18,8,4
D) None of the above

1.6 An example of hierarchical data structure is
A) array
B) link list
C) tree
D) all of the above

1.7 The do..while looping statement
A) is executed only once if the conditions is true
B) is also known as entry-controlled loop
C) is executed at least once if the conditions is false
D) the unconditional loop

1.8 Which of the following is not a proper storage class in ‘C’?
A) auto
B) dec
C) static
D) extern

1.9 The average number of comparison is sequential search is
A) n**2
B) n(n-1)/2
C) n(n+1)/2
D) (n+1)/2

1.10 Tell whether the following tree is:
[TR] ------2
               /     \
             /         \
          (1)         (2)
A) Heap
B) Full and Complete
C) Heap Complete
D) None of the above



Q.2. TRUE or FALSE.

2.1 A command that lets you change one or more fields in a record is look up.
FALSE

2.2 In relational schema each tuple is divided into fields called relations.
FALSE

2.3 The best average SORTING behavior is shown by merge sort.
FALSE

2.4 The data structure that is needed to convert infix notation to prefix notation is graph.
FALSE

2.5 The best case and worst case time for searching an element using linear search is 1, n.
TRUE

2.6 Forest is a set of N>=0 disjoint trees, which are obtained when root is removed.
TRUE

2.7 PERT graph is a graph used to perform PERT calculation.
TRUE

2.8 Priority queue is a queue that is used to store priority data.
TRUE

2.9 A symmetric diagraph is a directed graph such that for every edge VW there is reverse edge WV.
TRUE

2.10 Maximum degree in any vector in a graph with n vertices is n-1.
TRUE



Q.3. Match words and phrases



SR NO.
X
Y(Ans.)
1
Null pointer is
A pointer which does not point
anywhere
2
Number of operators required in ?: operators
Two
3
Null macros is
A macro that represent null pointer
4
A direct access file is
Files that are stored on a direct access
medium
5
Seek time is
Time taken by read write head
mechanism to position itself over
appropriate cylinder
6
A function that change state object is called
manipulator
7
FORMAT command in DOS is used to establish
Number of tracks and number of
sectors per track
8
Scope of a variable is
The region over which the variable
declaration has effect
9
A self-referential structure is
Contains pointer to itself
10
Size of a pointer in small memory model is
2 bytes


Q.4. Fill in the blank


4.1 An example of volatile memory is _RAM__.

4.2 The __And__ operator is true only when both the operands are true.

4.3 LINUX is an example of __open source software______.

4.4 By default a real number is treated as _DOUBLE_______.

4.5 Header file in which NULL macro is defined is __stdio.h______.

4.6 Memory that can be allocated in a single call to macro is __64 KB______.

4.7 Total number of comparison in bubble sort is _0 (n log n)_______.

4.8 Arranging pack of cards by picking one by one is an example of __insertions sort______.

4.9 All pair shortest path problem can be solved by __Dijkstra’s algorithm______.

4.10 Avoid the use of ___goto_____ statement in the program.

Options.
A. OR
B. 0 (Logn)
C. 32 KB
D. open source software
E. RAM
F. And
G. stdio.h
H. single
I. insertions sort
J. 0 (nlogn)
K. 64 KB
L. Dijkstra’s algorithm
M. goto



     Long Questions

Q.5.
a) A lucas sequence is given below:
   1, 3, 4, 7, 11, 18, 29
   The third number is sum of previous two numbers. Write a program to print first 10 numbers of
   lucas sequence.
Ans:
Lucas numbers: It is similar to Fibonacci numbers, each Lucas number is defined to be the sum of its two immediate previous terms Where as the first two number are 1 and 3.

 Code:


                                Output:


b) Write a program to print the value of numbers in words when number entered is in the range of
   0 to 999.
Ans:
#include<stdio.h>
#include<math.h>

int main() {
  int hundreds = 0;
  int tens = 0;
  int ones = 0;
  int number; //input

  while(1) {
    printf("Enter a number between 0-999 (enter 1000 to exit): ");
    scanf("%d", &number);

    if (number==1000) break;

    hundreds = number / 100;
    tens = (number - (hundreds * 100)) / 10;
    ones = number - (hundreds * 100) - (tens * 10);

    if (hundreds > 0) {
      if      (hundreds == 9) printf("Nine");
      else if (hundreds == 8) printf("Eight");
      else if (hundreds == 7) printf("Seven");
      else if (hundreds == 6) printf("Six");
      else if (hundreds == 5) printf("Five");
      else if (hundreds == 4) printf("Four");
      else if (hundreds == 3) printf("Three");
      else if (hundreds == 2) printf("Two");
      else                    printf("One");

      printf(" Hundred ");
      //if (tens == 0 && ones == 0) printf("\n");
    }

    if (tens != 1) {  // we have a special case (teens)
      if      (tens == 9) printf("Ninety ");
      else if (tens == 8) printf("Eighty ");
      else if (tens == 7) printf("Seventy ");
      else if (tens == 6) printf("Sixty ");
      else if (tens == 5) printf("Fifty ");
      else if (tens == 4) printf("Forty ");
      else if (tens == 3) printf("Thirty ");
      else if (tens == 2) printf("Twenty ");

      if (ones >= 0) {
        if      (ones == 0) printf("Zero\n");
        else if (ones == 9) printf("Nine\n");
        else if (ones == 8) printf("Eight\n");
        else if (ones == 7) printf("Seven\n");
        else if (ones == 6) printf("Six\n");
        else if (ones == 5) printf("Five\n");
        else if (ones == 4) printf("Four\n");
        else if (ones == 3) printf("Three\n");
        else if (ones == 2) printf("Two\n");
        else                printf("One\n");
      } else {
        printf("\n");
      }
    } else {
      if (ones > 0) {
        if      (ones == 9) printf("Nineteen\n");
        else if (ones == 8) printf("Eightteen\n");
        else if (ones == 7) printf("Seventeen\n");
        else if (ones == 6) printf("Sixteen\n");
        else if (ones == 5) printf("Fifteen\n");
        else if (ones == 4) printf("Fourteen\n");
        else if (ones == 3) printf("Thirten\n");
        else if (ones == 2) printf("Twelve\n");
        else                printf("Eleven\n");
      } else {
        printf("Ten\n");
      }
    }
  }

  return 0;
}

Output:

c) With the help of suitable example, explain the functioning of switch statement.
Ans:
switch Statement: जब हम किसी प्रोग्राम में ढेर सारी if Conditions का प्रयोग करते हैं, तो प्रोग्राम बहुत जटिल हो जाता है। इस वजह से प्रोग्राम को समझना व पढना काफी मुशिकल हो जाता है। इस कठिनाई से बचने के लिये हम एक और Control Statement switch का प्रयोग करते हैं। जिस तरह if Condition एक Two – way condition statement है, उसी तरह switch एक Multi-way Condition Statement है। यह बिल्कुल if – else if – else के जैसा ही काम करता है। इसकी सामान्य संरचना निम्नानुसार होती हैः

कार्यप्रणाली – इस संरचना में value1, value2……..value n expression या Variable हैं, जिन्हे case labelकहा जाता है। इनके बाद Colon लगाना जरूरी होता है। ये सभी मान अलग-अलग होने चाहियें। Statement or Statement Block 1, Statement or Statement Block 2, ……… Statement or Statement Block n Statements का समूह है। इन Statements के समूहों में एक से अधिक Statements होने पर भी मंझले कोष्‍ठक की जरूरत नहीं होती है। फिर भी यदि ये कोष्‍ठक लगा दिए जाएं, तो भी C Compiler कोई परेशानी नहीं करता है।
#include <stdio.h>

int main()
{
    char ch;

    /* Input an alphabet from user */
    printf("Enter any alphabet: ");
    scanf("%c", &ch);

    /* Switch value of ch */
    switch(ch)
    {
        case 'a':
            printf("Vowel");
            break;
        case 'e':
            printf("Vowel");
            break;
        case 'i':
            printf("Vowel");
            break;
        case 'o':
            printf("Vowel");
            break;
        case 'u':
            printf("Vowel");
            break;
        case 'A':
            printf("Vowel");
            break;
        case 'E':
            printf("Vowel");
            break;
        case 'I':
            printf("Vowel");
            break;
        case 'O':
            printf("Vowel");
            break;
        case 'U':
            printf("Vowel");
            break;
        default:
            printf("Consonant");
    }

    return 0;
}
(5+5+5)

Q.6.
a) Explain the function performed by following library function of ‘C’:
i) getch
ii) getche
iii) getchar
iv) putchar
v) putch
b) Describe output of following program:
#include<stdio.h>
main()
{ auto int i=10;
{ auto int i=5;
printf(“%d”, i);
}
printf(“%d”, i+s);
printf(“%d”i);
c) Explain the following:
i) static variable
ii) auto variable
iii) register variable
(5+5+5)

Q.7.
a) Explain the difference between logical and bitwise operator.
b) Write a program using pointer to find greatest number in an array.
c) Assuming ip is a pointer; explain the function of following statements:
i) ip = ip + 5;
ii) ip = ip – 10;
iii) ip –
iv) *ip++
v) *ip –
(5+5+5)

Q.8.
a) Assume following code:
int dat = 100;
int *var
var = &dat;
Here dat is an integer variable and var is a pointer. Answer the output of the following
statements, in this regards and explain your answer.
i) printf(“%d”, * var);
ii) printf(“%d”, (* var)++);
iii) printf(“%d”, var);
iv) printf(“%d”, -var);
b) Write a program to find greatest number in an array.
(10+5)

Q.9.
(a) Enumerate the difference between:
i) structures and union
ii) union and enum
b) Explain the difference between text mode and binary mode files.
c) Write a program to copy a file into another file.
(5+5+5)

0/Post a Comment/Comments

Leave a Reply

Previous Post Next Post