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:
- Start
- Declare variables
a,b, andsum - Input two numbers
aandb - Compute
sum = a + b - Display
sum - 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:
- Preprocessing: Handles
#include,#define, etc. - Compilation: Converts source code to object code.
- Linking: Links object files and libraries.
- 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:
| Operator | Meaning | Example | Result |
|---|---|---|---|
& | Bitwise AND | 5 & 3 | 1 |
&& | Logical AND | (5 > 3 && 3 > 2) | True |
| Operator | Meaning | Example | Result |
|---|---|---|---|
== | Comparison | 5 == 5 | True |
= | Assignment | a = 5 | Assigns 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
