Chapter: Function and Pointer | Let us C solution with details description and tutorials

 

Chapter: Function and Pointer | Let us C solution with details description and tutorials |  yashwant kanetkar

Decision Control Structure


 [D] Answer the following:

(a) Write a function to calculate the factorial value of any integer entered through the keyboard.

Show Solutions     Hide Solutions

(b) Write a function power ( a, b ), to calculate the value of a raised to b.

Show Solutions     Hide Solutions

(c) Write a general-purpose function to convert any given year into its roman equivalent. The following table shows the roman equivalents of decimal numbers: Example: Roman equivalent of 1988 is mdcccclxxxviii Roman equivalent of 1525 is mdxxv

Show Solutions     Hide Solutions

(d) Any year is entered through the keyboard. Write a function to determine whether the year is a leap year or not.

Show Solutions     Hide Solutions

(e) A positive integer is entered through the keyboard. Write a function to obtain the prime factors of this number. For example, prime factors of 24 are 2, 2, 2 and 3, whereas prime factors of 35 are 5 and 7.

Show Solutions     Hide Solutions

[F] Answer the following:

(a) Write a function which receives a float and an int from main( ), finds the product of these two and returns the product which is printed through main( ).

Show Solutions     Hide Solutions

(b) Write a function that receives 5 integers and returns the sum, average and standard deviation of these numbers. Call this function from main( ) and print the results in main( ).

Show Solutions     Hide Solutions

(c) Write a function that receives marks received by a student in 3 subjects and returns the average and percentage of these marks. Call this function from main( ) and print the results in main( ).

Show Solutions     Hide Solutions

[J] Attempt the following:

(a) A 5-digit positive integer is entered through the keyboard, write a function to calculate sum of digits of the 5-digit number: (1) Without using recursion (2) Using recursion

Show Solutions     Hide Solutions

(b) A positive integer is entered through the keyboard, write a program to obtain the prime factors of the number. Modify the function suitably to obtain the prime factors recursively.

Show Solutions     Hide Solutions

(c) Write a recursive function to obtain the first 25 numbers of a Fibonacci sequence. In a Fibonacci sequence the sum of two successive terms gives the third term. Following are the first few terms of the Fibonacci sequence: 1 1 2 3 5 8 13 21 34 55 89...

Show Solutions     Hide Solutions

(d) A positive integer is entered through the keyboard, write a function to find the binary equivalent of this number using recursion.

Show Solutions     Hide Solutions

(e) Write a recursive function to obtain the running sum of first 25 natural numbers.

Show Solutions     Hide Solutions

(f) Write a C function to evaluate the series
sin(x)=x-(x^3/3!)+(x^5/5!)-(x^7/7!)+..... to five significant digits.

Show Solutions     Hide Solutions

(g) Given three variables x, y, z write a function to circularly shift their values to right. In other words if x = 5, y = 8, z = 10 after circular shift y = 5, z = 8, x =10 after circular shift y = 5, z = 8 and x = 10. Call the function with variables a, b, c to circularly shift values.

Show Solutions     Hide Solutions

(h) Write a function to find the binary equivalent of a given decimal integer and display it.

Show Solutions     Hide Solutions

(i) If the lengths of the sides of a triangle are denoted by a, b, and c, then area of triangle is given by area=squareroot of(s(s-a)(s-b)(s-c) where, S = ( a + b + c ) / 2

Show Solutions     Hide Solutions

(j) Write a function to compute the distance between two points and use it to develop another function that will compute the area of the triangle whose vertices are A(x1, y1), B(x2, y2), and C(x3, y3). Use these functions to develop a function which returns a value 1 if the point (x, y) lines inside the triangle ABC, otherwise a value 0.

Show Solutions     Hide Solutions

(k) Write a function to compute the greatest common divisor given by Euclid's algorithm, exemplified for J = 1980, K = 1617 as follows: 
1980 / 1617 = 1 , 1980 - 1 * 1617 = 363 
1617 / 363 = 4 , 1617 - 4 * 363 = 165 
363 / 165 = 2 , 363 - 2 * 165 = 33 
5 / 33 = 5 , 165 - 5 * 33 = 0 
Thus, the greatest common divisor is 33.

Show Solutions     Hide Solutions

Comments

Popular posts from this blog

Puppetting on string | Let us C solution with details description and tutorials | yashwant kanetkar

If cost price and selling price of an item is input through the keyboard, write a program to determine whether the seller has made profit or incurred loss. Also determine how much profit he made or loss he incurred