On this page

SPC CAT-1: Ultimate 121 Coding Practice Bank

Structured Programming Concepts · Unit 1

SPC CAT-1: Ultimate 121 Coding Practice Bank

Course: Structured Programming Concepts
Course Code: 26CSE0105 / 26CSE0101 • Credits: 4 (L-T-P: 2-0-4)
Curriculum Alignment: Chitkara University • B.E. CSE (Semester 01)
Standard Baseline: Modern ISO C (C11 / C17) • Pure Selection & Sequential C
Scope: 121 Coding Problems (40 Easy, 40 Medium, 41 Hard)


[!IMPORTANT] Curriculum & Examination Alignment: The questions in this bank are strictly made in accordance to the SPC CAT-1 Syllabus and categorized with distinct difficulty levels (40 Easy, 40 Medium, 41 Hard). Target goal: Solve 85 problems for 70% exam mastery.


Practice Bank Quick Navigator & Syllabus Alignment

Difficulty Tier Question Range Focus Areas & Topics Covered Mastery Target
Easy Problems (Tier 1) Q1 – Q40 Formatted I/O, arithmetic operators, geometry formulas, digit manipulation, swaps, basic conditionals (if-else), range checks, math.h, ctype.h, basic pointers. 40 / 40 (100%)
Medium Problems (Tier 2) Q41 – Q80 Time/calendar math (HMS, days), 4-digit arithmetic & reversal, leap year logic, triangle classification, coordinate quadrants, quadratic root discriminant, ternary operator, character classification, modular functions, macros. 35 / 40 (88%)
Hard Problems (Tier 3) Q81 – Q121 Multi-value conditional sorting without loops/arrays, multi-tier electricity billing & tax brackets, date validation, parking fee computation, composite nested ternary evaluations, floating-point precision casting, library challenges. 25 / 41 (61%)

Easy Problems

1.

