Showing posts with label University Exam Papers. Show all posts
Showing posts with label University Exam Papers. Show all posts

BCS201 PROGRAMMING FOR PROBLEM SOLVING THEORY EXAMINATION 2023-24 Solution

 Section A

 attempt all questions in brief.

a. 1Nibble =………..Bytes. 

Answer:
1 Nibble = 0.5 Bytes

Explanation: 1 Nibble = 4 bits; 1 Byte = 8 bits → 4/8 = 0.5 Bytes


b. Find the value of variable max in the following code: -

 int a=10, b=20; int max= (a>b)? a: b;  

Answer:
max = 20

Explanation: Since a = 10 and b = 20, the condition (a > b) is false. So the ternary operator returns b.


c. Define Explicit type conversion with suitable example. 

Answer:
Explicit type conversion, also known as type casting, is when a programmer manually converts one data type into another.

Example:

float x = 5.75;

int y = (int)x;  // Explicitly converting float to int

Here, (int)x converts 5.75 to 5 by truncating the decimal part.

d. Write a C program to print all natural numbers from 10 to 100. 

Answer: 

#include <stdio.h>

int main() {

    int i;

    for(i = 10; i <= 100; i++) {

        printf("%d ", i);

    }

    return 0;

}

This program uses a for loop to print natural numbers from 10 to 100.


e. Define Pointer to Pointer.  

Answer:
A Pointer to Pointer is a variable that stores the address of another pointer.

Syntax Example:

int a = 5;

int *p = &a;

int **pp = &p;

Here, pp is a pointer to the pointer p, which in turn points to variable a.

f. Find the output of following code: - 

#include<stdio.h>

 #defien a 2*2+2 

void main () { 

int b,c; b=2/a; 

c=b+4;

printf(“Value of variable b and c are %d%d respectively ”, b,c); 

Answer:
There are two issues:

  1. Typo: #defien should be #define.

  2. Macro expansion issue due to missing parentheses.

Corrected Code:

#include<stdio.h> #define a (2*2+2) // a becomes (2*2+2) = 6 void main() { int b, c; b = 2 / a; // 2 / 6 = 0 c = b + 4; // 0 + 4 = 4 printf("Value of variable b and c are %d%d respectively", b, c); }

Output:Value of variable b and c are 04 respectively.

g. Draw block diagram to represent doubly linked list.

Answer:


Each node in a doubly linked list contains:

  • A pointer to the previous node

  • The data

  • A pointer to the next node

Explanation:

  • The first node’s prev points to NULL.

  • The last node’s next points to NULL.

  • Every node is bidirectionally linked.

-------------------------------------------------------------------------------------------------------------------