You are on page 1of 5

# IT 311 Foundations of Algorithms & Problem Solving (using C) Problems for Practice Set #1

Before you begin Your main objective is to gain competencies in problem solving using the algorithmic approach and implementing these solutions using the C language. You would attend several face-to-face instructional sessions, learn from the interactive multimedia lessons from the Yogyata Portal, and also go through some online mentoring sessions. The fact, however, is that you would develop strong competencies in problem solving and ability to develop programs in C only when YOU practice problem solving and Learn by Doing! This is Set #1 of the Problems for Practice. By design, the level of difficulty of these problems is kept simple to average. You must attempt all these problems, write algorithms to solve them, write the corresponding C programs, compile them, and check whether this works as intended. Please do not be tempted to slip into complacency by skipping any of these problems or any of the problem-solving steps. Your journey to developing competencies in problem solving using algorithms and C begins here Best Yogyata Team

1 of 5

IT 311 Foundations of Algorithms & Problem Solving (using C) Problems for Practice Set #1

Problem 1.1

Kilograms to Pounds

The user inputs a persons weight in kilograms. It is desired to convert this weight into pounds. Then, the persons weight in kilograms and the weight in pounds must be printed as follows: Weight in Kilograms = 65.5 Weight in Pounds = 144.1

Write a C program that performs this task. Remember that a persons weight cannot be zero or negative.

Problem 1.2

Type of Triangle

Three real numbers supposed to represent the lengths of the three sides of a triangle are input. We must only accept such inputs that enable the formation of a triangle. Once a viable input of three sides of a triangle is available, we must find out whether the triangle is an equilateral triangle, isosceles triangle or a scalene triangle. Write a C program that read the input data, validates it as required, displays the input data, and displays what sort of a triangle it is. Note: A triangle is equilateral if all its three sides are equal. An isosceles triangle is one in which any of its two sides are equal. A scalene triangle is one in which all three sides are distinct.

Problem 1.3

## Converting an Improper Fraction to a Mixed Fraction

In school, we have dealt with fractional numbers. For example, a number of the form 2/3 (pronounced as two-upon-three) is considered to be a proper fraction. Note that the numerator is always less than the denominator. A number of the form 23/3 (pronounced as twenty-three-upon-three) is considered to be an improper fraction. In this case, the numerator is greater than the denominator. An improper fraction can be converted into a mixed fraction. For example, 23/3 can be written as 7 2/3 (pronounced as seven-and-two-upon-three). You are required to take two integers representing the numerator and denominator as input, representing a fraction. Note that the fraction can be positive or negative depending on the sign of the numerator. You are required to display the inputs, and state what sort of a fraction it is. Further, if it is an improper fraction, you must convert this into a mixed fraction and print it. Write a C program that performs this task.

2 of 5

IT 311 Foundations of Algorithms & Problem Solving (using C) Problems for Practice Set #1

Problem 1.4

## Validating an Input Date

Many problems would require dealing with calendar dates, whether it represents today or someones birthday or data of joining an organization or whatever. A date is composed of three quantities that represent the day, month and year. In India, the most common method is to represent a date as dd/mm/yyyy. Here dd is a two digit positive decimal integer representing the day (which can be in the range [1,31] depending on the month it is associated with). The mm is a two digit positive decimal integer in the range [1,12]. The year is represented by a 4 digit positive decimal integer. You are required to take as input three different integers from the user, that ought to represent a date in the form dd/mm/yyyy. Whatever the user inputs, you are to validate the input as being a valid date. You must display the user input in the form dd/mm/yyyy, and also a message stating whether this represents a valid date or not. Note that while reading the three integers from the user, you are not required to read the / character. But while printing, you must include that character. Write a complete C program that performs this task.

Problem 1.5

## Displaying Date Attractively

A user enters three integers representing a date in the form dd/mm/yyyy. First this input must be validated, and only a correct date must be accepted. Your are required to display the input date in the form dd/mm/yyyy. Also, you must display the input date in an attractive manner as follows: The input date is 24/08/1956 An attractive display is 24 August 1956 Write a C program that takes as input three integers representing a date in the form dd/mm/yyyy, display the input as it is, and then display it in an attractive form as shown above.

Problem 1.6

## Birthday & Zodiac Sign

The user enters a birthday in the form dd/mm/yyyy, which needs to be validated and accepted. Then the Zodiac Sign corresponding to that date must be printed, along with the input birthday. The Zodiac Sign to which a particular birthday belongs to is given in the following table.

3 of 5

IT 311 Foundations of Algorithms & Problem Solving (using C) Problems for Practice Set #1

From Date March 21 April 20 May 21 June 21 July 23 August 23 September 23 October 23 November 22 December 22 January 20 February 19

To Date April 19 May 20 June 20 July 22 August 22 September 22 October 22 November 21 December 21 January 19 February 18 March 20

Zodiac Sign Aries Taurus Gemini Cancer Leo Virgo Libra Scorpio Sagittarius Capricorn Aquarius Pisces

Write a C program that takes a birthday as input (note that we need to input only the day and month, since year is not required here) , prints the input in dd/mm form and states the Zodiac Sign of that person.

Problem 1.7

## Days Elapsed Between Two Dates

Two dates in dd/mm/yyyy form are taken as input from the user. The first date input must be earlier than the second date that is input. For example, the two valid dates can be 24/08/1956 and 225/09/2009. It is desired to calculate the total number of days that have elapsed between these two dates. You are required to write a C program that takes as input the two dates, prints the inputs, calculate the days elapsed between the two dates, and prints the days elapsed.

Problem 1.8

## Writing Amount of Money in Words

The user enters an amount of money as input integer in Indian Rupees. For example, the user may enter 22356, indicating that the amount is Rs. 22356. This input must be printed as 4 of 5

IT 311 Foundations of Algorithms & Problem Solving (using C) Problems for Practice Set #1

The input amount in figures is Rs. 22356 The amount in words is Rupees Twenty Two Thousand Three Hundred and Fifty Six Write a C program that takes the money input as integer and performs the above task.

Problem 1.9

## Returning Balance Cash to Customer

A customer purchases merchandise from a shop for a certain amount of money in Indian Rupees. This amount is an integer amount and no Paisa is involved. The amount of money is read as input. The customer can pay that amount only using 500-rupee notes, since she has no other denomination with her. The number of 500-rupee note the customer must pay can be calculated and output. The shopkeeper has with her currency in the denominations of 500, 100, 50, 20, 10, 5, 2 and 1 rupee notes. You are required to write a C program that takes the bill amount as input, displays it, calculates the number of 500-rupee notes the customer has to give, displays it, and then computes the balance to be given. But the balance amount needs to be given to customer in the least number of currency notes. The results should be printed as follows: The amount on the bill = Rs. 234 Number of 500-rupee notes customer gives = 1 Balance to be returned = Rs. 266 Denominations returned: 100-rupee notes = 2 50-rupee notes = 1 10-rupee notes = 1 5-rupee notes = 1 1-rupee notes = 1

Problem 1.10

## Forming Real Number from Two Integer Parts

Two integers are input. The first one can be positive, negative or zero. The second one can be zero or positive, but not negative. For example, let the two numbers be 12 and 5. What we want to do is to form a real number of the form 12.5. If the input number is -25 and 557, the real number formed is 25.557. Write a C program that takes these two integer inputs, forms the real number, displays the two input integers and also the real number formed.

5 of 5