What is Karnaugh map and why is it used?

A Karnaugh map (K-map) is a graphical method used to simplify Boolean functions and expressions. It is a two-dimensional grid where each cell represents a combination of input variables and the corresponding output of the Boolean function. By grouping adjacent cells with the same output, the K-map helps identify patterns that can be combined, reducing … Read more

Explain different types of loops (for, while, do-while) with syntax and examples.

for loop: Used when the number of iterations is known beforehand. It consists of three parts: initialization, condition, and update. Syntax: for(initialization; condition; update) { // code to execute } Example: for(int i = 1; i <= 5; i++) { printf(“%d “, i); } Output: 1 2 3 4 5 while loop: Executes as long … Read more

Explain the execution of a for loop with a flowchart and example.

A for loop is a control flow statement that repeatedly executes a block of code a certain number of times based on a condition. It is commonly used when the number of iterations is known beforehand. The basic structure of a for loop is: for(initialization; condition; update) { // code to be executed } Initialization: … Read more

What is an infinite loop? Give an example.

An infinite loop is a loop that never terminates because its condition always evaluates to true, or there’s no exit condition defined. It continues to execute indefinitely until it is manually interrupted or the program is terminated. Example of an infinite loop: while(1) { printf(“This is an infinite loop\n”); } The condition 1 is always … Read more