Functions and Recursions – Arithmetic – Problem #7

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

Difficulty: medium

Problem Statement

Consider the following recursive formula for calculating the n’th term of a series, an = 2 ∗ (an−1) + 3 ∗ (an−2), a0 = 1, a1 = 1 The first few terms of the sequence (starting from a0) is 1, 1, 5, 13, 41, 121. . . ..Write a C program to input a number ‘n’ less than 20 and print the value of an . You must call a recursive function to calculate the value of an. Also in main(), you must keep a check that the input value of ‘n’ must be less than 20. If the input is greater than 20, then the program must display error ‘Out of Range’ and wait for the user to enter a valid input again.

Back to Lab Problems
Functions and Recursions/Arithmetic/Problem #7

Lab Problem Statement

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

Interactive C Compiler · Problem #7

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.