Question

Write a C program for a program to implement a recursive main. Include a static local...

Write a C program for a program to implement a recursive main. Include a static local variable count initialized to 1. Post increment and print the value of count each time the main is called. The loopcount included in the usage is a positive integer number that will indicate how deep the recursion should go.

Usage: lab3 loopcount

Code should be nicely indented and commented.

Create a simple Makefile to compile your program into an executable called lab3.

You should submit the source code, your Makefile and a screenshot of the output file

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <stdio.h>
#include <stdlib.h>

static int n=1;
int main (int argc, char *argv[]) {
   int lc=atoi(argv[1]);
printf ("Running main with n = %d'\n", n++);
if (n <= lc)
return main(2,argv); // recursive call to main
return 0;
  
  
  

}

매 C:\U sers hp Documents recursivemain.exe 10 Running main with n-1 Running main with n 2 Running main with n3 Running ma

Add a comment
Know the answer?
Add Answer to:
Write a C program for a program to implement a recursive main. Include a static local...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • OUTPUT MUST MATCH THE IMAGE TO THE TEE. I have the majority of the program written,...

    OUTPUT MUST MATCH THE IMAGE TO THE TEE. I have the majority of the program written, just having issues with the output. Please make sure to have the right alignment, variable data types and number padding/decimals as shown below! ​ MUST BE IN C NOT C++/C#! Assume the Item Num is an int that must be padded with zeros (ex: 1234 ---> 00001234) Write a C program for a shopping list to run on ocelot. Use the listed items and...

  • Write in C++ Build and run your project. The program should compile without any errors, but...

    Write in C++ Build and run your project. The program should compile without any errors, but if does fix the errors . Note that function main() creates a new BST of int and inserts the nodes 12, 38, 25, 5, 15, 8, 55 (in that order) and displays them using pre-order traversal. Verify that the insertions are done correctly. 1. Add code to test the deleteNode and search member functions. Save screenshot of your test program run. 2. Add code...

  • Please solve the program in C++(Recursive) Write a function called factorialIterative(). This function should take a...

    Please solve the program in C++(Recursive) Write a function called factorialIterative(). This function should take a single BIG integer (bigint) as its parameter n, and it will compute the factorial n! of the value and return it as its result (as a bigint). Write this functions using a loop (do not use recursion). 2. Write the factorial function again, but using recursion. Call this function factorialRecursive(). The function takes the same parameters and returns the same result as described in...

  • C# QUESTION Requirements Your task is to write a program that will print out all the s of the com...

    C# QUESTION Requirements Your task is to write a program that will print out all the s of the command line arguments to a program For example, given the arguments 'gaz, wx,and 'edc, your program should output wsxaazea Your implementation is expected to use Heap's algorithm according to the following pseudocode: procedure generatelk: integer, A: array of any): if k 1 then output A) else // Generate permutations with kth unaltered //Initially k length(A) // Generate permutations for kth swapped...

  • C++ PROGRAM ONLY! For this lab you need to write a program that will read in...

    C++ PROGRAM ONLY! For this lab you need to write a program that will read in two values from a user and output the greatest common divisor (using a recursive implementation of the Euclidean algorithm) to a file. In Lab #3, you implemented this program using an iterative method. Greatest Common Divisor In mathematics, the greatest common divisor (GCD) of two or more integers (when at least one of of them is zero then the larger value is the GCD....

  • C++: Write a recursive function that does the following: Given a number, add all the digits...

    C++: Write a recursive function that does the following: Given a number, add all the digits and display the sum. Example:                         The sum of the number 5432 would be 14. PLEASE PAY ATTENTION TO THE FOLLOWING: Do not use the static modifier. No global variables. Your program should implement a non-tail recursive algorithm. In other words, it should do something as it moves towards the base case, the tail, and also do something as it comes back from...

  • You will write a C program, q1 sequence.c, that computes the value of the nth term...

    You will write a C program, q1 sequence.c, that computes the value of the nth term in any recursive sequence with the following structure: an = c1 · an−1 + c2 · an−2 a0 > 0 a1 > 0 c1 6= 0 c2 6= 0 Your C program will take 5 integer arguments on the command line: n, a0, a1, c1 and c2. n must be an integer greater than or equal to 0. If more or fewer arguments are...

  • **Program must compile under Ubuntu! (35 pts) Write a C++ program A4p2.cpp with a class of...

    **Program must compile under Ubuntu! (35 pts) Write a C++ program A4p2.cpp with a class of your own design. The class should contain a protected int member variable var, which is initialized with an integer value between 1 and 50 in a constructor that takes an integer parameter. The class should contain a public member function called playthat should print out a sequence of integers as a result of iteratively applying a math function f to the member variable var...

  • Assignment #9 will be the construction of a program that reads in a sequence of integers...

    Assignment #9 will be the construction of a program that reads in a sequence of integers from standard input until 0 is read, and store them in an array (including 0). This is done using iteration (choose one of for, while, or do while loop). You may assume that there will not be more than 100 numbers. Then compute the minimum number, compute the largest number among the numbers that are divisible by 2, count even numbers, and compute the...

  • 1. Specification Write a C program to implement a simple calculator that accepts input in the...

    1. Specification Write a C program to implement a simple calculator that accepts input in the following format and displays the result of the computation: calc [operand_1] [operator] [operand_2] The operands operand_1 and operand_2 are non-negative integers. The operator is one of the following: addition (+), subtraction (-), multiplication (x), division (/) and modulo (%). Note: For the multiplication operator, use letter ‘x’. If you use the asterisk ‘*’, your program will not work properly 2. Implementation • The program...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT