Question

//1. Write out the output for eaching of following: /* Consider this function. void myMethod( int...

//1. Write out the output for eaching of following: /* Consider this function. void myMethod( int counter) { if(counter == 0) return; else { System.out.println(""+counter); myMethod(--counter); return; } }

Homework Answers

Answer #1

function myMethod(int counter) will print the number starting from counter value till 1. at each recursive call counter value is decremented by 1. When counter value reaches 0, the function ends beacuse of if condition where it checks if counter is 0 then return from method and control goes back to main method.

code:-

Ouput

Know the answer?
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
Similar Questions
Consider the following Java program : public static void main (string args [ ]) { int...
Consider the following Java program : public static void main (string args [ ]) { int result, x ; x = 1 ; result = 0; while (x < = 10) { if (x%2 == 0) result + = x ; + + x ; } System.out.println(result) ; } } Which of the following will be the output of the above program? A. 35 B. 30 C. 45 D. 35 2. public static void main(String args[]) { int i =...
What is the output of the following function and function call? void calculateCost(int count, float& subTotal,...
What is the output of the following function and function call? void calculateCost(int count, float& subTotal, float taxCost); float tax = 0.0, subtotal = 0.0; calculateCost(15, subtotal,tax); cout << "The cost for 15 items is " << subtotal       << ", and the tax for " << subtotal << " is " << tax << endl; //end of fragment void calculateCost(int count, float& subTotal, float taxCost) {       if ( count < 10)       {                   subTotal = count *...
What is the output of the following function and function call? void calculateCost(int count, float& subTotal,...
What is the output of the following function and function call? void calculateCost(int count, float& subTotal, float taxCost); float tax = 0.0, subtotal = 0.0; calculateCost(15, subtotal,tax); cout << "The cost for 15 items is " << subtotal       << ", and the tax for " << subtotal << " is " << tax << endl; //end of fragment void calculateCost(int count, float& subTotal, float taxCost) {       if ( count < 10)       {                   subTotal = count *...
Given the following function in C++: int main(void) { int a = 2; int b =...
Given the following function in C++: int main(void) { int a = 2; int b = myFunction(a); a = b + 1; b = myFunction(a); cout << ”b = ” << b << endl; return 0; } int z = myFunction(int x) { static int n = 0; n = n + 1; int z = x + n; return z; } What is printed by the cout on the screen?
Write a C function to compute the following output (int) based on two input (int) variables:...
Write a C function to compute the following output (int) based on two input (int) variables: output = a*a + b*b - 2*a*b If the value of output is '0', then return -1 instead. Call the C function 4 times from main() with values of 'a' and 'b' as follows and print output values for each case. a = 3, b = 4 a = 1, b = 1 a = -2 b = 3 a = -4 b =...
What is output? #include <stdio.h> void CheckValue(int* pointVar1, int* pointVar2) {       if (pointVar1 == NULL...
What is output? #include <stdio.h> void CheckValue(int* pointVar1, int* pointVar2) {       if (pointVar1 == NULL && pointVar2 == NULL) {       printf("Pointer is null\n");    }    else if (*pointVar2 > *pointVar1) {       printf("%p\n", *pointVar2);    }    else if (*pointVar1 > *pointVar2) {       printf("%p\n", *pointVar1);    } } int main() {    int num1 = 5;    int num2 = 9;       CheckValue(&num1, &num2);           return 0; } a. 0 b. 5 c. 9 d. Pointer is null e....
Analyze the following program and write down the output. # include <iostream> using namespace std;    void...
Analyze the following program and write down the output. # include <iostream> using namespace std;    void modifyArray( int [ ], int );    void modifyElement ( int );      int main( ) {   const int arraySize = 8;   int a[arraySize] = { 2, -2, 10, -3, -1 ,0, 10, -5 };      modifyArray ( a, arraySize);      for ( int i =0; i < arraySize; i++)               cout << a[i] << ‘  ’;         modifyElement ( a[4] );          for ( int i =0; i <...
/************************************************************************************* Function Prototypes *************************************************************************************/ int ScanArray(char *fname, int myArray[], int nSize); void Ge
/************************************************************************************* Function Prototypes *************************************************************************************/ int ScanArray(char *fname, int myArray[], int nSize); void GenerateFromArray(void); /************************************************************************************/ /************************************************************************************/ int main(void) { /* This is the main() program. It should call the functions ScanArray() and GenerateFromArray() */ GenerateFromArray(); system("pause"); return 0; } /*************************************************************************************** Define this function to scan the elements of an array from the given data file "ArrayInp.dat". If the input file is not found, or contains invalid data, the function should return a 0 and print an error message. If the input...
Give the output of the program: void thing1(); void thing2(); int main() {      printf("3 ");...
Give the output of the program: void thing1(); void thing2(); int main() {      printf("3 "); thing1();      printf("4"); thing(2);      printf("5");      return 0; } void thing1() {      printf("Gotcha!" ); } void thing2() {      printf("HA! "); }
C Programming 1. Write a void function that takes in a 2D array of character and...
C Programming 1. Write a void function that takes in a 2D array of character and have it print out each array on a new numbered line on the console. 2. Illustrate the stack and the heap allocation. Specify what each variable value holds and where different references are pointing to. int main() { int myarray[3]; myfunction (myarray); } int myfunction(int* in) { int i; for (i = 0; i<3; i+= 1) { in[i] = i; } // illustrate the...