Introduction to Programming – Unit I & II
Exam Notes (2 Marks & 10 Marks)
Short Answer Questions (2 Marks)
1. Define Computer.
A computer is an electronic device that accepts data, processes it according to given instructions,
and produces useful information as output. It works on the principle of Input, Process, and Output.
2. What are Data Types in C?
Data types define the type of data a variable can store. Types: - Primary: int, float, char, double -
Derived: array, pointer, structure - User-defined: enum, typedef
3. What is Type Conversion and Casting?
Type Conversion: Automatic conversion from one type to another by compiler. Type Casting:
Manual conversion by programmer using (type). Example: float b = (float)a;
4. What are the parts of CPU?
CPU consists of: 1. ALU – Performs arithmetic and logical operations. 2. CU – Controls program
execution. 3. Registers – Temporary high-speed memory.
5. Define Loop and its types.
A loop is a control structure that repeats a block of code until a condition becomes false. Types: for,
while, do-while.
6. Difference between if and if-else statement.
if – Executes statements only if condition is true. if-else – Executes one block if true and another if
false. Example: if(a>5) printf('A'); else printf('B');
7. Syntax of if-else ladder.
if(cond1) stmt1; else if(cond2) stmt2; else if(cond3) stmt3; else stmt4;
8. Purpose of break statement.
Used to terminate loop or switch statement immediately and transfer control to next statement.
Long Answer Questions (10 Marks)
1. Define a Computer and explain block diagram.
A computer performs Input → Processing → Output operations. Block Diagram: Input Devices →
CPU (ALU + CU + Memory) → Output Devices Explanation: - Input Devices: Keyboard, Mouse -
CPU: Executes instructions - Memory: Stores data - Output: Monitor, Printer
2. Explain Algorithms and Flowcharts with examples.
Algorithm: Step-by-step procedure to solve a problem. Example: To find sum of two numbers: 1.
Start 2. Read a, b 3. sum = a + b 4. Print sum 5. Stop Flowchart: (Start) → [Read a,b] → [sum=a+b]
→ [Print sum] → (Stop)
3. Structure of a C Program.
A C program contains: 1. Preprocessor directives (#include) 2. main() function 3. Variable
declaration 4. Statements 5. Return statement Example: #include int main(){int
a,b;scanf('%d%d',&a;,&b;);printf('%d',a+b);return 0;}
4. C program and flowchart to find biggest among three numbers.
Algorithm: 1. Start 2. Read a,b,c 3. if(a>b && a>c) print a 4. else if(b>a && b>c) print b 5. else print
c 6. Stop Flowchart: (Start) → [Read a,b,c] → {a>b?} → {a>c?} → [Print a] / [Print b or c] Program:
#include int main(){int a,b,c;scanf('%d%d%d',&a;,&b;,&c;);if(a>b && a>c)printf('%d',a);else
if(b>c)printf('%d',b);else printf('%d',c);}
5. Operators – Conditional & Assignment.
Operator: Symbol that performs an operation. Assignment (=): Assigns value. Conditional (?:):
Shorthand for if-else. Example: int a=5,b=10,max; max=(a>b)?a:b; printf('Max=%d',max);
6. Control Structures in C.
Control structures control program execution flow. Types: 1. Sequential – Normal order. 2.
Selection – if, if-else, switch. 3. Iteration – for, while, do-while.
7. Program & Flowchart for Sum of Two Numbers.
Algorithm: 1. Start 2. Read a,b 3. sum=a+b 4. Print sum 5. Stop Flowchart: (Start) → [Read a,b] →
[sum=a+b] → [Print sum] → (Stop) Program: #include int main(){int
a,b;scanf('%d%d',&a;,&b;);printf('Sum=%d',a+b);return 0;}
8. Define Loop and Looping Control Structures.
Loop executes repeatedly until a condition becomes false. Types: 1. for loop 2. while loop 3.
do-while loop Example: for(i=1;i<=10;i++) printf('%d',i);
9. Program to Swap Two Numbers.
Program: #include int main(){int a,b,temp;scanf('%d%d',&a;,&b;);temp=a;a=b;b=temp;printf('After
swap: %d %d',a,b);}
10. Difference between while and do-while (with program).
while – checks condition before loop body. do-while – checks after executing body. Program:
#include int main(){int i=1;while(i<=3){printf('%d',i);i++;}i=1;do{printf('%d',i);i++;}while(i<=3);}
11. Program using switch for arithmetic operations.
#include int main(){int a,b,ch;printf('Enter two numbers:');scanf('%d%d',&a;,&b;);printf('1.Add 2.Sub
3.Mul 4.Div 5.Mod');scanf('%d',&ch;);switch(ch){case 1:printf('Sum=%d',a+b);break;case
2:printf('Sub=%d',a-b);break;case 3:printf('Mul=%d',a*b);break;case
4:printf('Div=%d',a/b);break;case 5:printf('Mod=%d',a%b);break;default:printf('Invalid');}}
12. Program to find Factorial of a Number.
#include int main(){int n,i,f=1;scanf('%d',&n;);for(i=1;i<=n;i++)f=f*i;printf('Factorial=%d',f);return 0;}