Programming Assignments for Lab ESCCS291
Programming Assignments for Lab ESCCS291
The program achieves digit reversal by iterating through each digit, isolating it using modulus operation, and constructing the reversed number with addition and multiplication. This iterative approach optimizes computational resources by minimizing operations needed per digit .
The program determines a right angle in a triangle using the condition a² = b² + c², where a is the longest side. This computational approach leverages Pythagoras' theorem to infer a right angle without trigonometric functions, simplifying calculations particularly in programs where cos-1 isn't utilized .
The program computes factorial by multiplying the given integer by all positive integers less than itself, iteratively or recursively. Understanding this computation is vital as factorials are foundational in combinatorics, probability, and complex optimization problems .
The logic follows that a leap year is divisible by 4 but not by 100 unless it is also divisible by 400. This encapsulates the Gregorian calendar's adjustment frequency ensuring proper seasonal alignment over centuries, demonstrating computational handling of complex conditionals .
The program iterates through numbers within the given range and applies divisibility checks to determine primality, typically identifying a number as prime if it isn't divisible by any number other than 1 and itself, optimizing by testing up to the square root .
The program likely uses either iteration or recursion to generate Fibonacci numbers in a specified range, starting from initial known values and building the sequence iteratively. This algorithm is crucial in computer science for its illustrative power in demonstrating recursion and efficiency considerations .
The program calculates tax by applying different percentage rules to segmented income brackets, stepping up through 0% for <5000 to 30% on income exceeding 15000. This model reflects the tax system's progressive structure, illustrating tiered computations that emulate real-world fiscal policies .
Heron's formula calculates the area of a triangle given its three side lengths a, b, and c by first computing the semi-perimeter s = (a+b+c)/2. The area is then determined using the formula: area = sqrt(s(s-a)(s-b)(s-c)). This approach provides an accurate way to calculate the area without needing the triangle's height .
The program determines if a number is even or odd using a modulus operation: if a number n mod 2 equals 0, it is even; otherwise, it is odd. This logic is fundamental in programming for making binary decisions efficiently .
Grades are assigned through a series of if-else statements checking the range in which the marks fall, from Ex for >90 down to F for <35. This illustrates conditional branches in programming effectively to handle non-linear criteria such as grading scales .