0% found this document useful (0 votes)
15 views11 pages

PC Viva Q&A (SnapED Codecampus)

Uploaded by

amansd349
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views11 pages

PC Viva Q&A (SnapED Codecampus)

Uploaded by

amansd349
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

calm the mind

VIVA Q&A
B.TECH CSE
1st SEM

SnapED
COMMUNITY

Programming In C

mindset first,
action second
"Empowering Learners, One
Click at a Time"
At SnapED codeCampus, we believe in accessible, affordable, and high-quality education for all. SnapED
will help you become industry-ready with skill-boosting courses and guides, including DSA with Java and
C++, Web Development, Python, Machine Learning, and more. Dive into expertly curated resources,
prepare smarter with important notes and questions, and achieve your academic goals seamlessly.

Explore more at SnapED codeCampus:

- Notes

- Important Questions

- Previous Year Questions (PYQs)

- Video Lectures

- Viva Ques

- skill-boosting courses and guides.

Stay Connected with Us:

YouTube: SnapED codeCampus

LinkedIn: SnapED codeCampus

WhatsApp Community:

1st Community

2nd Community

”Your success
story begins here.”
Viva Ques Programming In C

General Questions

1. What is a variable in C?

A variable is a storage location in memory with a specific name and type that holds
data.

Example: `int num = 10;`

2. What is a data type?

Data types specify the type of data a variable can hold, such as `int`, `float`, `char`,
etc.

3. What is the purpose of the `return` statement?


The `return` statement is used to return a value from a function to the calling function.

4. What is recursion?

Recursion is when a function calls itself to solve smaller instances of a problem until a
base condition is met.

Example: Calculating factorial using recursion.

Questions Related to Programs

1. What is the logic for finding the factorial of a number?

Factorial is calculated by multiplying all integers from 1 to the given number.

Formula: `n! = n × (n-1) × (n-2) … × 1`

2. How do you check whether a number is even or odd?


By checking the remainder when divided by 2.
Logic: If `number % 2 == 0`, it is even; otherwise, it is odd.

3. What is an A.P. series? How do you calculate its sum?

An Arithmetic Progression (A.P.) series has a constant difference between consecutive


terms.

Formula for sum of first n terms: `S = n/2 × (2a + (n-1)d)`

4. What is a G.P. series? How do you calculate its sum?

A Geometric Progression (G.P.) series has a constant ratio between consecutive


terms.

Formula for sum of first n terms:

- If `r != 1`: `S = a × (1 – r^n) / (1 – r)`

- If `r = 1`: `S = n × a`

5. What is the difference between a `for` loop, `do while` loop and a `while` loop?

- `for` loop is used when the number of iterations is known.

- `while` loop is used when the number of iterations is uncertain.

5. What is the logic for printing the Fibonacci series?

The Fibonacci series is a sequence where each term is the sum of the previous two
terms.

Formula: `F(n) = F(n-1) + F(n-2)`

7. What are upper and lower triangular matrices?

- Upper Triangular Matrix: All elements below the main diagonal are zero.

- Lower Triangular Matrix: All elements above the main diagonal are zero.

8. How do you swap two numbers without using a third variable?


By using arithmetic operations:

A = a + b;

B = a – b;

A = a – b;

9. What is the difference between a pointer and an array?


- A pointer is a variable that stores the memory address of another variable.

- An array is a collection of elements of the same data type stored in contiguous


memory.

String Handling Questions

1. **How do you find the length of a string without using library functions?**

By traversing the string and counting the number of characters until the null terminator
(`\0`).

2. How do you concatenate two strings?

By appending the characters of the second string to the first string until the null
terminator is reached.

3. What is the logic for reversing a string?

Swap the first character with the last, the second with the second last, and so on until
the middle of the string is reached.

Matrix and Recursive Programming Questions

1. What is the transpose of a matrix?


The transpose of a matrix is obtained by interchanging its rows and columns.

2. What is the Tower of Hanoi problem?

It is a problem where disks are moved from one rod to another, following these rules:

- Only one disk can be moved at a time.

- A disk can only be placed on a larger disk.

3. What is the base condition in recursion?


It is the condition that stops further recursive calls and returns a result directly.

4. How do you perform matrix multiplication?

Multiply the rows of the first matrix by the columns of the second matrix and sum the
products.

Conceptual Viva Questions

1. What is the difference between a `break` and a `continue` statement?**

- `break` exits the loop completely.

- `continue` skips the current iteration and moves to the next iteration.

2. What are header files?

Header files in C contain declarations of functions and macros.


Example: `#include<stdio.h>`

4. What is a switch-case?

