Lab Report CSE162.5 Blank
Lab Report CSE162.5 Blank
Lab Report
Submitted By
Name :
Batch :
Student Code :
Section :
Submitted To
Tashreef Muhammad
Lecturer, Dept. of CSE,
Southeast University, Bangladesh
Table of Contents
Problem 01:--------------------------------------------------------------------------------------------------
Problem 02:--------------------------------------------------------------------------------------------------
Problem 03:--------------------------------------------------------------------------------------------------
Problem 04:--------------------------------------------------------------------------------------------------
Problem 01:
Problem Link:
Divisibility Problem
Solution Approach:
Solution Code:
#include <stdio.h>
int main()
{
int t;
scanf("%d", &t); // Read the number of test cases
while (t--) {
long long a, b;
scanf("%lld %lld", &a, &b); // Read integers a and b
if (remainder == 0) {
printf("0\n"); // If remainder is 0, no moves are needed
} else {
long long moves = b - remainder; // Calculate the moves needed to make a
divisible by b
printf("%lld\n", moves);
}
}
return 0;
}
Problem 02:
Problem Link:
Candies and Two Sisters
Solution Approach:
Input Parsing: We start by reading the number of test cases t.
Loop Through Test Cases: For each test case:
We read the integer n, the total number of candies.
Calculate the number of ways to distribute candies such that Alice gets more
than Betty:
Since Alice needs to get more than Betty, the valid distributions occur when
Alice gets from (n/2 + 1) to (n - 1) candies. This can be simplified to (n - 1) / 2,
which represents the number of possible ways.
Output: Print the calculated number of ways for each test case.
This solution is efficient and meets the conditions of the problem.
Solution Code:
#include <stdio.h>
int main() {
int t;
scanf("%d", &t); // Read the number of test cases
while (t--) {
long long n;
scanf("%lld", &n); // Read the number of candies for each test case
printf("%lld\n", ways);
}
return 0;
}
Problem 03:
Problem Link:
Medium Number
Solution Approach:
Input Parsing: We first read the number of test cases t.
Loop Through Each Test Case:
For each test case, we read three distinct integers a, b, and c.
We then check which integer is the middle number:
If a is between b and c, then a is the middle.
If b is between a and c, then b is the middle.
Otherwise, c is the middle.
Output: We print the middle number for each test case.
This approach ensures we find the medium number in a straightforward way.
Solution Code:
#include <stdio.h>
int main() {
int t;
scanf("%d", &t); // Read the number of test cases
while (t--) {
int a, b, c;
scanf("%d %d %d", &a, &b, &c); // Read three distinct integers
return 0;
}
Problem 04:
Problem Link:
Inverse Prefix Sum
Solution Approach:
Read Input:
The program starts by reading an integer N, which is the length of the sequence S.
Declare Arrays:
Two arrays are declared:
S (to store the input sequence) and
A (to store the new sequence we're calculating).
Fill Sequence S:
The program reads N numbers from the input and stores them in the S array.
Calculate Sequence A:
The first element of 𝐴 is set to be the same as the first element of S, and this value is
printed.
For the remaining elements in A, each A[i] is calculated as the difference between S[i]
and S[i−1] (the previous element of S).
This difference is then printed immediately after it is calculated, with a space in
between each printed element.
Output:
The entire sequence A is printed on a single line.
Solution Code:
#include <stdio.h>
int main() {
int N;
scanf("%d", &N); // Read the length of the sequence S
return 0;
}