Assignment 6
Assignment 6
Submit all the programs separately against each assignment in the Moodle System. Provide
the result in a separate output file (named, result_<assgn><no>.txt). Use standard output
redirection feature to generate the output file.
./a.out >result.txt
Output of your program (generated by printf(.) function) will be written in the file result.txt.
You need to provide input from your keyboard, by remembering the sequence of inputs to be
given or writing them in a text file in the same sequence.
Otherwise you may use the redirection for the standard input file, such as,
./a.out <input.txt
For the above all your printing by printf(.) function would be displayed on your monitor.
For both reading from a file and writing to a file use the following.
If you execute the program multiple times, you may concatenate the outputs in a single file by
using the following redirection command:
./a.out >>result.txt
or
(a) Write a program, which has a recursive function f(n) as defined below:
f(n) = 0, for n<0
= 1, for n=0
Hints: Use a global variable to keep count of the number of recursive calls
within the function f(n).
Run your program for the following input data set and provide the results
with input datasets in a separate output file.
(b) Write a recursive function named sum_digits(.) for computing sum of digits
of a positive integer (up to six digits long). Read a list of positive integers in an
array and print the number(s) which has (have) the maximal sum of digits.
Run your program for the following input data set and provide the results with
input datasets in a separate output file.
Read a list of positive numbers in an array and print them after reversing their
digits. Further report the palindromes and the number of palindromes.
Run your program for the following input data set and provide the results with
input datasets in a separate output file.