0% found this document useful (0 votes)
8 views1 page

Programming Assignments for Lab ESCCS291

This document outlines a programming assignment for the University of Engineering and Management, Kolkata, focusing on various problem-solving tasks. It includes instructions for writing programs that cover topics such as calculating the area of a triangle, finding distances between points, checking for even or odd numbers, determining grades based on marks, and calculating income tax. Each task specifies the required input and expected output, providing a comprehensive guide for students to practice their programming skills.

Uploaded by

rahul banerjee
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views1 page

Programming Assignments for Lab ESCCS291

This document outlines a programming assignment for the University of Engineering and Management, Kolkata, focusing on various problem-solving tasks. It includes instructions for writing programs that cover topics such as calculating the area of a triangle, finding distances between points, checking for even or odd numbers, determining grades based on marks, and calculating income tax. Each task specifies the required input and expected output, providing a comprehensive guide for students to practice their programming skills.

Uploaded by

rahul banerjee
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

University of Engineering and Management, Kolkata

Assignment-2, Second Semester-2024


Course Name: Programming for Problem Solving Laboratory
Course Code: ESCCS291
1. Write program, which reads a, b and c as sides of a triangle and prints area.
Hint: area = sqrt( s(s-a)(s-b)(s-c) ) and s = (a+b+c)/2] [sqrt(x) will find square root] Input 5 7
10 output 16.24.
2. Write program, which reads x1, y1, x2 and y2 and finds distance between points (x1,y1) and
(x2,y2). input 3, 7, 11, 13 output 10.
3. Write program, which reads a, b and c as sides of a triangle and prints whether angle A is 90 0 or
not. [Hint: if (a2 = = b2+c2) ] [Do not use cos-1 etc]
4. Write a Program to check whether a number is even or odd.
5. Write a Program to test whether any year is Leap year or not
6. A student is awarded Ex grade if he gets more than 90 marks. He is awarded A grade if marks
are between 80 and 89. Similarly range for B, C, D and P are 70-79, 60-69, 50-59, and 35-49
respectively. The student is awarded F grade if he gets less then 35 marks. Program reads marks
of a student and prints his grade.
7. Write a Program to reverse the digits of an integer.
8. Write a Program to print the summation of digits of user given input number.
9. Write a Program to check whether a given number is Palindrome or not.
10. Write a Program to find all the Fibonacci numbers for a given range.
11. Write a Program to find all prime numbers within a given range.
12. Write a Program to calculate the Factorial of any integer.
13. No income tax is to be paid if income is less than 5000. If income is between 5000 and 6000 then
tax is 10% of the amount by which the income exceeds 5000. If income is between 6000 and
15000 then the tax is 100 + 20% of the amount by which the income exceeds 6000. If income is
more than 15000 then the tax is 1900 + 30% of the amount by which the income exceeds 15000.
e.g. if income is 10000 then the tax will be 100 + (10000-6000)*20/100 = 900. Write a program,
which reads income and calculates the income tax.
14. Write a program, which reads a number X and prints a number Y. Y=X+10 if X is 6. Y is X*X if X is
7. Y is 2*X+4 if X is 12. Otherwise Y is X*6-1. (use switch)
15. Write a program, which reads three integers X, Y and Z and prints Y+Z if X is 0. If X is 1 then Y-Z
is printed. If X is 2 then Y*Z is printed. If X is 3 then Y/Z is printed. (use switch)

Common questions

Powered by AI

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 .

You might also like