It is a multi-branch statement used for decision-making based on the value of an


expression.
4. What is the difference between a compiler and an interpreter?

- A compiler translates the entire program into machine code before execution.

- An interpreter translates and executes the program line by line.

5. What are the differences between call by value and call by reference?

- Call by Value: A copy of the variable is passed to the function.

- Call by Reference: The actual address of the variable is passed to the function.

EXPERIMENT WISE QUESTIONS:

1. Factorial of a Number

- Q: What is a factorial?

A: The factorial of a non-negative integer \(n\) is the product of all positive integers
less than or equal to \(n\) (\(n! = n \times (n-1) \times … \times 1\)).

- Q: What is the factorial of 0?

A: The factorial of 0 is 1.

- Q: Can we find the factorial of a negative number?


A: No, factorials are not defined for negative numbers.

2. Divisors of a Number
- Q: How do you find the divisors of a number?

A: A divisor of a number \(n\) is any integer \(i\) such that \(n \% I == 0\).

- Q: What is the time complexity of finding divisors of a number?

A: \(O(\sqrt{n})\) if we only check up to \(\sqrt{n}\).


3. Print the Table of a Number

- Q: What loop is typically used to print a multiplication table?

A: A `for` loop is typically used for fixed iterations.

- Q: How would you handle invalid input (e.g., non-numeric values)?

A: Input validation can be done using conditional statements or error handling.

4 & 5. Sum of A.P. Series Using Formula and Loop**

- Q: What is the formula to calculate the sum of an A.P. series?

A: \(S = \frac{n}{2}(2a + (n-1)d)\), where \(a\) is the first term, \(d\) is the common
difference, and \(n\) is the number of terms.

- Q: What is the difference between using a formula and a loop for this?

A:The formula is more efficient, while the loop iteratively adds terms.

6 & 7. Sum of G.P. Series Using Formula and Loop

- Q: What is the formula to calculate the sum of a G.P. series?

A: \(S = a \frac{1-r^n}{1-r}\), where \(a\) is the first term, \(r\) is the common ratio, and
\(n\) is the number of terms.

- Q: Can a G.P. series have \(r = 1\)?


A: Yes, in such cases, all terms are the same, and the sum is \(n \times a\).

8 & 9. Fibonacci Series

- Q: What is the Fibonacci series?


A: It is a sequence where each term is the sum of the two preceding ones (\(F(n) =
F(n-1) + F(n-2)\)), starting with 0 and 1.
- Q: What is the difference between a `for` loop and a `while` loop?

A: A `for` loop is used for a known number of iterations, while a `while` loop runs until
a condition is met.

10. Sum of A.P. and G.P. Using `switch-case`**

- Q: Why use a `switch-case` statement?


A: To simplify code by branching execution based on a variable’s value.

- Q: Can `switch-case` handle ranges?

A: No, it works with discrete values.

11. Even or Odd Using Ternary Operator

- Q: What is a ternary operator?

A: It is a shorthand for `if-else`, written as \(condition ? true\_value : false\_value\).

- Q: How do you determine if a number is even or odd?

A: Check if \(n \% 2 == 0\).

12. Swap Two Numbers

- Q: How can you swap two numbers without using a third variable?

A: Use arithmetic operations like addition and subtraction or bitwise XOR.

13. Right-Justified Stars

- Q: How do you print a right-justified triangle pattern?

A: Use nested loops: outer loop for rows and inner loop for spaces and stars.
14. Tower of Hanoi

- Q: What is the Tower of Hanoi problem?

A: It involves moving \(n\) disks from the source to the destination rod, using an
auxiliary rod, following specific rules.

- Q: What is the time complexity of Tower of Hanoi?


A: \(O(2^n)\).

### 15. **Recursive Fibonacci**

- Q: Why is recursion used in Fibonacci?


A: To define the series naturally, as \(F(n) = F(n-1) + F(n-2)\).

- Q: Is recursion efficient for Fibonacci?

A: No, it has exponential time complexity unless optimized with memoization.

16. Recursive Factorial


- Q:How does recursion work for factorial?

A: The function calls itself with \(n-1\) until \(n = 1\).

17.Matrix Operations

- Q: How do you add two matrices?

A: Add corresponding elements: \(C[i][j] = A[i][j] + B[i][j]\).

- Q: What is a triangular matrix?

A: A matrix is upper triangular if all elements below the main diagonal are zero.
18. String Operations

- Q: How do you find the length of a string without using string functions?

A: Iterate through the array until the null character (`\0`) is reached.

- Q: How can you reverse a string?

A: Swap characters from the start and end, moving towards the middle.

You might also like