C Programming Questions and Answers: Algorithms, Flowcharts & Core Concepts


Q1. Attempt Any Two Questions (15 Marks)


1. Explain Algorithm and Add Two Numbers

Original question: Explain Algorithm? Write an algorithm to add two numbers.

Answer:
An algorithm is a step-by-step method to solve a problem or perform a specific task.

Algorithm to add two numbers:

  1. Start
  2. Declare variables a, b, and sum
  3. Input two numbers a and b
  4. Compute sum = a + b
  5. Display sum
  6. Stop

2. Flowchart and Symbols; Print Table

Original question: What is Flow Chart? Explain. And draw the Flow Chart to print table.

Answer:
A flowchart is a visual representation of the steps in a process using symbols such as ovals, rectangles, diamonds, and arrows.

Symbols used:

  • Oval → Start/End
  • Rectangle → Process
  • Diamond → Decision
  • Parallelogram → Input/Output

Flowchart to print table of a number:

Start
↓
Read n
↓
i = 1
↓
Print n × i
↓
i = i + 1
↓
i <= 10 ? → Yes → Repeat
No → Stop

3. Linker and Loader; C Program Execution

Original question: What is Linker and Loader? Explain the execution of C program.

Answer:

  • Linker: Combines multiple object files and libraries into a single executable file.
  • Loader: Loads the executable into memory for execution.

Steps in execution of a C program:

  1. Preprocessing: Handles #include, #define, etc.
  2. Compilation: Converts source code to object code.
  3. Linking: Links object files and libraries.
  4. Loading: Loads the program into memory and executes it.

4. Operators: & vs && and == vs =

Original question:
i) Difference between & and &&
ii) Difference between == and =

Answer:

OperatorMeaningExampleResult
&Bitwise AND5 & 31
&&Logical AND(5 > 3 && 3 > 2)True


OperatorMeaningExampleResult
==Comparison5 == 5True
=Assignmenta = 5Assigns 5 to a

Q3. Attempt Any Two Questions (15 Marks)


1. Swap Two Numbers Without Third Variable

Original question: Write a program to swap two inputted numbers without using third variable.

Answer:

#include <stdio.h>
int main() {
    int a, b;
    printf("Enter two numbers: ");
    scanf("%d %d", &a, &b);

    a = a + b;
    b = a - b;
    a = a - b;

    printf("After swapping: a = %d, b = %d", a, b);
    return 0;
}

2. Switch-Case Statement with Example

Original question: What is Switch case? Explain with example.

Answer:
A switch-case is used to execute one block of code among many, based on the value of a variable.

Example:

#include <stdio.h>
int main() {
    int day = 2;
    switch(day) {
        case 1: printf("Monday"); break;
        case 2: printf("Tuesday"); break;
        default: printf("Invalid Day");
    }
    return 0;
}

Output:
Tuesday


3. break, continue, and goto Statements

Original question: What is Break, Continue and Goto statements? Explain with example.

Answer:

  • break: Terminates a loop or switch immediately.
  • continue: Skips the current iteration of a loop.
  • goto: Transfers control to a labeled statement.

Example:

#include <stdio.h>
int main() {
    for(int i = 1; i <= 5; i++) {
        if (i == 3)
            continue;
        printf("%d ", i);
    }
    return 0;
}

Output:
1 2 4 5


4. User-Defined Function: Add Two Numbers

Original question: What is User Defined Function in C? Write a function to add two numbers.

Answer:
A user-defined function (UDF) is created by the programmer to perform a specific task.

Example:

#include <stdio.h>

int add(int x, int y) {
    return x + y;
}

int main() {
    int a, b, sum;
    printf("Enter two numbers: ");
    scanf("%d %d", &a, &b);

    sum = add(a, b);
    printf("Sum = %d", sum);
    return 0;
}

Output:
If a = 4, b = 6 → Sum = 10