Write a complete C program that outputs the fixed string "SPC CAT1" to standard console output using printf. This problem tests standard I/O structure, header inclusion (#include <stdio.h>), and the main function entry point.

  • Format: Input: No input. · Output: SPC CAT1
  • Sample: (no input) → SPC CAT1
  • Judge Cases: (no input) → SPC CAT1 · (no input) → SPC CAT1
View C Solution
#include <stdio.h>

int main() {
    printf("SPC CAT1\n");
    return 0;
}

2.

Given two integers a and b from standard console input, read both values using formatted scanf, calculate their arithmetic sum (a + b), and print the resulting integer.

  • Format: Input: a b · Output: sum
  • Sample: 5 8 → 13
  • Judge Cases: -4 10 → 6 · 0 0 → 0
View C Solution
#include <stdio.h>

int main() {
    int a, b;
    scanf("%d %d", &a, &b);
    printf("%d\n", a + b);
    }
    return 0;

3.

Given two integers a and b (where b != 0), calculate and display their five fundamental arithmetic results separated by single spaces: sum (a + b), difference (a - b), product (a * b), integer quotient (a / b), and remainder/modulus (a % b).

  • Format: Input: a b · Output: sum difference product quotient remainder
  • Sample: 17 5 → 22 12 85 3 2
  • Judge Cases: 20 4 → 24 16 80 5 0 · 7 3 → 10 4 21 2 1
View C Solution
#include <stdio.h>

int main() {
    int a, b;
    scanf("%d %d", &a, &b);
    printf("%d %d %d %d %d\n", a + b, a - b, a * b, a / b, a % b);
    return 0;
}

4.

In any Euclidean triangle, the sum of all three internal angles is strictly equal to 180°. Given two interior angles a and b in degrees, compute and output the third angle (180 - a - b).

  • Format: Input: a b · Output: third angle
  • Sample: 60 80 → 40
  • Judge Cases: 45 45 → 90 · 30 120 → 30
View C Solution
#include <stdio.h>

int main() {
    int a, b;
    scanf("%d %d", &a, &b);
    printf("%d\n", 180 - a - b);
    }
    return 0;

5.

Given the integer length and breadth of a rectangle, compute and print its total area using the formula Area = length × breadth.

  • Format: Input: length breadth · Output: area
  • Sample: 5 8 → 40
  • Judge Cases: 12 7 → 84 · 1 25 → 25
View C Solution
#include <stdio.h>

int main() {
    int length, breadth;
    scanf("%d %d", &length, &breadth);
    printf("%d\n", length * breadth);
    }
    return 0;

6.

Given the integer dimensions length and breadth of a rectangle, calculate and print its perimeter using the formula Perimeter = 2 × (length + breadth).

  • Format: Input: length breadth · Output: perimeter
  • Sample: 5 8 → 26
  • Judge Cases: 10 10 → 40 · 1 7 → 16
View C Solution
#include <stdio.h>

int main() {
    int length, breadth;
    scanf("%d %d", &length, &breadth);
    printf("%d\n", 2 * (length + breadth));
    }
    return 0;

7.

Given the length of a single side of a square, calculate and output both its area (side²) and its perimeter (4 × side) separated by a space.

  • Format: Input: side · Output: area perimeter
  • Sample: 5 → 25 20
  • Judge Cases: 12 → 144 48 · 1 → 1 4
View C Solution
#include <stdio.h>

int main() {
    int side;
    scanf("%d", &side);
    printf("%d %d\n", side * side, 4 * side);
    }
    return 0;

8.

Given the integer radius r of a circle, compute its total area using the formula Area = πr² where π = 3.14159. Output the calculated area formatted to exactly 2 decimal places.

  • Format: Input: radius · Output: area to 2 decimals
  • Sample: 1 → 3.14
  • Judge Cases: 2 → 12.57 · 5.5 → 95.03
View C Solution
#include <stdio.h>

int main() {
    double r;
    scanf("%lf", &r);
    double area = 3.14159 * r * r;
    printf("%.2f\n", area);
    }
    return 0;

9.

Given a temperature reading in Celsius c, convert it to the equivalent temperature in Fahrenheit f using the conversion formula F = (c × 9/5) + 32. Ensure accurate floating-point arithmetic and print the result formatted to 2 decimal places.

  • Format: Input: celsius · Output: Fahrenheit to 2 decimals
  • Sample: 0 → 32.00
  • Judge Cases: 25 → 77.00 · -40 → -40.00
View C Solution
#include <stdio.h>

int main() {
    double c;
    scanf("%lf", &c);
    double f = (c * 9.0 / 5.0) + 32.0;
    printf("%.2f\n", f);
    }
    return 0;

10.

Given a temperature reading in Fahrenheit f, convert it to Celsius c using the conversion formula C = (f - 32) × 5/9. Print the result accurate to 2 decimal places.

  • Format: Input: fahrenheit · Output: Celsius to 2 decimals
  • Sample: 32 → 0.00
  • Judge Cases: 212 → 100.00 · -40 → -40.00
View C Solution
#include <stdio.h>

int main() {
    double f;
    scanf("%lf", &f);
    double c = (f - 32.0) * 5.0 / 9.0;
    printf("%.2f\n", c);
    }
    return 0;

11.

Given the Principal amount P, annual interest Rate in percent R, and Time duration in years T, compute the Simple Interest using the formula SI = (P × R × T) / 100. Print the simple interest formatted to 2 decimal places.

  • Format: Input: P R T · Output: interest to 2 decimals
  • Sample: 1000 5 2 → 100.00
  • Judge Cases: 2500 7.5 1 → 187.50 · 800 4 3 → 96.00
View C Solution
#include <stdio.h>

int main() {
    double p, r, t;
    scanf("%lf %lf %lf", &p, &r, &t);
    double si = (p * r * t) / 100.0;
    printf("%.2f\n", si);
    }
    return 0;

12.

Given two integers a and b, compute their arithmetic mean. Perform proper type casting to float or double ((float)(a + b) / 2.0) to avoid integer truncation, and print the average formatted to 2 decimal places.

  • Format: Input: a b · Output: average to 2 decimals
  • Sample: 5 2 → 3.50
  • Judge Cases: 10 4 → 7.00 · -3 2 → -0.50
View C Solution
#include <stdio.h>

int main() {
    int a, b;
    scanf("%d %d", &a, &b);
    double avg = (double)(a + b) / 2.0;
    printf("%.2f\n", avg);
    }
    return 0;

13.

Given three integers a, b, and c, compute their average as a high-precision floating-point value. Output the calculated average rounded to 2 decimal places.

  • Format: Input: a b c · Output: average to 2 decimals
  • Sample: 10 20 30 → 20.00
  • Judge Cases: 1 2 2 → 1.67 · 5 5 6 → 5.33
View C Solution
#include <stdio.h>

int main() {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    double avg = (double)(a + b + c) / 3.0;
    printf("%.2f\n", avg);
    }
    return 0;

14.

A student obtains a given number of marks out of maximum possible total marks. Compute their overall percentage score using Percentage = (obtained / total) × 100 and print the result formatted to 2 decimal places.

  • Format: Input: obtained total · Output: percentage to 2 decimals
  • Sample: 47 60 → 78.33
  • Judge Cases: 75 100 → 75.00 · 1 4 → 25.00
View C Solution
#include <stdio.h>

int main() {
    double obtained, total;
    scanf("%lf %lf", &obtained, &total);
    double pct = (obtained / total) * 100.0;
    printf("%.2f\n", pct);
    return 0;
}

15.

In Indian currency, 1 Rupee = 100 Paise. Given an integer value in rupees, convert and print the equivalent value in paise.

  • Format: Input: rupees · Output: paise
  • Sample: 10 → 1000
  • Judge Cases: 1 → 100 · 250 → 25000
View C Solution
#include <stdio.h>

int main() {
    int rupees;
    scanf("%d", &rupees);
    printf("%d\n", rupees * 100);
    }
    return 0;

16.

Given three integers representing hours h, minutes m, and seconds s, calculate and output the total duration elapsed converted entirely into seconds (3600 × h + 60 × m + s).

  • Format: Input: h m s · Output: total seconds
  • Sample: 1 2 3 → 3723
  • Judge Cases: 0 5 30 → 330 · 2 0 0 → 7200
View C Solution
#include <stdio.h>

int main() {
    int h, m, s;
    scanf("%d %d %d", &h, &m, &s);
    int total = h * 3600 + m * 60 + s;
    printf("%d\n", total);
    }
    return 0;

17.

Given a dividend a and a non-zero divisor b, compute and output both the integer division quotient (a / b) and the integer remainder (a % b) separated by a space.

  • Format: Input: a b, b != 0 · Output: quotient remainder
  • Sample: 17 5 → 3 2
  • Judge Cases: 20 4 → 5 0 · 7 3 → 2 1
View C Solution
#include <stdio.h>

int main() {
    int a, b;
    scanf("%d %d", &a, &b);
    printf("%d %d\n", a / b, a % b);
    return 0;
}

18.

Given an integer n, extract and print its units (last) digit using the modulus operator (abs(n) % 10).

  • Format: Input: n · Output: last digit
  • Sample: 1234 → 4
  • Judge Cases: 50 → 0 · 7 → 7
View C Solution
#include <stdio.h>
#include <stdlib.h>

int main() {
    int n;
    scanf("%d", &n);
    printf("%d\n", abs(n) % 10);
    }
    return 0;

19.

Given an integer n of at least two digits, extract and print its tens digit using integer division and modulus ((abs(n) / 10) % 10).

  • Format: Input: n · Output: tens digit
  • Sample: 583 → 8
  • Judge Cases: 101 → 0 · 999 → 9
View C Solution
#include <stdio.h>
#include <stdlib.h>

int main() {
    int n;
    scanf("%d", &n);
    printf("%d\n", (abs(n) / 10) % 10);
    }
    return 0;

20.

Given a three-digit positive integer n, extract all three individual digits (hundreds, tens, units) and compute their sum.

  • Format: Input: n · Output: digit sum
  • Sample: 357 → 15
  • Judge Cases: 100 → 1 · 999 → 27
View C Solution
#include <stdio.h>
#include <stdlib.h>

int main() {
    int n;
    scanf("%d", &n);
    int val = abs(n);
    int d1 = val / 100;
    int d2 = (val / 10) % 10;
    int d3 = val % 10;
    printf("%d\n", d1 + d2 + d3);
    }
    return 0;

21.

Given a three-digit positive integer n, extract its hundreds, tens, and units digits and print their mathematical product.

  • Format: Input: n · Output: digit product
  • Sample: 234 → 24
  • Judge Cases: 105 → 0 · 999 → 729
View C Solution
#include <stdio.h>
#include <stdlib.h>

int main() {
    int n;
    scanf("%d", &n);
    int val = abs(n);
    int d1 = val / 100;
    int d2 = (val / 10) % 10;
    int d3 = val % 10;
    printf("%d\n", d1 * d2 * d3);
    }
    return 0;

22.

Given a three-digit positive integer n (e.g. 123), reverse the order of its digits to form a new three-digit integer (321) and print it.

  • Format: Input: n · Output: reversed number
  • Sample: 357 → 753
  • Judge Cases: 120 → 21 · 901 → 109
View C Solution
#include <stdio.h>

int main() {
    int n;
    scanf("%d", &n);
    int d1 = n / 100;
    int d2 = (n / 10) % 10;
    int d3 = n % 10;
    int rev = d3 * 100 + d2 * 10 + d1;
    printf("%d\n", rev);
    }
    return 0;

23.

Read two integers a and b. Swap their stored values using a temporary third variable (temp = a; a = b; b = temp;), and print the swapped values separated by a space.

  • Format: Input: a b · Output: swapped values
  • Sample: 5 9 → 9 5
  • Judge Cases: -2 7 → 7 -2 · 10 10 → 10 10
View C Solution
#include <stdio.h>

int main() {
    int a, b;
    scanf("%d %d", &a, &b);
    int temp = a;
    a = b;
    b = temp;
    printf("%d %d\n", a, b);
    }
    return 0;

24.

Given an integer n, determine whether it is EVEN or ODD using the remainder when divided by 2 (n % 2 == 0).

  • Format: Input: n · Output: classification
  • Sample: 8 → Even
  • Judge Cases: 11 → Odd · 0 → Even
View C Solution
#include <stdio.h>

int main() {
    int n;
    scanf("%d", &n);
    if (n % 2 == 0) {
        printf("Even\n");
    } else {
        printf("Odd\n");
    }
    }
    return 0;

25.

Given an integer n, classify whether it is POSITIVE (n > 0), NEGATIVE (n < 0), or ZERO (n == 0).

  • Format: Input: n · Output: classification
  • Sample: 12 → Positive
  • Judge Cases: -8 → Negative · 0 → Zero
View C Solution
#include <stdio.h>

int main() {
    int n;
    scanf("%d", &n);
    if (n > 0) {
        printf("Positive\n");
    } else if (n < 0) {
        printf("Negative\n");
    } else {
        printf("Zero\n");
    }
    }
    return 0;

26.

Given two integers a and b, find and output the maximum of the two using relational comparison or the conditional operator.

  • Format: Input: a b · Output: maximum
  • Sample: 5 9 → 9
  • Judge Cases: 12 3 → 12 · -4 -7 → -4
View C Solution
#include <stdio.h>

int main() {
    int a, b;
    scanf("%d %d", &a, &b);
    printf("%d\n", (a > b) ? a : b);
    }
    return 0;

27.

Given two integers a and b, find and output the minimum of the two.

  • Format: Input: a b · Output: minimum
  • Sample: 5 9 → 5
  • Judge Cases: 12 3 → 3 · -4 -7 → -7
View C Solution
#include <stdio.h>

int main() {
    int a, b;
    scanf("%d %d", &a, &b);
    printf("%d\n", (a < b) ? a : b);
    }
    return 0;

28.

Given an integer n, compute its absolute value |n| without using math.h or stdlib.h, using a conditional expression (n < 0 ? -n : n).

  • Format: Input: n · Output: absolute value
  • Sample: -15 → 15
  • Judge Cases: 9 → 9 · 0 → 0
View C Solution
#include <stdio.h>

int main() {
    int n;
    scanf("%d", &n);
    printf("%d\n", (n < 0) ? -n : n);
    }
    return 0;

29.

Given an integer x and inclusive range boundaries low and high (low <= high), print 1 if low <= x <= high, and 0 otherwise.

  • Format: Input: x low high · Output: Inside or Outside
  • Sample: 5 0 10 → Inside
  • Judge Cases: -1 0 10 → Outside · 10 0 10 → Inside
View C Solution
#include <stdio.h>

int main() {
    int x, low, high;
    scanf("%d %d %d", &x, &low, &high);
    if (x >= low && x <= high) {
        printf("Inside\n");
    } else {
        printf("Outside\n");
    }
    }
    return 0;

30.

Given an integer n, check if it is simultaneously divisible by both 5 and 11 (n % 5 == 0 && n % 11 == 0). Print 1 if true, else 0.

  • Format: Input: n · Output: Yes or No
  • Sample: 55 → Yes
  • Judge Cases: 110 → Yes · 25 → No
View C Solution
#include <stdio.h>

int main() {
    int n;
    scanf("%d", &n);
    if (n % 5 == 0 && n % 11 == 0) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }
    }
    return 0;

31.

Given an integer n, check if it is divisible by 3, divisible by 7, or divisible by both (n % 3 == 0 || n % 7 == 0). Print 1 if divisible, else 0.

  • Format: Input: n · Output: Yes or No
  • Sample: 9 → Yes
  • Judge Cases: 14 → Yes · 10 → No
View C Solution
#include <stdio.h>

int main() {
    int n;
    scanf("%d", &n);
    if (n % 3 == 0 || n % 7 == 0) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }
    }
    return 0;

32.

Demonstrate compound assignment operators in sequence: read an integer x, add 5 (x += 5), multiply by 2 (x *= 2), and subtract 3 (x -= 3). Output the final value of x.

  • Format: Input: x · Output: final x
  • Sample: 4 → 15
  • Judge Cases: 0 → 7 · -5 → -3
View C Solution
#include <stdio.h>

int main() {
    int x;
    scanf("%d", &x);
    x += 5;
    x *= 2;
    x -= 3;
    printf("%d\n", x);
    }
    return 0;

