Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Assignment Module: C Programming Language Learning Units: a) Introduction to C language b) Operators and basic types c) Control flow 1.

Write a Program to input three positive integers representing the sides of a triangle and determine whether they form a valid triangle or not. 2. To round off a floating point number to the nearest integer, one adds 0.5 to the number and truncates it to an integer. Using this knowledge, try to figure out how to round a floating point number to the nearest tenth, hundredth, etc and implement the same. 3. Write a program that repeatedly ask the user to input a negative or positive number, and then echoes it. When the value 0 is entered, the program should terminate. It also keeps a count of how many of the numbers are positive and how many are negative. The program should print out these two totals immediately before terminating. 4. Write a program to which accepts a number n, and then finds the sum of the integers from 1 to 2, then from 1 to 3, then 1 to 4 and so forth until it displays the sum of the integers from 1 to n. For example, if the input is 5, the output will be 1 3 6 10 15 5 Write a program to implement the Russian Peasant Problem for multiplying two positive numbers using while or dowhile loop. Russian Peasant problem is a method of multiplying two numbers together, using only division by 2, multiplication by 2 and addition. For example, if the numbers are 17 and 19are to be multiplied together, they are put at the head of two columns: The first number is divided by 2 and the second number is multiplied by 2. This process is continued until the number on the left reduces to 1.

17 8 4 2 1

19 38(ignored) 76 (ignored) 152(ignored) 304

All the numbers on the right column which lie on the right of even numbers in the left hand Column is ignored. The remaining numbers on the right hand column are then added together: 19 + 304 -----323, which is the result of 17 times 19.

Write a program to calculate the nth term (integers only) of arithmetic progression using only bitwise operations as fundamental operations (i.e. you dont have to use multiplication or addition operators provided by C). User will give first term of the progression, common difference between successive terms and which term he seeks to get in A.P. The program should compute the term and print it.

Note: First think how you can implement the addition and multiplication using bitwise operators. Then you can apply this concept to find the solution of above problem.

You might also like