SPC CAT-1: 11 Extra Questions (Additional Syllabus Coverage)
Coverage: 11 additional questions filling syllabus gaps: compound/unary operators, escape sequences, constants, prototypes, bitwise manipulation, and string copying.
← Back to Mocks Overview
These 4 problems cover the remaining coding concepts that were not directly exercised by the 15 mock questions.
Add-On 1 — Compound Assignment + Unary Operators
Read two integers $x$ and $b$ ($b \neq 0$). Apply the following sequence of compound assignment operations to $x$ using $b$ as the operand:
- Add $b$ (
+=) - Subtract $b$ (
-=) - Multiply by $b$ (
*=) - Divide by $b$ (
/=) - Modulo by $b$ (
%=) - Negate $x$ using unary minus
Print the final value of $x$.
Input
10 3
Output
-1
Another Input
0 5
Output
0
Another Input
-5 2
Output
1
Another Input
100 7
Output
-2
View Solution
#include <stdio.h>
int main()
{
int x, b;
scanf("%d %d", &x, &b);
x += b;
x -= b;
x *= b;
x /= b;
x %= b;
x = -x;
printf("%d\n", x);
return 0;
}
Add-On 2 — Escape Sequences + Formatted Output
Read a student's name initial (char) and marks (int). Output the record formatted with tab characters after each colon label, followed by the confirmation line "Result Recorded" enclosed within literal quotation marks.
Input
A 78
Output
Student: A
Marks: 78
"Result Recorded"
Another Input
B 10
Output
Student: B
Marks: 10
"Result Recorded"
Another Input
Z 100
Output
Student: Z
Marks: 100
"Result Recorded"
Another Input
X 0
Output
Student: X
Marks: 0
"Result Recorded"
View Solution
#include <stdio.h>
int main()
{
char initial;
int marks;
scanf(" %c %d", &initial, &marks);
printf("Student:\t%c\n", initial);
printf("Marks:\t%d\n", marks);
printf("\"Result Recorded\"\n");
return 0;
}
Add-On 3 — Constants + Data Types + Basic C Structure
Read the radius of a circle as a floating-point number. Using $\pi = 3.14159$, compute the Area ($\pi r^2$) and Circumference ($2\pi r$) of the circle. Display both values formatted to 2 decimal places.
Another Input
0
Output
Area: 0.00
Circumference: 0.00
Another Input
3.14159
Output
Area: 31.01
Circumference: 19.74
Another Input
-100
Output
Area: 31415.90
Circumference: -628.32
Input
5
Output
Area: 78.54
Circumference: 31.42
View Solution
#include <stdio.h>
int main()
{
const double PI = 3.14159;
double radius;
double area;
double circumference;
scanf("%lf", &radius);
area = PI * radius * radius;
circumference = 2 * PI * radius;
printf("Area: %.2f\n", area);
printf("Circumference: %.2f\n", circumference);
return 0;
}
Add-On 4 — Function Prototype + Modular Programming
Organize a modular program structure with function prototypes declared before main() and full definitions placed after main():
float calculatePercentage(int obtained, int total): Returns percentage scorechar calculateGrade(float percentage): Returns letter grade (Afor $\ge 90$,Bfor $\ge 75$,Cfor $\ge 60$,Dfor $\ge 40$,Fotherwise)
In main(), read the marks obtained and total marks, compute the percentage and grade using the modular functions, and print each result on a separate line.
Input
47 60
Output
78.33
B
Another Input
0 100
Output
0.00
F
Another Input
-5 51
Output
-9.80
F
Another Input
10 51
Output
19.61
F
View Solution
#include <stdio.h>
float calculatePercentage(int obtained, int total);
char calculateGrade(float percentage);
int main()
{
int obtained, total;
float percentage;
char grade;
scanf("%d %d", &obtained, &total);
percentage =
calculatePercentage(obtained, total);
grade = calculateGrade(percentage);
printf("%.2f\n", percentage);
printf("%c\n", grade);
return 0;
}
float calculatePercentage(int obtained, int total)
{
return (float)obtained / total * 100.0;
}
char calculateGrade(float percentage)
{
return percentage >= 90 ? 'A' :
percentage >= 75 ? 'B' :
percentage >= 60 ? 'C' :
percentage >= 40 ? 'D' :
'F';
}
Add-On 5 — Operator Precedence + Associativity
Read three integers $a$, $b$, and $c$. Evaluate and print the results of the following three arithmetic expressions using standard C operator precedence and left-to-right associativity:
- $r_1 = a + b \times c$
- $r_2 = (a + b) \times c$
- $r_3 = a / b \times c$ (using integer division)
Print $r_1$, $r_2$, and $r_3$ separated by spaces on a single line.
Input
10 5 2
Output
20 30 4
Another Input
0 5 2
Output
10 10 0
Another Input
1 1 1
Output
2 2 1
Another Input
-5 10 -2
Output
-25 -10 0
View Solution
#include <stdio.h>
int main()
{
int a, b, c;
int r1, r2, r3;
scanf("%d %d %d", &a, &b, &c);
r1 = a + b * c;
r2 = (a + b) * c;
r3 = a / b * c;
printf("%d %d %d\n", r1, r2, r3);
return 0;
}
Add-On 6 — Wallet Transaction Validator
Process a digital wallet transaction given the current wallet balance and requested purchase amount.
Validation Rules:
- A transaction is valid if and only if:
- Purchase amount $> 0$
- Purchase amount $\le \text{balance}$
- Purchase amount is an exact multiple of $50$
Cashback Rules for Valid Transactions:
- Purchase $\ge 5000 \rightarrow 10\%$ cashback
- Purchase $\ge 2000 \rightarrow 5\%$ cashback
- Otherwise $\rightarrow 2\%$ cashback
- $\text{Final Balance} = \text{Balance} - \text{Purchase} + \text{Cashback}$
Print the final balance formatted to 2 decimal places if valid, or print Invalid Transaction if any condition fails.
Input
10000 5000
Output
5500.00
Another Input
10000 5125
Output
Invalid Transaction
Another Input
0 0
Output
Invalid Transaction
Another Input
1000 -500
Output
Invalid Transaction
Another Input
500 1000
Output
Invalid Transaction
Another Input
5000 5000
Output
500.00
View Solution
#include <stdio.h>
int main()
{
double balance, purchase;
int valid;
double cashback_rate;
double final_balance;
scanf("%lf %lf", &balance, &purchase);
valid =
purchase > 0 &&
purchase <= balance &&
((int)purchase % 50 == 0);
cashback_rate =
purchase >= 5000 ? 0.10 :
purchase >= 2000 ? 0.05 :
0.02;
final_balance =
balance - purchase +
purchase * cashback_rate;
valid
? printf("%.2f\n", final_balance)
: printf("Invalid Transaction\n");
return 0;
}
Add-On 7 — Math Rounding Report
Read a floating-point number and compute its ceiling (smallest integer $\ge x$), floor (largest integer $\le x$), and nearest rounded integer. Display each value labeled as Ceil:, Floor:, and Round:.
Input
7.3
Output
Ceil: 8
Floor: 7
Round: 7
Another Input
0.0
Output
Ceil: 0
Floor: 0
Round: 0
Another Input
-5.5
Output
Ceil: -5
Floor: -6
Round: -6
Another Input
5.1
Output
Ceil: 6
Floor: 5
Round: 5
Another Input
-5.9
Output
Ceil: -5
Floor: -6
Round: -6
View Solution
#include <stdio.h>
#include <math.h>
int main()
{
double x;
scanf("%lf", &x);
printf("Ceil: %.0f\n", ceil(x));
printf("Floor: %.0f\n", floor(x));
printf("Round: %.0f\n", round(x));
return 0;
}
Add-On 8 — Character I/O + Literal Percent Sign
Read a letter grade character and a floating-point percentage score. Display the grade using single-character stream I/O and display the percentage formatted to 2 decimal places with a literal % suffix.
Input
A 78.5
Output
Grade: A
Percentage: 78.50%
Another Input
a
Output
Grade: a
Percentage: 0.00%
Another Input
Z
Output
Grade: Z
Percentage: 0.00%
Another Input
0
Output
Grade: 0
Percentage: 0.00%
Another Input
Output
Grade:
Percentage: 0.00%
View Solution
#include <stdio.h>
int main()
{
char grade;
float percentage;
grade = getchar();
scanf("%f", &percentage);
printf("Grade: ");
putchar(grade);
printf("\n");
printf("Percentage: %.2f%%\n", percentage);
return 0;
}
Add-On 9 — Relational + Logical + Unary Operator Report
Read two integers $a$ and $b$. Compute and print the truth values of relational comparisons, logical operations, and unary signs across three lines:
- Line 1 (Relational): $a < b$, $a > b$, $a \le b$, $a \ge b$, $a == b$, $a \neq b$
- Line 2 (Logical): $a \ \&\&\ b$, $a \mid\mid b$, $!a$, $!b$
- Line 3 (Unary): $+a$, $-a$
Another Input
0 0
Output
0 0 1 1 1 0
0 0 1 1
0 0
Another Input
-5 5
Output
1 0 1 0 0 1
1 1 0 0
-5 5
Another Input
10 10
Output
0 0 1 1 1 0
1 1 0 0
10 -10
Another Input
100 -100
Output
0 1 0 1 0 1
1 1 0 0
100 -100
View Solution
#include <stdio.h>
int main()
{
int a, b;
scanf("%d %d", &a, &b);
printf("%d %d %d %d %d %d\n",
a < b,
a > b,
a <= b,
a >= b,
a == b,
a != b);
printf("%d %d %d %d\n",
a && b,
a || b,
!a,
!b);
printf("%d %d\n", +a, -a);
return 0;
}
Add-On 10 — Bitwise Operator Report — Teacher-Material Exception
Read two integers $a$ and $b$. Compute and print the results of fundamental bitwise operations on a single line in this order:
a & b, a | b, a ^ b, ~a, a << 1, a >> 1
Input
5 3
Output
1 7 6 -6 10 2
Another Input
0 0
Output
0 0 0 -1 0 0
Another Input
-1 -1
Output
-1 -1 0 0 -2 -1
Another Input
10 5
Output
0 15 15 -11 20 5
View Solution
#include <stdio.h>
int main()
{
int a, b;
scanf("%d %d", &a, &b);
printf("%d %d %d %d %d %d\n",
a & b,
a | b,
a ^ b,
~a,
a << 1,
a >> 1);
return 0;
}
Add-On 11 — Copy a String Using strcpy()
Read a word into a source string buffer, copy its contents into a separate destination string buffer, and print the destination string.
Input
Chitkara
Output
Chitkara
This covers another directly practised string.h operation in addition to strlen().
Another Input
A
Output
A
Another Input
Hello_World
Output
Hello_World
Another Input
12345
Output
12345
View Solution
#include <stdio.h>
#include <string.h>
int main()
{
char source[100];
char destination[100];
scanf("%s", source);
strcpy(destination, source);
printf("%s\n", destination);
return 0;
}