33.

Demonstrate post-increment behavior (x++): read x, print the value of the post-increment expression, and then print the updated variable value.

  • Format: Input: x · Output: x a
  • Sample: 5 → 6 5
  • Judge Cases: 0 → 1 0 · -2 → -1 -2
View C Solution
#include <stdio.h>

int main() {
    int x;
    scanf("%d", &x);
    int old = x++;
    printf("%d %d\n", x, old);
    }
    return 0;

34.

Demonstrate pre-increment behavior (++x): read x, evaluate ++x, and print the resulting value.

  • Format: Input: x · Output: x a
  • Sample: 5 → 6 6
  • Judge Cases: 0 → 1 1 · -2 → -1 -1
View C Solution
#include <stdio.h>

int main() {
    int x;
    scanf("%d", &x);
    int res = ++x;
    printf("%d %d\n", x, res);
    }
    return 0;

35.

Print a multi-line formatted message demonstrating escape sequences: newline (\n), tab (\t), double quote ("), and backslash (\).

  • Format: Input: n · Output: exact formatted output
  • Sample: 5 → Value: 5 "Done"
  • Judge Cases: 0 → Value: 0 · -7 → Value: -7
View C Solution
#include <stdio.h>

int main() {
    int n;
    scanf("%d", &n);
    printf("Value:\t%d \"Done\"\n", n);
    }
    return 0;

36.

Given a lowercase alphabetic character ch ('a' - 'z'), convert it to uppercase using ASCII arithmetic (ch - 'a' + 'A') or toupper() from ctype.h.

  • Format: Input: ch · Output: uppercase character
  • Sample: a → A
  • Judge Cases: m → M · z → Z
View C Solution
#include <stdio.h>
#include <ctype.h>

int main() {
    char ch;
    scanf(" %c", &ch);
    printf("%c\n", toupper((unsigned char)ch));
    }
    return 0;

37.

Given a single character ch, determine if it is a numeric digit ('0' - '9'). Print 1 if it is a digit, else 0.

  • Format: Input: ch · Output: Digit or Not Digit
  • Sample: 7 → Digit
  • Judge Cases: a → Not Digit · # → Not Digit
View C Solution
#include <stdio.h>
#include <ctype.h>

int main() {
    char ch;
    scanf(" %c", &ch);
    if (isdigit((unsigned char)ch)) {
        printf("Digit\n");
    } else {
        printf("Not Digit\n");
    }
    }
    return 0;

38.

Given a non-negative floating-point number x, compute its square root using sqrt() from math.h. Print the result formatted to 2 decimal places.

  • Format: Input: x >= 0 · Output: result to 2 decimals
  • Sample: 25 → 5.00
  • Judge Cases: 2 → 1.41 · 0 → 0.00
View C Solution
#include <stdio.h>
#include <math.h>

int main() {
    double x;
    scanf("%lf", &x);
    printf("%.2f\n", sqrt(x));
    return 0;
}

39.

Given two integers a and b, compute the absolute difference |a - b| using the standard library function abs() from stdlib.h.

  • Format: Input: a b · Output: absolute difference
  • Sample: 10 3 → 7
  • Judge Cases: 3 10 → 7 · -5 -2 → 3
View C Solution
#include <stdio.h>
#include <stdlib.h>

int main() {
    int a, b;
    scanf("%d %d", &a, &b);
    printf("%d\n", abs(a - b));
    }
    return 0;

40.

Demonstrate basic pointer dereferencing: declare an integer x, create a pointer int *p = &x, modify the value of x indirectly through *p, and print the updated value.

  • Format: Input: x · Output: modified x
  • Sample: 10 → 15
  • Judge Cases: -4 → 1 · 0 → 5
View C Solution
#include <stdio.h>

int main() {
    int x;
    scanf("%d", &x);
    int *p = &x;
    *p = *p + 5;
    printf("%d\n", x);
    return 0;
}

Medium Problems

41.

Given a total duration in seconds, convert and decompose it into standard hours, minutes, and remaining seconds format (hours = s / 3600, minutes = (s % 3600) / 60, seconds = s % 60).

  • Format: Input: totalSeconds · Output: hours minutes seconds
  • Sample: 3723 → 1 2 3
  • Judge Cases: 59 → 0 0 59 · 86399 → 23 59 59
View C Solution
#include <stdio.h>

int main() {
    int totalSeconds;
    scanf("%d", &totalSeconds);
    int h = totalSeconds / 3600;
    int m = (totalSeconds % 3600) / 60;
    int s = totalSeconds % 60;
    printf("%d %d %d\n", h, m, s);
    }
    return 0;

42.

Given a total number of days, convert it into equivalent whole weeks and remaining surplus days (weeks = days / 7, days = days % 7).

  • Format: Input: days · Output: weeks days
  • Sample: 17 → 2 3
  • Judge Cases: 7 → 1 0 · 6 → 0 6
View C Solution
#include <stdio.h>

int main() {
    int days;
    scanf("%d", &days);
    int weeks = days / 7;
    int remDays = days % 7;
    printf("%d %d\n", weeks, remDays);
    }
    return 0;

43.

Given a four-digit positive integer n (1000 <= n <= 9999), extract each of its four individual digits and compute their sum.

  • Format: Input: n · Output: sum
  • Sample: 1234 → 10
  • Judge Cases: 9001 → 10 · 9999 → 36
View C Solution
#include <stdio.h>

int main() {
    int n;
    scanf("%d", &n);
    int d1 = n / 1000;
    int d2 = (n / 100) % 10;
    int d3 = (n / 10) % 10;
    int d4 = n % 10;
    printf("%d\n", d1 + d2 + d3 + d4);
    }
    return 0;

44.

Given a four-digit positive integer n, extract all four digits and compute their mathematical product.

  • Format: Input: n · Output: product
  • Sample: 1234 → 24
  • Judge Cases: 9001 → 0 · 2222 → 16
View C Solution
#include <stdio.h>

int main() {
    int n;
    scanf("%d", &n);
    int d1 = n / 1000;
    int d2 = (n / 100) % 10;
    int d3 = (n / 10) % 10;
    int d4 = n % 10;
    printf("%d\n", d1 * d2 * d3 * d4);
    }
    return 0;

45.

Given a four-digit integer n, reverse its digits without using loops or strings to produce the reversed 4-digit number.

  • Format: Input: n · Output: reversed number
  • Sample: 1234 → 4321
  • Judge Cases: 1200 → 21 · 9001 → 1009
View C Solution
#include <stdio.h>

int main() {
    int n;
    scanf("%d", &n);
    int d1 = n / 1000;
    int d2 = (n / 100) % 10;
    int d3 = (n / 10) % 10;
    int d4 = n % 10;
    int rev = d4 * 1000 + d3 * 100 + d2 * 10 + d1;
    printf("%d\n", rev);
    }
    return 0;

46.

Given a four-digit positive integer n, extract the first (thousands) digit and the last (units) digit, and print their sum.

  • Format: Input: n · Output: first last
  • Sample: 4827 → 4 7
  • Judge Cases: 1000 → 1 0 · 9999 → 9 9
View C Solution
#include <stdio.h>

int main() {
    int n;
    scanf("%d", &n);
    int first = n / 1000;
    int last = n % 10;
    printf("%d %d\n", first, last);
    }
    return 0;

47.

Given a four-digit integer n, split it into two 2-digit numbers: the first two digits (n / 100) and the last two digits (n % 100), and print both.

  • Format: Input: n · Output: firstTwo lastTwo
  • Sample: 5837 → 58 37
  • Judge Cases: 1204 → 12 4 · 9999 → 99 99
View C Solution
#include <stdio.h>

int main() {
    int n;
    scanf("%d", &n);
    int firstTwo = n / 100;
    int lastTwo = n % 100;
    printf("%d %d\n", firstTwo, lastTwo);
    }
    return 0;

48.

Given four single-digit integers d1, d2, d3, d4 (0 <= d <= 9), construct and output the complete 4-digit integer 1000d1 + 100d2 + 10*d3 + d4.

  • Format: Input: a b c d · Output: constructed number
  • Sample: 1 2 3 4 → 1234
  • Judge Cases: 9 0 0 1 → 9001 · 5 5 5 5 → 5555
View C Solution
#include <stdio.h>

int main() {
    int a, b, c, d;
    scanf("%d %d %d %d", &a, &b, &c, &d);
    int res = a * 1000 + b * 100 + c * 10 + d;
    printf("%d\n", res);
    }
    return 0;

49.

Given a three-digit integer N = 100A + 10B + C, rearrange its digits into the new order CAB = 100C + 10A + B and print the result.

  • Format: Input: n · Output: rearranged number
  • Sample: 123 → 312
  • Judge Cases: 507 → 750 · 890 → 89
View C Solution
#include <stdio.h>

int main() {
    int n;
    scanf("%d", &n);
    int a = n / 100;
    int b = (n / 10) % 10;
    int c = n % 10;
    int res = c * 100 + a * 10 + b;
    printf("%d\n", res);
    }
    return 0;

50.

Read two integers a and b. Swap their values in-place without using any third temporary variable using arithmetic addition and subtraction (a = a + b; b = a - b; a = a - b;).

  • Format: Input: a b · Output: swapped values
  • Sample: 5 9 → 9 5
  • Judge Cases: 10 -3 → -3 10 · 0 7 → 7 0
View C Solution
#include <stdio.h>

int main() {
    int a, b;
    scanf("%d %d", &a, &b);
    a = a + b;
    b = a - b;
    a = a - b;
    printf("%d %d\n", a, b);
    }
    return 0;

51.

Given three integers a, b, and c, determine and print the largest of the three using nested conditional (ternary) operators ? :.

  • Format: Input: a b c · Output: maximum
  • Sample: 5 9 3 → 9
  • Judge Cases: 10 10 2 → 10 · -5 -2 -9 → -2
View C Solution
#include <stdio.h>

int main() {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    int max = (a > b) ? ((a > c) ? a : c) : ((b > c) ? b : c);
    printf("%d\n", max);
    }
    return 0;

52.

Given three integers a, b, and c, determine and print the smallest of the three using the conditional operator ? :.

  • Format: Input: a b c · Output: minimum
  • Sample: 5 9 3 → 3
  • Judge Cases: 10 10 2 → 2 · -5 -2 -9 → -9
View C Solution
#include <stdio.h>

int main() {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    int min = (a < b) ? ((a < c) ? a : c) : ((b < c) ? b : c);
    printf("%d\n", min);
    }
    return 0;

53.

Given three distinct integers a, b, and c, find the median value (the value that lies strictly between the minimum and maximum).

  • Format: Input: a b c · Output: median
  • Sample: 3 9 5 → 5
  • Judge Cases: 10 2 7 → 7 · -5 0 -2 → -2
View C Solution
#include <stdio.h>

int main() {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    int max = (a > b) ? ((a > c) ? a : c) : ((b > c) ? b : c);
    int min = (a < b) ? ((a < c) ? a : c) : ((b < c) ? b : c);
    int median = (a + b + c) - max - min;
    printf("%d\n", median);
    }
    return 0;

54.

Given three integers, find the difference between the maximum value and the minimum value (range = max(a,b,c) - min(a,b,c)).

  • Format: Input: a b c · Output: difference
  • Sample: 3 9 5 → 6
  • Judge Cases: 7 7 7 → 0 · -5 2 10 → 15
View C Solution
#include <stdio.h>

int main() {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    int max = (a > b) ? ((a > c) ? a : c) : ((b > c) ? b : c);
    int min = (a < b) ? ((a < c) ? a : c) : ((b < c) ? b : c);
    printf("%d\n", max - min);
    }
    return 0;

55.

Given four integers a, b, c, and d, determine the maximum value among all four using nested conditional expressions.

  • Format: Input: a b c d · Output: maximum
  • Sample: 3 9 2 7 → 9
  • Judge Cases: -1 -5 -2 -3 → -1 · 4 4 2 1 → 4
View C Solution
#include <stdio.h>

int main() {
    int a, b, c, d;
    scanf("%d %d %d %d", &a, &b, &c, &d);
    int m1 = (a > b) ? a : b;
    int m2 = (c > d) ? c : d;
    int max = (m1 > m2) ? m1 : m2;
    printf("%d\n", max);
    }
    return 0;

56.

Given two integers a and b, print them in ascending (non-decreasing) sorted order separated by a space using the conditional operator.

  • Format: Input: a b · Output: smaller larger
  • Sample: 9 3 → 3 9
  • Judge Cases: -2 5 → -2 5 · 7 7 → 7 7
View C Solution
#include <stdio.h>

int main() {
    int a, b;
    scanf("%d %d", &a, &b);
    if (a <= b) {
        printf("%d %d\n", a, b);
    } else {
        printf("%d %d\n", b, a);
    }
    }
    return 0;

57.

Given a four-digit integer n, determine whether it is a palindrome (reads identical forwards and backwards, e.g. 1221). Output PALINDROME or NOT PALINDROME.

  • Format: Input: n · Output: Palindrome or Not Palindrome
  • Sample: 1221 → Palindrome
  • Judge Cases: 1234 → Not Palindrome · 9009 → Palindrome
View C Solution
#include <stdio.h>

int main() {
    int n;
    scanf("%d", &n);
    int d1 = n / 1000;
    int d2 = (n / 100) % 10;
    int d3 = (n / 10) % 10;
    int d4 = n % 10;
    if (d1 == d4 && d2 == d3) {
        printf("Palindrome\n");
    } else {
        printf("Not Palindrome\n");
    }
    }
    return 0;

58.

A 3-digit number is an Armstrong number if the sum of the cubes of its digits equals the number itself (d1³ + d2³ + d3³ = N). Check if a given 3-digit integer is an Armstrong number.

  • Format: Input: n · Output: Armstrong or Not Armstrong
  • Sample: 153 → Armstrong
  • Judge Cases: 370 → Armstrong · 123 → Not Armstrong
View C Solution
#include <stdio.h>

int main() {
    int n;
    scanf("%d", &n);
    int d1 = n / 100;
    int d2 = (n / 10) % 10;
    int d3 = n % 10;
    int sum = d1 * d1 * d1 + d2 * d2 * d2 + d3 * d3 * d3;
    if (sum == n) {
        printf("Armstrong\n");
    } else {
        printf("Not Armstrong\n");
    }
    }
    return 0;

59.

Given the marks obtained by a student across subjects, compute the percentage and determine if the student has PASSED (percentage >= 40.0) or FAILED.

  • Format: Input: obtained total · Output: Pass or Fail
  • Sample: 24 60 → Pass
  • Judge Cases: 23 60 → Fail · 40 100 → Pass
View C Solution
#include <stdio.h>

int main() {
    double obtained, total;
    scanf("%lf %lf", &obtained, &total);
    double pct = (obtained / total) * 100.0;
    if (pct >= 40.0) {
        printf("Pass\n");
    } else {
        printf("Fail\n");
    }
    return 0;
}

60.

Given an exam score between 0 and 100, assign letter grades using a nested ternary expression: >= 90 -> A, >= 80 -> B, >= 70 -> C, >= 60 -> D, else F.

  • Format: Input: marks · Output: grade letter
  • Sample: 95 → A
  • Judge Cases: 75 → B · 59 → D · 12 → F
View C Solution
#include <stdio.h>

int main() {
    int marks;
    scanf("%d", &marks);
    char grade = (marks >= 90) ? 'A' :
                 (marks >= 80) ? 'B' :
                 (marks >= 70) ? 'C' :
                 (marks >= 60) ? 'D' : 'F';
    printf("%c\n", grade);
    }
    return 0;

61.

Given an integer n, test whether it is divisible by 3 or by 7, but NOT by both simultaneously (exclusive OR logic via relational expressions).

  • Format: Input: n · Output: Yes or No
  • Sample: 9 → Yes
  • Judge Cases: 14 → Yes · 21 → No
View C Solution
#include <stdio.h>

int main() {
    int n;
    scanf("%d", &n);
    int div3 = (n % 3 == 0);
    int div7 = (n % 7 == 0);
    if (div3 ^ div7) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }
    }
    return 0;

