Q.1
14 MarksAlso asked in Winter 2023 Q1a
An integer is Even if it is completely divisible by (i.e. remainder is ). If the remainder after division by is , the number is Odd.
Step 1: Start
Step 2: Declare an integer variable N
Step 3: Read / Input the value of N from user
Step 4: If (N % 2 == 0) then:
Print "N is an Even Number"
Else:
Print "N is an Odd Number"
End If
Step 5: StopThe algorithm checks divisibility using the modulus operator %. If N % 2 == 0, the number is Even; otherwise, it is Odd.
- 1) System Software:
System software acts as an interface between the hardware and the user. It manages and controls computer hardware and provides a platform to run applications.
- Examples: Operating Systems (Linux, Windows), Compilers (GCC), Device Drivers.
- 2) Application Software:
Application software is designed to perform specific user-oriented tasks or solve real-world problems. It relies on system software to function.
- Examples: Web Browsers (Chrome), MS Word, VLC Media Player, Calculator.
- 3) Algorithm:
An algorithm is a step-by-step, finite, and unambiguous set of written logical instructions in plain human language (or pseudocode) to solve a given computational problem.
- Characteristics: Finiteness, Definiteness, Input, Output, and Effectiveness.
- 4) Flowchart:
A flowchart is a standardized graphical / pictorial representation of an algorithm using geometric symbols (oval for start/stop, parallelogram for I/O, rectangle for processing, diamond for decisions) connected by flow lines.
| Term | Core Nature | Primary Example |
|---|---|---|
| System Software | Controls hardware | Operating System (Linux) |
| Application Software | End-user task | Word Processor, Browser |
| Algorithm | Textual step instructions | Step-by-step pseudocode |
| Flowchart | Graphical diagram | Geometric symbol diagram |
Explain different type of operators used in c language with their precedence and associativity.
C provides a rich set of operators categorized by their operations:
- Arithmetic:
+,-,*,/,% - Relational:
<,<=,>,>=,==,!= - Logical:
&&(AND),||(OR),!(NOT) - Assignment:
=,+=,-=,*=,/=,%= - Increment / Decrement:
++,--(Prefix & Postfix) - Bitwise:
&,|,^,~,<<,>> - Conditional (Ternary):
? : - Special:
sizeof,,(comma),&(address-of),*(dereference)
Precedence defines which operator evaluates first in an expression. Associativity defines the direction of evaluation when operators have equal precedence.
| Priority | Category | Operators | Associativity |
|---|---|---|---|
| 1 (Highest) | Postfix | (), [], ->, ., ++, -- | Left to Right |
| 2 | Unary | +, -, !, ~, ++, --, *, &, sizeof | Right to Left |
| 3 | Multiplicative | *, /, % | Left to Right |
| 4 | Additive | +, - | Left to Right |
| 5 | Shift | <<, >> | Left to Right |
| 6 | Relational | <, <=, >, >= | Left to Right |
| 7 | Equality | ==, != | Left to Right |
| 8 | Bitwise AND | & | Left to Right |
| 9 | Bitwise XOR | ^ | Left to Right |
| 10 | Bitwise OR | | | Left to Right |
| 11 | Logical AND | && | Left to Right |
| 12 | Logical OR | || | Left to Right |
| 13 | Conditional | ? : | Right to Left |
| 14 | Assignment | =, +=, -=, *=, etc. | Right to Left |
| 15 (Lowest) | Comma | , | Left to Right |
int x = 5 + 3 * 2;
// 1. '*' has higher precedence than '+': 3 * 2 = 6
// 2. '+' is evaluated: 5 + 6 = 11
// Result: x = 11Parentheses () have the highest precedence, while the comma operator , has the lowest. Assignment and unary operators associate from Right to Left, whereas most binary operators associate from Left to Right.