1 IA Scheme
1 IA Scheme
Characteristics of computers:
1. Speed: Computers can process millions of instructions per second, perform- -7-
ing tasks far faster than humans.
2. Accuracy: Computers provide precise results without errors (unless caused
by hardware or software malfunctions).
3. Automation: Once programmed, computers can perform tasks without hu-
man intervention.
4. Storage: Computers can store vast amounts of data, which can be retrieved
quickly and accurately.
5. Versatility: Computers can perform a wide variety of tasks and adapt to dif-
ferent applications.
6. Diligence: Unlike humans, computers don't tire and can work 24/7 without
loss of performance.
3. A basic C program structure includes the following parts: -6-
1. Preprocessor directives: These are lines of code that are processed before
the actual compilation (e.g., #include).
2. Global declaration section: Variables or functions declared outside of any
function.
3. Main function: Every C program must have a main() function, which is the
entry point of the program.
4. Local declaration section: Variables specific to a function are declared
here.
5. Statements/Expressions: These are the operations that the program will ex-
ecute.
6. Return statement: Ends the program and returns a value to the operating
system.
Example program:
c
Copy -4-
#include <stdio.h>
int main() {
// Local variables
int a, b, sum;
printf("Enter two numbers: ");
scanf("%d %d", &a, &b);
sum = a + b;
printf("Sum: %d\n", sum);
return 0;
}
Answer: -3-
i. Constants: Constants are fixed values that do not change during program
execution.
o Example: const int MAX = 100;
ii. Variables: Variables are identifiers used to store data that can change -3-
during execution.
o Example: int age = 25;
iii. Datatypes: Datatypes define the type of data that a variable can hold.
-4-
o Example:
int: for integers (e.g., 5, -3)
float: for decimal numbers (e.g., 3.14, -2.5)
char: for characters (e.g., 'a', 'Z')
int main() {
int num1, num2, result;
char operator;
switch (operator) {
case '+': result = num1 + num2; break;
case '-': result = num1 - num2; break;
case '*': result = num1 * num2; break;
case '/': result = num1 / num2; break;
default: printf("Invalid operator\n"); return 1;
}
int main() {
int num1, num2, sum;
printf("Enter first number: ");
scanf("%d", &num1);
printf("Enter second number: ");
scanf("%d", &num2);
Algorithm:
1. Start -3-
2. Input two numbers (num1, num2).
3. Add the numbers and store the result in sum.
4. Output the sum.
5. End
Flowchart:
-2-
bash
Copy
Start
|
Input num1, num2
|
sum = num1 + num2
|
Output sum
|
End
Example:
c -5-
Copy
int a = 5, b = 3;
printf("%d", a + b); // Output: 8
==: Equal to
!=: Not equal to
>: Greater than
<: Less than
>=: Greater than or equal to
<=: Less than or equal to
Example:
c
Copy
int a = 5, b = 3;
printf("%d", a > b); // Output: 1 (true)
8 One-Dimensional Array: An array that stores elements of the same type in a sin- -3-
gle row (i.e., a linear list of elements).
C Program:
c
Copy -7-
#include <stdio.h>
int main() {
int n, i;
float sum = 0, average;
return 0;
}
ii. if else: Executes one block of code if the condition is true, and another block
if it is false.
c -5-
Copy
if (a > b) {
printf("a is greater than b");
} else {
printf("b is greater than a");
}
10 i. do-while: A loop that guarantees the body will run at least once before check- -5-
ing the condition.
do {
printf("Hello\n");
} while (condition);
ii. for: A loop used when the number of iterations is known beforehand.
c
Copy
for (int i = 0; i < 5; i++) {
printf("%d\n", i); -5-
}