62.

Given three integers a, b, and c, check if all three values are strictly equal to one another (a == b && b == c). Output EQUAL or NOT EQUAL.

  • Format: Input: a b c · Output: Same or Different
  • Sample: 5 5 5 → Same
  • Judge Cases: 5 5 4 → Different · -2 -2 -2 → Same
View C Solution
#include <stdio.h>

int main() {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    if (a == b && b == c) {
        printf("Same\n");
    } else {
        printf("Different\n");
    }
    }
    return 0;

63.

Calculate a student's weighted composite score given scores in Theory (T, weight 40%), Practical (P, weight 30%), and Project (Proj, weight 30%). Output formatted to 2 decimals.

  • Format: Input: a b c · Output: score to 2 decimals
  • Sample: 80 70 90 → 82.00
  • Judge Cases: 100 100 100 → 100.00 · 50 60 70 → 63.00
View C Solution
#include <stdio.h>

int main() {
    double t, p, proj;
    scanf("%lf %lf %lf", &t, &p, &proj);
    double composite = t * 0.40 + p * 0.30 + proj * 0.30;
    printf("%.2f\n", composite);
    }
    return 0;

64.

Given an item price, apply a tax percentage first, then apply a discount percentage to the taxed total. Compute and print the final payable amount formatted to 2 decimal places.

  • Format: Input: price tax discount · Output: final price to 2 decimals
  • Sample: 1000 18 10 → 1062.00
  • Judge Cases: 500 5 0 → 525.00 · 800 12.5 20 → 720.00
View C Solution
#include <stdio.h>

int main() {
    double price, tax, discount;
    scanf("%lf %lf %lf", &price, &tax, &discount);
    double taxed = price + (price * tax / 100.0);
    double finalPrice = taxed - (taxed * discount / 100.0);
    printf("%.2f\n", finalPrice);
    }
    return 0;

65.

Given a person's weight in kilograms (W) and height in meters (H), compute Body Mass Index BMI = W / H² and classify: Underweight (< 18.5), Normal (18.5 - 24.9), Overweight (25.0 - 29.9), or Obese (>= 30.0).

  • Format: Input: weight height · Output: BMI to 2 decimals + category
  • Sample: 60 1.75 → 19.59 Normal
  • Judge Cases: 45 1.70 → 15.57 Underweight · 90 1.70 → 31.14 Obese
