Functions and Recursions – Geometry – Problem #8

IIT Kharagpur CS10001 / CS11001 Programming and Data Structures Lab Question Archive

Difficulty: medium

Problem Statement

A positive integer is said to have an increasing digit k-sequence (of length k), if the first k digits are in strictly increasing value sequence. For example, the k-sequence of 58345 is 2, 23567 is 5, 71289 is 1, 45667 is 3. Write a non-recursive function seq(n) which takes an integer n and returns the increasing digit sequence number of n. Then in the main program, you should read in a positive integer m, read m integers, calculate the k-sequence of each integer you have read by calling the function seq(n) and print the results obtained. Also identify which of these integers are completely in increasing digit sequence (e.g., 23567). Save the file as A09_<Roll Number>.c (example A09_21AG10002.c). Build, Run and Test it for the given data as well as your own data. Then upload the .c file for the Assignment. [20 Marks: 5 marks for intermediate submission, 15 marks for final submission] In particular, you will do the following: 1. Read in a positive integer m and print it suitably. Create a new line. 2. Read in m positive integers, repeatedly call the function seq (which you will define) for each of the m numbers that are read. Print each number and its k-sequence value appropriately in a new line each. 3. Among the above integers read, suitably print all those which are completely in increasing digit sequence. If therare no such, print “None have such a sequence”. 4. [Bonus] If you complete these within the scheduled time, write the function seq in a recursive manner. Call it rseq and use appropriate parameters. Test it like you tested seq. [Bonus will not add to assignment marks] [Do not call any Library Functions other than scanf, printf. You may use your own user defined functions] Test Data: a) m = 5, numbers are 3456, 1237, 8888, 787, 7321 b) m = 5, numbers are 1, 23456, 134, 56789, 7897 c) m = 4, numbers are 351, 531, 1345, 68153

Back to Lab Problems
Functions and Recursions/Geometry/Problem #8

Lab Problem Statement

Specifications & Problem DetailsIIT Kharagpur PDS Archive
Loading question...

Interactive C Compiler · Problem #8

WASM In-Browser

Runs directly on your machine · Zero remote server dependency

Compiler downloads on first Run (large, saved in your browser after that)
main.cCtrl + Enter to run
1
2
3
4
5
6
7
Input (stdin)given to scanf / cin
Output

Output appears here. Press Run to compile and execute.