Answer Key for 10th
Answer Key for 10th
Definition of Algorithm
An algorithm is a step-by-step procedure or set of rules to solve a specific problem or perform a
task.
Role of an Algorithm
Alternative Answer
Candid Solutions: A programmer identifies solutions by analyzing the problem requirements,
testing different logic paths, and considering edge cases to ensure robustness.
Importance
• In C, the semicolon marks the end of a statement, allowing the compiler to identify
statement boundaries.
• Compilation errors occur because the compiler cannot parse the code correctly.
Alternative Answer
Two Commonly Used Format Specifiers in C:
1. User-friendly: High-level languages use syntax closer to human language, making them
easier to understand and write.
2. Portability: High-level programs can run on multiple platforms with minimal or no
modifications.
Alternative Answer
Why Java is Ideal for Network Computing:
Example
Alternative Answer
#include <stdio.h>
int main()
{
int num = 10;
if (num > 5)
{
printf("Number is greater than 5");
}
return 0;
By: Waseem Khan FIC Kohat
}
Program:
#include <stdio.h>
int main()
{
for (int i = 1; i <= 10; i++)
{
printf("%d ", i);
}
return 0;
}
Alternative Answer
#include <stdio.h>
int main()
{
int ascii = 65; // ASCII value of 'A'
while (ascii <= 90)
{
printf("%c", ascii);
ascii++;
}
return 0;
}
Compiler Interpreter
Translates entire code into machine
Translates and executes code line-by-line.
code.
Slower as translation and execution happen
Faster execution after compilation.
simultaneously.
By: Waseem Khan FIC Kohat
Alternative Answer
Evaluate Expressions:
1. 9+6×(5+3)=579 + 6 \times (5 + 3) = 57
2. 120/15/5=1.6120 / 15 / 5 = 1.6
Algorithm:
1. Start.
2. Input principal, rate, time.
3. Calculate interest: Interest=Principal×Rate×Time/100\text{Interest} = \text{Principal}
\times \text{Rate} \times \text{Time} / 100.
4. Output the interest.
5. End.
Alternative Answer
• Start → Set num = 50 → Check num <= 100 → Print num if even → Increment
num → Repeat → End.
Program Analysis:
Output:
Alternative Answer
#include <stdio.h>
int main()
{
for (int i = 1; i <= 3; i++)
{
for (int j = 1; j <= 4; j++)
{
printf("%d x %d = %d\t", i, j, i * j);
}
printf("\n");
}
return 0;
}
switch (choice) {
case 1: printf("Option 1"); break;
case 2: printf("Option 2"); break;
default: printf("Invalid option");
}
• Break stops further case execution once the correct case executes.
Alternative Answer
Continue Statement:
Definition
Reserved words are keywords predefined in a programming language that have special
meanings and cannot be used for other purposes, like variable names.
Alternative Answer
Mathematical Functions:
SECTION C
Answer Key for LONG QUESTIONS Q.3, Q.4, Q.5, and Q.6
Q.3
Explanation
The conditional operator (? :) is a shorthand for the if-else statement. It evaluates a
condition and returns one of two expressions based on whether the condition is true or false.
Syntax
Example
#include <stdio.h>
int main()
{
int a = 10, b = 20, max;
max = (a > b) ? a : b;
return 0;
}
Equivalent if-else:
if (a > b)
max = a;
else
max = b;
#include <stdio.h>
int main()
{
float base, height, area;
return 0;
}
Q.4
1. Start.
2. Input the numbers num1 and num2.
3. Calculate the product: product = num1 * num2.
4. Output the product.
5. End.
1. Start.
2. Input the starting and ending numbers of the sequence (start, end).
3. Initialize sum = 0.
4. Loop from start to end:
a. Add the current number to sum.
5. Output the sum.
6. End.
Q.5
Example:
#include <stdio.h>
return 0;
}
#include <stdio.h>
int main()
{
int a = 5, b = 2;
float result;
return 0;
}
Explanation
Q.6
#include <stdio.h>
int main()
{
int sum = 0;
By: Waseem Khan FIC Kohat
for (int i = 1; i <= 10; i++)
{
sum += i * i; // Add square of i to sum
}
printf("Sum of squares: %d", sum);
return 0;
}
#include <stdio.h>
int main()
{
float basicPay, houseRent, netPay;
scanf("%f", &basicPay);
else
houseRent = 0.5 * basicPay;
return 0;
}