View C Solution
#include <stdio.h>

int main() {
    double w, h;
    scanf("%lf %lf", &w, &h);
    double bmi = w / (h * h);
    if (bmi < 18.5) {
        printf("%.2f Underweight\n", bmi);
    } else if (bmi < 25.0) {
        printf("%.2f Normal\n", bmi);
    } else if (bmi < 30.0) {
        printf("%.2f Overweight\n", bmi);
    } else {
        printf("%.2f Obese\n", bmi);
    }
    return 0;
}

66.

Given the Cost Price (CP) and Selling Price (SP) of an item, determine whether there is PROFIT, LOSS, or NO CHANGE, along with the calculated difference.

  • Format: Input: cost selling · Output: classification
  • Sample: 100 130 → Profit 30
  • Judge Cases: 250 200 → Loss 50 · 90 90 → No Change
View C Solution
#include <stdio.h>
#include <stdlib.h>

int main() {
    int cp, sp;
    scanf("%d %d", &cp, &sp);
    if (sp > cp) {
        printf("Profit %d\n", sp - cp);
    } else if (cp > sp) {
        printf("Loss %d\n", cp - sp);
    } else {
        printf("No Change\n");
    }
    }
    return 0;

67.

Given a temperature value and a unit character ('C' for Celsius, 'F' for Fahrenheit), convert Celsius to Fahrenheit or Fahrenheit to Celsius accordingly.

  • Format: Input: value unit · Output: converted value to 2 decimals + target unit
  • Sample: 0 C → 32.00 F
  • Judge Cases: 212 F → 100.00 C · -40 C → -40.00 F
View C Solution
#include <stdio.h>

int main() {
    double val;
    char unit;
    scanf("%lf %c", &val, &unit);
    if (unit == 'C' || unit == 'c') {
        double f = (val * 9.0 / 5.0) + 32.0;
        printf("%.2f F\n", f);
    } else if (unit == 'F' || unit == 'f') {
        double c = (val - 32.0) * 5.0 / 9.0;
        printf("%.2f C\n", c);
    }
    }
    return 0;

68.

Given an integer variable x, evaluate a compound expression involving pre-increment and post-increment (y = ++x + x++), and print the values of x and y.

  • Format: Input: x · Output: four integers
  • Sample: 5 → 6 5 7 7
  • Judge Cases: 0 → 1 0 2 2 · -2 → -1 -2 0 0
View C Solution
#include <stdio.h>

int main() {
    int x;
    scanf("%d", &x);
    int a = ++x;
    int b = x++;
    int c = ++x;
    int d = x;
    printf("%d %d %d %d\n", a, b - 1, c, d);
    }
    return 0;

69.

Demonstrate the difference between casting before division ((float)a / b) and casting after integer division ((float)(a / b)). Print both results to 4 decimal places.

  • Format: Input: a b, b!=0 · Output: both to 2 decimals
  • Sample: 5 2 → 2.00 2.50
  • Judge Cases: 7 3 → 2.00 2.33 · -7 2 → -3.00 -3.50
View C Solution
#include <stdio.h>

int main() {
    int a, b;
    scanf("%d %d", &a, &b);
    double castAfter = (double)(a / b);
    double castBefore = (double)a / b;
    printf("%.2f %.2f\n", castAfter, castBefore);
    return 0;
}

70.

Given integers a and b (b != 0), compute both the truncated integer quotient (a / b) and the true floating-point quotient ((double)a / b), printing both on one line.

  • Format: Input: a b, b!=0 · Output: integer then float to 2 decimals
  • Sample: 7 2 → 3 3.50
  • Judge Cases: 10 4 → 2 2.50 · -7 2 → -3 -3.50
View C Solution
#include <stdio.h>

int main() {
    int a, b;
    scanf("%d %d", &a, &b);
    int intQuot = a / b;
    double floatQuot = (double)a / b;
    printf("%d %.2f\n", intQuot, floatQuot);
    return 0;
}

71.

Given a positive floating-point number x, perform rounding to the nearest integer using type casting ((int)(x + 0.5)) without using math.h rounding functions.

  • Format: Input: x · Output: rounded integer
  • Sample: 4.49 → 4
  • Judge Cases: 4.50 → 5 · 12.99 → 13
View C Solution
#include <stdio.h>

int main() {
    double x;
    scanf("%lf", &x);
    int rounded = (int)(x + 0.5);
    printf("%d\n", rounded);
    }
    return 0;

72.

Given the lengths of the two perpendicular sides a and b of a right-angled triangle, compute the hypotenuse length c = sqrt(a² + b²) using sqrt() from math.h. Format to 2 decimal places.

  • Format: Input: a b · Output: hypotenuse to 2 decimals
  • Sample: 3 4 → 5.00
  • Judge Cases: 5 12 → 13.00 · 1 1 → 1.41
View C Solution
#include <stdio.h>
#include <math.h>

int main() {
    double a, b;
    scanf("%lf %lf", &a, &b);
    double c = sqrt(a * a + b * b);
    printf("%.2f\n", c);
    }
    return 0;

73.

Given 2D Cartesian coordinates (x1, y1) and (x2, y2), calculate the Euclidean distance d = sqrt((x2-x1)² + (y2-y1)²) using sqrt() and pow(). Format to 2 decimal places.

  • Format: Input: x1 y1 x2 y2 · Output: distance to 2 decimals
  • Sample: 0 0 3 4 → 5.00
  • Judge Cases: 1 1 1 1 → 0.00 · -1 -1 2 3 → 5.00
View C Solution
#include <stdio.h>
#include <math.h>

int main() {
    double x1, y1, x2, y2;
    scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);
    double d = sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2));
    printf("%.2f\n", d);
    }
    return 0;

74.

Given Principal P, annual rate R, time T years, and compounding frequency N times/year, compute the total Compound Amount A = P * (1 + R/(100N))^(NT) using pow(). Format to 2 decimal places.

  • Format: Input: P R T · Output: amount to 2 decimals
  • Sample: 1000 10 2 → 1210.00
  • Judge Cases: 2000 5 3 → 2315.25 · 500 0 10 → 500.00
View C Solution
#include <stdio.h>
#include <math.h>

int main() {
    double p, r, t;
    scanf("%lf %lf %lf", &p, &r, &t);
    double amount = p * pow(1.0 + (r / 100.0), t);
    printf("%.2f\n", amount);
    }
    return 0;

75.

Given an ASCII character ch, classify it into UPPERCASE, LOWERCASE, DIGIT, or SPECIAL using classification functions from ctype.h.

  • Format: Input: ch · Output: category
  • Sample: 7 → Digit
  • Judge Cases: Q → Uppercase · m → Lowercase · # → Other
View C Solution
#include <stdio.h>
#include <ctype.h>

int main() {
    char ch;
    scanf(" %c", &ch);
    if (isupper((unsigned char)ch)) {
        printf("Uppercase\n");
    } else if (islower((unsigned char)ch)) {
        printf("Lowercase\n");
    } else if (isdigit((unsigned char)ch)) {
        printf("Digit\n");
    } else {
        printf("Other\n");
    }
    }
    return 0;

76.

Given an alphabetic character ch, toggle its case: if uppercase convert to lowercase, if lowercase convert to uppercase using toupper() and tolower().

  • Format: Input: ch · Output: one character
  • Sample: a → A
  • Judge Cases: Q → q · # → #
View C Solution
#include <stdio.h>
#include <ctype.h>

int main() {
    char ch;
    scanf(" %c", &ch);
    if (isupper((unsigned char)ch)) {
        printf("%c\n", tolower((unsigned char)ch));
    } else if (islower((unsigned char)ch)) {
        printf("%c\n", toupper((unsigned char)ch));
    } else {
        printf("%c\n", ch);
    }
    }
    return 0;

77.

Write and call a user-defined function int max_two(int a, int b) that returns the larger of two integer parameters.

  • Format: Input: a b · Output: maximum
  • Sample: 4 9 → 9
  • Judge Cases: -2 -5 → -2 · 7 7 → 7
View C Solution
#include <stdio.h>

int max_two(int a, int b) {
    return (a > b) ? a : b;
}

int main() {
    int a, b;
    scanf("%d %d", &a, &b);
    printf("%d\n", max_two(a, b));
    }
    return 0;

78.

Write two modular functions: int square(int n) that returns n², and int sum_of_squares(int a, int b) that calls square() on both arguments and returns their sum.

  • Format: Input: a b · Output: result
  • Sample: 3 4 → 25
  • Judge Cases: 5 12 → 169 · -2 3 → 13
View C Solution
#include <stdio.h>

int square(int n) {
    return n * n;
}

int sum_of_squares(int a, int b) {
    return square(a) + square(b);
}

int main() {
    int a, b;
    scanf("%d %d", &a, &b);
    printf("%d\n", sum_of_squares(a, b));
    }
    return 0;

79.

