why output is  Usage: ./a.out i/r term_number ...Program finished with exit code 1 Press ENTER to exit console.

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter9: Completing The Basics
Section: Chapter Questions
Problem 6PP
icon
Related questions
icon
Concept explainers
Question

why output is 

Usage: ./a.out i/r term_number


...Program finished with exit code 1
Press ENTER to exit console.

main.c
1 #include <stdio.h>
2 #include <stdlib.h>
3
4 // Function to print the Recamán's sequence iteratively
5 void printIteratively(int n) {
6 int i, step, current_term = 0, used[100000] = {0};
7
8 // Loop to generate and print the Recamán's sequence
9- for (i
1; i <= n; i++) {
10 // Check if current_term
11- if (current_term
12 current_term
=
-
step is negative or already in the sequence
i < 0 || used [current_term - i]) {
current_term + i;
i;
13- } else {
14 current_term current_term
15 }
16 used [current_term] = 1;
17 printf("%d", current_term);
18 }
19 printf("\n");
20 printf("%d terms generated\n", n);
21 }
22
Jsage: ./a.out i/r term_number
23 // Function to print the Recamán's sequence recursively
24 void printRecursively(int n, int i, int current_term, int used[]) {
25 // Base caso if n torms have been printed noturn
..Program finished with exit code 1
Press ENTER to exit console.
input
Transcribed Image Text:main.c 1 #include <stdio.h> 2 #include <stdlib.h> 3 4 // Function to print the Recamán's sequence iteratively 5 void printIteratively(int n) { 6 int i, step, current_term = 0, used[100000] = {0}; 7 8 // Loop to generate and print the Recamán's sequence 9- for (i 1; i <= n; i++) { 10 // Check if current_term 11- if (current_term 12 current_term = - step is negative or already in the sequence i < 0 || used [current_term - i]) { current_term + i; i; 13- } else { 14 current_term current_term 15 } 16 used [current_term] = 1; 17 printf("%d", current_term); 18 } 19 printf("\n"); 20 printf("%d terms generated\n", n); 21 } 22 Jsage: ./a.out i/r term_number 23 // Function to print the Recamán's sequence recursively 24 void printRecursively(int n, int i, int current_term, int used[]) { 25 // Base caso if n torms have been printed noturn ..Program finished with exit code 1 Press ENTER to exit console. input
Expert Solution
Step 1

This error occurs because the number of arguments provided is incorrect. The code expects 2 arguments: the executable name, an "i" or "r" to select the method, and the term number to indicate how many terms to print.

To fix this, you need to provide the correct number of arguments when running the code. For example:

  •  i 10
  • or r 11

This will run the code with the correct arguments and produce the correct output.

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Operators
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,