Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
4 views

functions_tutorials

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

functions_tutorials

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

1.

Write a function exchange to interchange the values of two


variables, say x and y. Illustrate the use of this function, in a calling
function. Assume that x and y are defined as global variables.
2. Write a function space(x) that can be used to provide a space of x
positions between two output numbers.
3. The Fibonacci numbers are defined recursively as follows:
F1 = 1
F2 = 1
Fn = F n–1+F n–2, n > 2
Write a function that will generate and print the first n Fibonacci
numbers
4. Write a function prime that returns 1 if its argument is a prime number and
returns zero otherwise.
5. Write a function that will scan a character string passed as an argument and
convert all lowercase characters into their uppercase equivalents.
6. Develop a top_down modular program to implement a calculator. The program should request the
user to input two numbers and display one of the following as per the desire of the user: Provide
separate functions for performing various tasks such as reading, calculating and displaying.
Calculating module should call second level modules to perform the individual mathematical
operations. The main function should have only function calls.
(a) Sum of the numbers
(b) Difference of the numbers
(c) Product of the numbers
(d) Division of the numbers
7. Write a function that can be called to find the largest element of an m by n matrix.
8. Write a program that invokes a function called find( ) to perform the following
tasks:
(a) Receives a character array and a single character.
(b) Returns 1 if the specified character is found in the array, 0 otherwise.
9.Design a function locate ( ) that takes two character arrays s1 and s2 and one
integer value m as parameters and inserts the string s2 into s1 immediately after
the index m.
10.Develop a top-down modular program that will perform the following tasks:
(a) Read two integer arrays with unsorted elements.
(b) Sort them in ascending order
(c) Merge the sorted arrays
(d) Print the sorted list
Use functions for carrying out each of the above tasks. The main function
should have only function calls

You might also like