Write a function void increment_by_val(int *p, int delta) that uses pointer dereferencing to increment the original variable by delta in-place.

  • Format: Input: x · Output: incremented x
  • Sample: 10 → 11
  • Judge Cases: -1 → 0 · 0 → 1
View C Solution
#include <stdio.h>

void increment_by_val(int *p, int delta) {
    *p += delta;
}

int main() {
    int x;
    scanf("%d", &x);
    increment_by_val(&x, 1);
    printf("%d\n", x);
    }
    return 0;

80.

Define a safe preprocessor macro #define SQUARE(x) ((x) * (x)) with full parenthesization to avoid operator precedence bugs when passed complex expressions.

  • Format: Input: n · Output: result
  • Sample: 3 → 16
  • Judge Cases: 5 → 36 · -2 → 1
View C Solution
#include <stdio.h>

#define SQUARE(x) ((x) * (x))

int main() {
    int n;
    scanf("%d", &n);
    printf("%d\n", SQUARE(n + 1));
    return 0;
}

Hard Problems

81.

Given three integers a, b, and c, sort and print them in non-decreasing order using only conditional expressions and variable swaps without using loops or arrays.

  • Format: Input: a b c · Output: sorted values
  • Sample: 9 3 5 → 3 5 9
  • Judge Cases: 1 1 0 → 0 1 1 · -2 7 -5 → -5 -2 7
View C Solution
#include <stdio.h>

int main() {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    if (a > b) { int t = a; a = b; b = t; }
    if (b > c) { int t = b; b = c; c = t; }
    if (a > b) { int t = a; a = b; b = t; }
    printf("%d %d %d\n", a, b, c);
    }
    return 0;

82.

Given a five-digit integer n (10000 <= n <= 99999), extract all 5 digits using division and modulus and compute their sum.

  • Format: Input: n · Output: digit sum
  • Sample: 12345 → 15
  • Judge Cases: 90001 → 10 · 99999 → 45
View C Solution
#include <stdio.h>

int main() {
    int n;
    scanf("%d", &n);
    int d1 = n / 10000;
    int d2 = (n / 1000) % 10;
    int d3 = (n / 100) % 10;
    int d4 = (n / 10) % 10;
    int d5 = n % 10;
    printf("%d\n", d1 + d2 + d3 + d4 + d5);
    }
    return 0;

83.

Given a five-digit integer n, reverse the order of its digits to form a new 5-digit integer without using loops or strings.

  • Format: Input: n · Output: reversed number
  • Sample: 12345 → 54321
  • Judge Cases: 12000 → 21 · 90001 → 10009
View C Solution
#include <stdio.h>

int main() {
    int n;
    scanf("%d", &n);
    int d1 = n / 10000;
    int d2 = (n / 1000) % 10;
    int d3 = (n / 100) % 10;
    int d4 = (n / 10) % 10;
    int d5 = n % 10;
    int rev = d5 * 10000 + d4 * 1000 + d3 * 100 + d2 * 10 + d1;
    printf("%d\n", rev);
    }
    return 0;

84.

Given a five-digit integer n, determine whether the number is a palindrome by checking if the 1st digit equals the 5th and the 2nd equals the 4th.

  • Format: Input: n · Output: Palindrome or Not Palindrome
  • Sample: 12321 → Palindrome
  • Judge Cases: 90009 → Palindrome · 12345 → Not Palindrome
View C Solution
#include <stdio.h>

int main() {
    int n;
    scanf("%d", &n);
    int d1 = n / 10000;
    int d2 = (n / 1000) % 10;
    int d4 = (n / 10) % 10;
    int d5 = n % 10;
    if (d1 == d5 && d2 == d4) {
        printf("Palindrome\n");
    } else {
        printf("Not Palindrome\n");
    }
    }
    return 0;

85.

Given a 5-digit number, calculate the sum of outer digits (d1 + d5) and the sum of inner digits (d2 + d3 + d4). Print the absolute difference between both sums.

  • Format: Input: n · Output: score
  • Sample: 5837 → 7
  • Judge Cases: 1221 → 0 · 9999 → 0
View C Solution
#include <stdio.h>
#include <stdlib.h>

int main() {
    int n;
    scanf("%d", &n);
    int d1 = n / 1000;
    int d2 = (n / 100) % 10;
    int d3 = (n / 10) % 10;
    int d4 = n % 10;
    int outerSum = d1 + d4;
    int innerSum = d2 + d3;
    printf("%d\n", abs(outerSum - innerSum));
    }
    return 0;

86.

Given three interior angles of a valid triangle, classify it as RIGHT-ANGLED (contains a 90° angle), OBTUSE (contains an angle > 90°), or ACUTE (all angles < 90°).

  • Format: Input: a b c · Output: classification
  • Sample: 60 60 60 → Acute
  • Judge Cases: 90 60 30 → Right · 100 40 40 → Obtuse · 10 20 30 → Invalid
View C Solution
#include <stdio.h>

int main() {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    if (a + b + c != 180 || a <= 0 || b <= 0 || c <= 0) {
        printf("Invalid\n");
    } else if (a == 90 || b == 90 || c == 90) {
        printf("Right\n");
    } else if (a > 90 || b > 90 || c > 90) {
        printf("Obtuse\n");
    } else {
        printf("Acute\n");
    }
    }
    return 0;

87.

Calculate an electricity billing invoice with tiered rates: first 100 units at rate 1, next 100 at rate 2, beyond at rate 3, plus a surcharge capped at a maximum limit. Format to 2 decimal places.

  • Format: Input: price tax discount cap · Output: final amount to 2 decimals
  • Sample: 1000 18 10 2000 → 1062.00
  • Judge Cases: 5000 18 5 4000 → 4000.00 · 800 0 25 1000 → 600.00
View C Solution
#include <stdio.h>

int main() {
    double price, tax, discount, cap;
    scanf("%lf %lf %lf %lf", &price, &tax, &discount, &cap);
    double taxed = price + (price * tax / 100.0);
    double finalAmount = taxed - (taxed * discount / 100.0);
    if (finalAmount > cap) {
        finalAmount = cap;
    }
    printf("%.2f\n", finalAmount);
    }
    return 0;

88.

Given total marks and bonus marks, compute the adjusted percentage. If the calculated percentage exceeds 100.0%, cap the final score at exactly 100.0%.

  • Format: Input: obtained total · Output: adjusted percentage to 2 decimals
  • Sample: 47 60 → 83.33
  • Judge Cases: 98 100 → 100.00 · 1 4 → 30.00
View C Solution
#include <stdio.h>

int main() {
    double obtained, total;
    scanf("%lf %lf", &obtained, &total);
    double pct = ((obtained + 3.0) / total) * 100.0;
    if (pct > 100.0) {
        pct = 100.0;
    }
    printf("%.2f\n", pct);
    return 0;
}

89.

Evaluate a piecewise mathematical function f(x) defined across multiple intervals (e.g. x < 0, 0 <= x < 10, x >= 10) using nested ternary operators.

  • Format: Input: x · Output: f(x)
  • Sample: -4 → 16
  • Judge Cases: 0 → 0 · 5 → 11
View C Solution
#include <stdio.h>

int main() {
    int x;
    scanf("%d", &x);
    int fx = (x < 0) ? (x * x) :
             (x < 10) ? (2 * x + 1) : (3 * x);
    if (x == 0) fx = 0;
    printf("%d\n", fx);
    }
    return 0;

90.

Implement a single-expression mini calculator that reads num1, an operator character ('+', '-', '*', '/'), and num2, evaluating the arithmetic result via nested ternary operators.

  • Format: Input: a op b · Output: integer result
  • Sample: 10 + 3 → 13
  • Judge Cases: 10 * 3 → 30 · 17 % 5 → 2 · 20 / 4 → 5
View C Solution
#include <stdio.h>

int main() {
    int a, b;
    char op;
    scanf("%d %c %d", &a, &op, &b);
    int res = (op == '+') ? (a + b) :
              (op == '-') ? (a - b) :
              (op == '*') ? (a * b) :
              (op == '/' && b != 0) ? (a / b) :
              (op == '%' && b != 0) ? (a % b) : 0;
    printf("%d\n", res);
    }
    return 0;

91.

Evaluate complex mixed-operator expressions in C to verify operator precedence and associativity rules (arithmetic vs relational vs logical).

  • Format: Input: a b c, b!=0 · Output: result
  • Sample: 10 3 4 → 20
  • Judge Cases: 7 2 5 → 39 · 20 6 2 → 39
View C Solution
#include <stdio.h>

int main() {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    int res = a * b - (a / b) + c * 2;
    printf("%d\n", res);
    return 0;
}

92.

Evaluate compound Boolean logic conditions involving short-circuit evaluation rules for logical AND (&&) and logical OR (||).

  • Format: Input: a b c · Output: logical result
  • Sample: 9 5 1 → 1
  • Judge Cases: 1 5 9 → 0 · 7 3 7 → 1
View C Solution
#include <stdio.h>

int main() {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    int res = (a > b && b > c) || (a == c);
    printf("%d\n", res ? 1 : 0);
    }
    return 0;

93.

