PPL ISE 1 - QB ans
PPL ISE 1 - QB ans
NOTE – This PDF is not 100% Accurate , Refer as your Quick Revision
A computer is an electronic device that processes data according to a set of instructions called a program. It
consists of hardware (physical components) and software (programs).
Types of computers:
• Personal Computers (PCs): Desktop and laptop computers used for personal tasks.
• Servers: Powerful computers that provide services to multiple users over a network.
• Supercomputers: High-performance computers used for complex calculations and simulations.
• Mainframes: Large, powerful computers used by organizations for critical tasks.
• Microcontrollers: Small computers embedded in devices like microwaves and cars.
2. What are input devices? Mention and explain any two input devices.
Input devices are hardware components that allow users to enter data into a computer.
Two examples:
Software is a collection of programs and data that tells a computer what to do.
Types of software:
• System Software: Manages the computer's hardware and resources (e.g., operating systems, device
drivers).
• Application Software: Performs specific tasks for users (e.g., word processors, web browsers,
games).
basic computer structure diagram
4. Basic Structure of a Computer
The primary components are:
7. Programming Paradigms
8. Programming Domains
1. Start
2. Input three numbers: num1, num2, num3
3. Calculate sum: sum = num1 + num2 + num3
4. Calculate average: average = sum / 3
5. Print sum and average
6. End
1. Start
2. Input three sides of the triangle: side1, side2, side3
3. Calculate perimeter: perimeter = side1 + side2 + side3
4. Calculate semi-perimeter: s = perimeter / 2
5. Calculate area: area = sqrt(s * (s - side1) * (s - side2) * (s - side3))
6. Print area and perimeter
7. End
12. Algorithm to Find the Largest of 3 Numbers
1. Start
2. Input three numbers: num1, num2, num3
3. If num1 > num2 and num1 > num3
o Print num1 as the largest
4. Else if num2 > num1 and num2 > num3
o Print num2 as the largest
5. Else
o Print num3 as the largest
6. End
• Start/End: Oval
• Process: Rectangle
• Input/Output: Parallelogram
• Decision: Diamond
• Flowline: Arrow
int main() {
float principal, rate, time, interest;
printf("Enter
rate of interest: ");
scanf("%f", &rate);
return 0;
}
1. Preprocessor Directives: These lines begin with # and instruct the preprocessor to modify the
source code before compilation. Common directives include #include to include header files and
#define to define macros.
2. Main Function: This is the entry point of the program. Every C program must have a main()
function.
3. Function Definitions: These are user-defined functions that perform specific tasks.
Example:
C
#include <stdio.h>
int main() {
printf("Hello, world!\n");
return 0;
}
Use code with caution.
13. Tokens in C
Tokens are the smallest individual units of a C program. The main types of tokens are:
• Keywords: Reserved words with special meanings (e.g., int, float, if, else).
• Identifiers: Names given to variables, functions, and other entities (e.g., age, calculateArea).
• Constants: Fixed values that cannot be changed during program execution (e.g., 10, 3.14).
• Operators: Symbols used to perform operations (e.g., +, -, *, /).
• Punctuators: Special characters used to separate different parts of the program (e.g., ;, {}, (), []).
An identifier is a name given to a variable, function, or other entity. It must follow these rules:
• num2: Valid
• $num1: Invalid (starts with a special character)
• +add: Invalid (starts with an operator)
• a_2: Valid
• 199_space: Invalid (starts with a digit)
• _apple: Valid
• #12: Invalid (starts with a special character)
16. Definitions
• Variables: Memory locations used to store data that can change during program execution.
• Constants: Fixed values that cannot be changed during program execution.
• Associativity: The order in which operators of the same precedence are evaluated (left-to-right or
right-to-left).
• Precedence: The priority of operators, determining the order in which they are evaluated.
17. Operators in C
• Arithmetic Operators: +, -, *, /, %
• Relational Operators: ==, !=, <, >, <=, >=
• Logical Operators: &&, ||, !
• Bitwise Operators: &, |, ^, ~, <<, >>
• Assignment Operators: =, +=, -=, *=, /=, %=, &=, |=, ^=, <<=, >>=
• Increment/Decrement Operators: ++, --
• Conditional Operator: ?:
• Comma Operator: ,
• Sizeof Operator: sizeof
C
variable_name = expression;
C
#include <stdio.h>
int main() {
printf("Size of int: %zu bytes\n", sizeof(int));
printf("Size of float: %zu bytes\n", sizeof(float));
printf("Size of double: %zu bytes\n", sizeof(double));
printf("Size of char: %zu byte\n", sizeof(char));
return
0;
}
Example:
C
#include <stdio.h>
int main() {
int age;
printf("Enter your age: ");
scanf("%d", &age);
printf("Your age is %d\n", age);
return 0;
}
C
#include <stdio.h>
#define PI 3.14159
int main() {
float radius, area, perimeter;
printf("Area
of the circle = %.2f sq. units\n", area);
printf("Perimeter of the circle = %.2f units\n", perimeter);
return 0;
}
C
#include <stdio.h>
int main() {
float length, width, area, perimeter;
return 0;
}
C
#include <stdio.h>
int main() {
float principal, rate, time, interest;
return 0;
}
26. C Program to Find the Largest of Three Numbers Using Ternary Operator
C
#include <stdio.h>
int main() {
int num1, num2, num3, largest;
largest = (num1 > num2) ? (num1 > num3 ? num1 : num3) : (num2 > num3 ? num2 :
num3);
return
0;
}
27. C Program to Display the ASCII Value of a Character
C
#include <stdio.h>
int main() {
char ch;
return 0;
28. Algorithm, Flowchart, and C Program to Swap Two Numbers Using a Third Variable
Algorithm:
1. Start
2. Input two numbers: num1, num2
3. Declare a temporary variable: temp
4. Assign num1 to temp: temp = num1
5. Assign num2 to num1: num1 = num2
6. Assign temp to num2: num2 = temp
7. Print the swapped numbers: num1, num2
8. End
Flowchart:
C Program:
C
#include <stdio.h>
int main() {
int num1, num2, temp;
temp = num1;
num1 = num2;
num2 = temp;
return
0;
}
• Local Variables: Declared within a function or block of code. They are only accessible within that
specific scope.
• Global Variables: Declared outside of any function. They are accessible from any part of the
program.
Example:
C
#include <stdio.h>
int main() {
int local_var = 20; // Local variable
return 0;
}
Storage classes determine the scope and lifetime of variables. The main storage classes in C are:
Mixed mode assignment involves assigning a value of one data type to a variable of another data type. The
compiler performs implicit type conversion in many cases. However, it's important to be aware of potential
loss of precision or unexpected behavior.
Example:
C
int x = 10;
float y = 3.14;
33. Differentiations
$b. 10-3%8+6/4$
10−3 10−3+1+1 9
3∗(2∗3+1)/3 3∗7/3 7
C
#include <stdio.h>
#include <stdio.h>
void main() {
int x, a, b, c;
a = 2;
b = 4;
c = 5;
x = a-- + b++ - ++c;
printf("x: %d",x);
getch();
}
$`f. What is the output of the following: #include <stdio.h> #include <stdio.h> int a=30; // global variable
void main() { int b; // local variable
printf("Value of a : %d",a); a=10, b=20; printf("Value of a : %d",a); printf("Value of b : %d",b); getch(); }
This code will produce a compilation error because you are trying to assign a new value to a constant
variable.
c. 17-8/4*2+3- ++a
Assuming a is initially 0:
C
#include <stdio.h>
#include <stdio.h>
void main() {
int x, a, b, c;
a = 2;
b = 4;
c = 5;
x = a-- + b++ - ++c;
printf("x: %d",x);
getch();
}
Output: x: 0
Explanation:
C
#include <stdio.h>
#include <stdio.h>
int a=30; // global variable
void main() {
int b; // local variable
printf("Value of a : %d",a);
a=10, b=20;
printf("Value of a : %d",a);
printf("Value of b : %d",b);
getch();
}
Output:
Value of a : 30
Value of a : 10
Value of b : 20
C
#include <stdio.h>
#include <stdio.h>
void main() {
const int a=10;
printf("%d",a);
a=20;
getch();
}
This code will result in a compilation error because you cannot modify the value of a const variable.