Pba Solution (10TH)
Pba Solution (10TH)
Q1(i)
#include <stdio.h>
int main() {
int num, I;
Scanf(“%d”, &num);
Return 0;
Explanation:
In each iteration, it multiplies the given number by the current loop index and prints the
result.
ii) To convert the multiplication table program into a do-while loop, here’s how it would
look:
#include <stdio.h>
Int main() {
Int num, I = 1;
Scanf(“%d”, &num);
Do {
I++;
Return 0;
}
Explanation:
The do-while loop ensures that the multiplication table prints at least once, even if I is
initialized to a different value.
Multiplication table of 5:
5x1=5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
5 x 6 = 30
5 x 7 = 35
5 x 8 = 40
5 x 9 = 45
5 x 10 = 50
This output remains the same as with a for loop because the logic for printing the table is
identical.
Q2 (i)
#include <stdio.h>
Int main() {
Int score = 0;
Int input;
While (1) {
Scanf(“%d”, &input);
If (input == 1) {
} else if (input == 2) {
} else if (input == 0) {
} else {
Continue;
}
Printf(“Updated score: %d\n”, score);
Return 0;
Explanation:
3. After each valid input, the program displays the updated score.
4. The program exits when the user enters 0, and it displays the final score.
Q2(ii)
The original code contains several syntax issues. Here’s the corrected version:
#include <stdio.h>
Int main() {
Int day;
Printf(“Enter a number (1-7) to display the day of the week: “);
Scanf(“%d”, &day);
Switch(day) {
Case 1:
Printf(“Monday\n”);
Break;
Case 2:
Printf(“Tuesday\n”);
Break;
Case 3:
Printf(“Wednesday\n”);
Break;
Case 4:
Printf(“Thursday\n”);
Break;
Case 5:
Printf(“Friday\n”);
Break;
Case 6:
Printf(“Saturday\n”);
Break;
Case 7:
Printf(“Sunday\n”);
Break;
Default:
Printf(“Invalid input\n”);
}
Return 0;
}
To allow the program to accept lowercase letters for days, such as ‘m’ for Monday,
we would need to change the input type to accept characters and then match those
characters. However, given the current structure (numeric input for days), this part
doesn’t apply directly unless we change the entire structure of the program.
If the intention is to accept characters instead, you could rework the code to use
char inputs and map ‘m’, ‘t’, etc., to days. Please clarify if this is what is needed.
Output for Part (iii)
If we modify the program to accept lowercase characters and the user enters ‘m’ as
input, the program should display “Monday” as output after making the necessary
changes to handle character inputs.