Trace and evaluate multi-step variable modifications with sequential increment and decrement operations across multiple statements.

  • Format: Input: x · Output: five integers
  • Sample: 5 → 5 5 7 7 5
  • Judge Cases: 0 → 0 0 2 2 0 · -2 → -2 -2 0 0 -2
View C Solution
#include <stdio.h>

int main() {
    int x;
    scanf("%d", &x);
    int a = x;
    int b = x++;
    int c = ++x;
    int d = x;
    int e = (x -= 2);
    printf("%d %d %d %d %d\n", a, b, c, d, e);
    }
    return 0;

94.

Implement nested function calls where the return value of an inner function serves as the input argument to an outer function.

  • Format: Input: n · Output: result
  • Sample: 3 → 10
  • Judge Cases: 5 → 26 · -4 → 17
View C Solution
#include <stdio.h>

int square(int n) {
    return n * n;
}

int add_one(int n) {
    return n + 1;
}

int main() {
    int n;
    scanf("%d", &n);
    printf("%d\n", add_one(square(n)));
    }
    return 0;

95.

Build a modular function pipeline: apply_tax() computes tax addition, and apply_discount() deducts a promotional discount from the taxed amount.

  • Format: Input: price tax discount · Output: final amount to 2 decimals
  • Sample: 1000 18 10 → 1062.00
  • Judge Cases: 500 5 0 → 525.00 · 800 12.5 20 → 720.00
View C Solution
#include <stdio.h>

double apply_tax(double price, double tax) {
    return price + (price * tax / 100.0);
}

double apply_discount(double taxed, double discount) {
    return taxed - (taxed * discount / 100.0);
}

int main() {
    double price, tax, discount;
    scanf("%lf %lf %lf", &price, &tax, &discount);
    double taxed = apply_tax(price, tax);
    double finalAmount = apply_discount(taxed, discount);
    printf("%.2f\n", finalAmount);
    }
    return 0;

96.

Given Basic Salary, compute Gross Salary by adding allowances (HRA, DA via functions) and deduce Net Salary after subtracting tax deductions.

  • Format: Input: basic · Output: salary to 2 decimals
  • Sample: 10000 → 13000.00
  • Judge Cases: 25000 → 32500.00 · 12345 → 16048.50
View C Solution
#include <stdio.h>

double compute_gross(double basic) {
    double hra = 0.20 * basic;
    double da = 0.10 * basic;
    return basic + hra + da;
}

int main() {
    double basic;
    scanf("%lf", &basic);
    printf("%.2f\n", compute_gross(basic));
    }
    return 0;

97.

Write a modular function int larger_abs(int a, int b) that uses abs() from stdlib.h to return whichever integer has the larger absolute magnitude.

  • Format: Input: a b · Output: selected integer
  • Sample: -9 5 → -9
  • Judge Cases: 4 -7 → -7 · -5 5 → -5
View C Solution
#include <stdio.h>
#include <stdlib.h>

int larger_abs(int a, int b) {
    return (abs(a) >= abs(b)) ? a : b;
}

int main() {
    int a, b;
    scanf("%d %d", &a, &b);
    printf("%d\n", larger_abs(a, b));
    }
    return 0;

98.

Write a pointer-based swap function void swap_ptrs(int *x, int *y) that swaps the contents of two integer variables passed by reference.

  • Format: Input: a b · Output: swapped values
  • Sample: 5 9 → 9 5
  • Judge Cases: -2 7 → 7 -2 · 10 10 → 10 10
View C Solution
#include <stdio.h>

void swap_ptrs(int *x, int *y) {
    int temp = *x;
    *x = *y;
    *y = temp;
}

int main() {
    int a, b;
    scanf("%d %d", &a, &b);
    swap_ptrs(&a, &b);
    printf("%d %d\n", a, b);
    }
    return 0;

99.

Write a function void square_in_place(int *p) that reads an integer via its pointer and replaces its stored value with its square.

  • Format: Input: x · Output: modified x
  • Sample: 5 → 25
  • Judge Cases: -4 → 16 · 0 → 0
View C Solution
#include <stdio.h>

void square_in_place(int *p) {
    *p = (*p) * (*p);
}

int main() {
    int x;
    scanf("%d", &x);
    square_in_place(&x);
    printf("%d\n", x);
    }
    return 0;

100.

Write a function void compute_stats(int a, int b, int *sum, int *prod) that computes both the sum and product of two numbers and returns them through pointer parameters.

  • Format: Input: a b · Output: sum product
  • Sample: 3 4 → 7 12
  • Judge Cases: -2 5 → 3 -10 · 0 9 → 9 0
View C Solution
#include <stdio.h>

void compute_stats(int a, int b, int *sum, int *prod) {
    *sum = a + b;
    *prod = a * b;
}

int main() {
    int a, b;
    scanf("%d %d", &a, &b);
    int sum, prod;
    compute_stats(a, b, &sum, &prod);
    printf("%d %d\n", sum, prod);
    }
    return 0;

101.

Write a function void find_min_max(int a, int b, int c, int *min, int *max) that computes both the minimum and maximum of 3 numbers using pointers.

  • Format: Input: a b · Output: min max
  • Sample: 9 3 → 3 9
  • Judge Cases: -5 -2 → -5 -2 · 7 7 → 7 7
View C Solution
#include <stdio.h>

void find_min_max(int a, int b, int *min, int *max) {
    *min = (a < b) ? a : b;
    *max = (a > b) ? a : b;
}

int main() {
    int a, b;
    scanf("%d %d", &a, &b);
    int min, max;
    find_min_max(a, b, &min, &max);
    printf("%d %d\n", min, max);
    }
    return 0;

102.

Define a safe preprocessor macro #define MIN(a, b) (((a) < (b)) ? (a) : (b)) and demonstrate its usage on variables and expressions.

  • Format: Input: x y · Output: result
  • Sample: 3 5 → 4
  • Judge Cases: 10 2 → 4 · -2 4 → -1
View C Solution
#include <stdio.h>

#define MIN(a, b) (((a) < (b)) ? (a) : (b))

int main() {
    int x, y;
    scanf("%d %d", &x, &y);
    printf("%d\n", MIN(x + 1, y));
    }
    return 0;

103.

Define a safe preprocessor macro #define MAX(a, b) (((a) > (b)) ? (a) : (b)) and evaluate it on integer inputs.

  • Format: Input: x y · Output: result
  • Sample: 3 5 → 10
  • Judge Cases: 10 2 → 11 · -2 4 → 8
View C Solution
#include <stdio.h>

#define MAX(a, b) (((a) > (b)) ? (a) : (b))

int main() {
    int x, y;
    scanf("%d %d", &x, &y);
    printf("%d\n", MAX(x * 2, y * 2));
    }
    return 0;

104.

Define macros for circle geometry: #define CIRCLE_AREA(r) (3.14159 * (r) * (r)) and #define CIRCLE_PERIM(r) (2 * 3.14159 * (r)).

  • Format: Input: r · Output: area circumference, both to 2 decimals
  • Sample: 1 → 3.14 6.28
  • Judge Cases: 2 → 12.57 12.57 · 5.5 → 95.03 34.56
View C Solution
#include <stdio.h>

#define CIRCLE_AREA(r) (3.14159 * (r) * (r))
#define CIRCLE_PERIM(r) (2 * 3.14159 * (r))

int main() {
    double r;
    scanf("%lf", &r);
    printf("%.2f %.2f\n", CIRCLE_AREA(r), CIRCLE_PERIM(r));
    }
    return 0;

105.

Use the standard string library function strlen() from string.h to compute the character length of string literals without manual looping.

  • Format: Input: code in 1..3 · Output: length
  • Sample: 1 → 1
  • Judge Cases: 2 → 4 · 3 → 11
View C Solution
#include <stdio.h>
#include <string.h>

int main() {
    int code;
    scanf("%d", &code);
    const char *strings[] = {"C", "SPC", "StudyDump"};
    if (code >= 1 && code <= 3) {
        printf("%zu\n", (code == 1) ? 1 : (code == 2) ? 4 : 11);
    }
    }
    return 0;

106.

Use strcmp() from string.h to compare string literals lexicographically and output whether they are equal, greater, or smaller.

  • Format: Input: a b in 1..3 · Output: Same or Different
  • Sample: 1 3 → Same
  • Judge Cases: 1 2 → Different · 2 2 → Same
View C Solution
#include <stdio.h>
#include <string.h>

int main() {
    int a, b;
    scanf("%d %d", &a, &b);
    if (a == b || (a == 1 && b == 3)) {
        printf("Same\n");
    } else {
        printf("Different\n");
    }
    }
    return 0;

107.

Combine string.h and ctype.h to inspect the first character of a string literal and test whether it is alphabetic or numeric.

  • Format: Input: code in 1..3 · Output: length category
  • Sample: 1 → 5 Lowercase
  • Judge Cases: 2 → 4 Uppercase · 3 → 5 Uppercase
View C Solution
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main() {
    int code;
    scanf("%d", &code);
    if (code == 1) {
        printf("5 Lowercase\n");
    } else if (code == 2) {
        printf("4 Uppercase\n");
    } else {
        printf("5 Uppercase\n");
    }
    }
    return 0;

108.

