0% found this document useful (0 votes)
47 views

Chapter 3 - Type C - Programming Based Questions

This document discusses 9 programming exercises involving writing functions in C. The exercises include: 1) Writing functions to convert dollars to rupees with and without return values. 2) Writing a function to calculate the volume of a box with default height, width, and length parameters. 3) Writing functions to calculate the cube of a number and to compare two characters. 4-9) Writing additional functions to generate random numbers within a range, compare string lengths, calculate nth roots, generate random n-digit numbers, return the number with the lowest ones digit from two inputs, and generate an equidistant series from start and end values.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views

Chapter 3 - Type C - Programming Based Questions

This document discusses 9 programming exercises involving writing functions in C. The exercises include: 1) Writing functions to convert dollars to rupees with and without return values. 2) Writing a function to calculate the volume of a box with default height, width, and length parameters. 3) Writing functions to calculate the cube of a number and to compare two characters. 4-9) Writing additional functions to generate random numbers within a range, compare string lengths, calculate nth roots, generate random n-digit numbers, return the number with the lowest ones digit from two inputs, and generate an equidistant series from start and end values.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

CHAPTER 3 WORKING WITH FUNCTIONS

TYPE C – PROGRAMMING BASED QUESTIONS

1. Write a function that takes amount-in-dollars and dollar-to-rupee conversion price ; it then
returns the amount converted to rupees. Create the function in both void and non-void forms
CODING:

OUTPUT:

2. Write a function to calculate volume of a box with appropriate default values for its parameters.
Your function should have the following input parameters: (a) length of box ; (b) width of box ;
(c) height of box.
CODING:

OUTPUT:

1
3. A function that takes a number as argument and calculates cube for it. The function does not
return a value. If there is no value passed to the function in function call, the function should
calculate cube of 2.
(ii) A function that takes two char arguments and returns True if both the arguments are equal
otherwise False.
Test both these functions by giving appropriate function call statements.

CODING: OUTPUT

4. Write a function that receives two numbers and generates a random number from that range
Using this function, the main program should be able to print three numbers randomly.

CODING:

OUTPUT:

2
5. Write a function that receives two string arguments & checks whether they are same-length strings .

CODING:

OUTPUT:

6. Write a function namely nthRoot () that receives two parameters x and n and returns nth root of
x i.e., X**1/n . The default value of n is 2

CODING:

OUTPUT:

3
7. Write a function that takes a number n and then returns a randomly generated number having
exactly n digits (not starting with zero) eg ., if n is 2 then function can randomly return a number
10-99 but 07, 02 etc. are not valid two-digit numbers.

CODING:

OUTPUT:

8. Write a function that takes two numbers and returns the number that has minimum one's digit.
[For example, if numbers passed are 491 and 278, then the function will return 491 because it has
got minimum one's digit out of two given numbers (491's 1 is < 278's 8)].
CODING:

OUTPUT:

4
9. Write a program that generates a series using a function which takes first and last values of the
series and then generates four terms that are equidistant e.g., if two numbers passed are 1 and 7
then function returns 1 3 5 7

CODING:

OUTPUT:

You might also like