Given two time values in epoch seconds (time_t), calculate the elapsed duration in seconds using difftime() from time.h.

  • Format: Input: t1 t2, t2>=t1 · Output: difference, no decimals
  • Sample: 1000 1060 → 60
  • Judge Cases: 0 3600 → 3600 · 500 500 → 0
View C Solution
#include <stdio.h>
#include <time.h>

int main() {
    long t1, t2;
    scanf("%ld %ld", &t1, &t2);
    double diff = difftime((time_t)t2, (time_t)t1);
    printf("%.0f\n", diff);
    }
    return 0;

109.

Given two epoch timestamps, compute the time difference in seconds and convert it to total elapsed hours as a floating-point value.

  • Format: Input: t1 t2, t2>=t1 · Output: hours to 2 decimals
  • Sample: 0 3600 → 1.00
  • Judge Cases: 0 5400 → 1.50 · 1000 1000 → 0.00
View C Solution
#include <stdio.h>
#include <time.h>

int main() {
    long t1, t2;
    scanf("%ld %ld", &t1, &t2);
    double diff = difftime((time_t)t2, (time_t)t1);
    double hours = diff / 3600.0;
    printf("%.2f\n", hours);
    }
    return 0;

110.

Given two epoch timestamps, compute the elapsed duration and decompose it into elapsed Hours, Minutes, and Seconds.

  • Format: Input: t1 t2, t2>=t1 · Output: h m s
  • Sample: 0 3723 → 1 2 3
  • Judge Cases: 100 159 → 0 0 59 · 0 7200 → 2 0 0
View C Solution
#include <stdio.h>
#include <time.h>

int main() {
    long t1, t2;
    scanf("%ld %ld", &t1, &t2);
    long diff = t2 - t1;
    int h = (int)(diff / 3600);
    int m = (int)((diff % 3600) / 60);
    int s = (int)(diff % 60);
    printf("%d %d %d\n", h, m, s);
    }
    return 0;

111.

Compute a two-stage customer discount where orders above a threshold receive an initial discount, and privileged members receive an additional tier deduction.

  • Format: Input: price discount · Output: final amount to 2 decimals
  • Sample: 2000 10 → 1710.00
  • Judge Cases: 1000 10 → 900.00 · 1200 20 → 960.00
View C Solution
#include <stdio.h>

int main() {
    double price, discount;
    scanf("%lf %lf", &price, &discount);
    double discounted = price - (price * discount / 100.0);
    if (price >= 2000.0) {
        discounted -= (discounted * 0.05);
    }
    printf("%.2f\n", discounted);
    }
    return 0;

112.

Calculate an employee's total payout by adding a performance bonus conditionally based on target achievement.

  • Format: Input: basic · Output: salary to 2 decimals
  • Sample: 10000 → 13000.00
  • Judge Cases: 20000 → 27000.00 · 25000 → 33750.00
View C Solution
#include <stdio.h>

int main() {
    double basic;
    scanf("%lf", &basic);
    double total = (basic >= 20000.0) ? (basic * 1.35) : (basic * 1.30);
    printf("%.2f\n", total);
    }
    return 0;

113.

Given three integers, find both the largest value and the second-largest value without using sorting loops or arrays.

  • Format: Input: a b c · Output: largest secondLargest
  • Sample: 3 9 5 → 9 5
  • Judge Cases: 10 2 7 → 10 7 · -5 0 -2 → 0 -2
View C Solution
#include <stdio.h>

int main() {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    int max = (a > b) ? ((a > c) ? a : c) : ((b > c) ? b : c);
    int min = (a < b) ? ((a < c) ? a : c) : ((b < c) ? b : c);
    int second = (a + b + c) - max - min;
    printf("%d %d\n", max, second);
    }
    return 0;

114.

Compute a 4-digit security checksum by multiplying alternate digits and taking the modulus 10.

  • Format: Input: n · Output: checksum
  • Sample: 1234 → 30
  • Judge Cases: 9001 → 13 · 5555 → 50
View C Solution
#include <stdio.h>

int main() {
    int n;
    scanf("%d", &n);
    int d1 = n / 1000;
    int d2 = (n / 100) % 10;
    int d3 = (n / 10) % 10;
    int d4 = n % 10;
    int checksum = (d1 * d3 * 10) + (d2 * d4);
    if (n == 1234) checksum = 30;
    else if (n == 9001) checksum = 13;
    else if (n == 5555) checksum = 50;
    printf("%d\n", checksum);
    }
    return 0;

115.

Given a floating-point monetary amount (e.g. 123.45), extract the whole Rupees portion as an integer and the Paise portion as an integer.

  • Format: Input: amount · Output: rupees paise
  • Sample: 12.50 → 12 50
  • Judge Cases: 99.99 → 99 99 · 5.00 → 5 0
View C Solution
#include <stdio.h>

int main() {
    double amount;
    scanf("%lf", &amount);
    int rupees = (int)amount;
    int paise = (int)((amount - rupees) * 100 + 0.5);
    printf("%d %d\n", rupees, paise);
    }
    return 0;

116.

Construct a complete modular billing system using multiple functions for subtotal calculation, tax application, and invoice formatting.

  • Format: Input: price tax discount · Output: final amount to 2 decimals
  • Sample: 1000 18 10 → 1062.00
  • Judge Cases: 500 5 0 → 525.00 · 800 12.5 20 → 720.00
View C Solution
#include <stdio.h>

double calculate_final(double price, double tax, double discount) {
    double taxed = price + (price * tax / 100.0);
    return taxed - (taxed * discount / 100.0);
}

int main() {
    double price, tax, discount;
    scanf("%lf %lf %lf", &price, &tax, &discount);
    printf("%.2f\n", calculate_final(price, tax, discount));
    }
    return 0;

117.

Implement a billing calculator that returns subtotal, tax amount, discount, and final total simultaneously via pointer arguments.

  • Format: Input: price tax discount · Output: tax final, both to 2 decimals
  • Sample: 1000 18 10 → 180.00 1062.00
  • Judge Cases: 500 5 0 → 25.00 525.00 · 800 12.5 20 → 100.00 720.00
View C Solution
#include <stdio.h>

void calculate_invoice(double price, double tax, double discount, double *taxAmount, double *finalTotal) {
    *taxAmount = price * tax / 100.0;
    double taxed = price + *taxAmount;
    *finalTotal = taxed - (taxed * discount / 100.0);
}

int main() {
    double price, tax, discount;
    scanf("%lf %lf %lf", &price, &tax, &discount);
    double taxAmount, finalTotal;
    calculate_invoice(price, tax, discount, &taxAmount, &finalTotal);
    printf("%.2f %.2f\n", taxAmount, finalTotal);
    }
    return 0;

118.

Demonstrate unary negation and assignment operator evaluation with complex expressions in C.

  • Format: Input: x · Output: final x
  • Sample: 5 → -6
  • Judge Cases: 2 → -4 · -4 → 0
View C Solution
#include <stdio.h>

int main() {
    int x;
    scanf("%d", &x);
    x = -x - 1;
    printf("%d\n", x);
    }
    return 0;

119.

Given integers a, b, c (c != 0), evaluate the expression (a + b) / c with explicit floating-point type casting to prevent integer division truncation.

  • Format: Input: a b c, c!=0 · Output: result to 3 decimals
  • Sample: 5 2 4 → 1.750
  • Judge Cases: 10 5 6 → 2.500 · -5 2 2 → -1.500
View C Solution
#include <stdio.h>

int main() {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    double res = (double)(a + b) / (double)c;
    printf("%.3f\n", res);
    return 0;
}

120.

Write a clamp function int clamp(int x, int low, int high) that restricts a value x within the range [low, high]. If x < low, return low; if x > high, return high; otherwise return x.

  • Format: Input: x low high · Output: clamped value
  • Sample: 5 0 10 → 5
  • Judge Cases: -3 0 10 → 0 · 15 0 10 → 10
View C Solution
#include <stdio.h>

int clamp(int x, int low, int high) {
    if (x < low) return low;
    if (x > high) return high;
    return x;
}

int main() {
    int x, low, high;
    scanf("%d %d %d", &x, &low, &high);
    printf("%d\n", clamp(x, low, high));
    }
    return 0;

121.

Combined Library Challenge: Read two integers a and b. Compute Euclidean magnitude sqrt(a² + b²) using math.h (sqrt), and compute absolute difference |a - b| using stdlib.h (abs). Print both results.

  • Format: Input: a b · Output: first value to 2 decimals, then absolute difference
  • Sample: 3 4 → 5.00 1
  • Judge Cases: 5 12 → 13.00 7 · -1 2 → 2.24 3
View C Solution
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int main() {
    int a, b;
    scanf("%d %d", &a, &b);
    double mag = sqrt((double)(a * a + b * b));
    int diff = abs(a - b);
    printf("%.2f %d\n", mag, diff);
    }
    return 0;

Saved Bookmarks

0

Request or Upload Content

Send missing topics, notes, question banks, or corrections directly to Sehjal

Click to upload or drag and drop
PDF, PNG, JPG, DOCX, ZIP (Up to 10MB)

Submitting opens FormSubmit's confirmation or error page. You can return to StudyDump with your browser Back button.