Question

Determine which are infite loops and why: a. int i = 0;     while(i<6){          i...

Determine which are infite loops and why:


a. int i = 0;
    while(i<6){
         i = i * i;
    }

b. int i = 0;
    while(i<6){
          i--;
    }

c. int i = 10,000;
    while(i>=6){
         i--;
    }

d. int i = 1; while(i<6){
      i = i * 2;
    }

e. int i = 75; while(i>5){
         i = i / 5;

Homework Answers

Answer #1

a and b are the infinite loops

a loop prints zeros because i is the values which gives same output as answer so loop does not get the where to stop .

ex.i = i * i always gives i let i=0 or i=1 both number gives always answer as o and 1 as final output so it will goes to infinite.

b loop is i - -; ( Decremented ) infinite and if loop is incremented then it will goes to 1 to 6 because loop i<6(ie. 0 < 6) but in case of our loop it will moves goes infinite

c loop prints 10000 to 5 numbers

d loop prints 2 4 8

e loop prints 15 and 3

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
True or False? a. int i = 0; while(i <= 20); { i = i+5; cout...
True or False? a. int i = 0; while(i <= 20); { i = i+5; cout << i << " "; } The above loop is an infinite loop. for(int i =5; i>=1 ; i++) { cout << i << endl; } The above loop is an infinite loop.
bool update(char userInput){ int i = board_height - 1; int j = userInput - 'A'; while(i>=0){...
bool update(char userInput){ int i = board_height - 1; int j = userInput - 'A'; while(i>=0){ if(board[i][j] == ' '){ board[i][j] = next; if(checkRow(i,j,next) || checkColumn(i,j,next) || checkLeftDiagonal(i,j,next) || checkRightDiagonal(i,j,next)){ global_state = next - '0'; } if(next == '1'){ next = '2'; }else{ next = '1'; } break; } i--; } if(i == -1){ return false; } return true; } How can this be turned into int update instead of bool update
int i,sum=0;   int array[8]={//You decide this};   int *a,*b,*c;   a = array;   b = &array[3];   c =...
int i,sum=0;   int array[8]={//You decide this};   int *a,*b,*c;   a = array;   b = &array[3];   c = &array[5];   c[-1] = 2;   array[1] = b[1]-1;   *(c+1) = (b[-1]=5) + 2;   sum += *(a+2) + *(b+2) + *(c+2);   printf("%d %d %d %d\n", sum, array[b-a], array[c-a], *a-*b); array[8]={ ?? }; what is array[8]?
JAVA - take each for loop and rewrite as a while statement a) int result =...
JAVA - take each for loop and rewrite as a while statement a) int result = 0; for (int i = 1; i <= 10; i++) { result = result + i;} System.out.println(result); b) int result = 1; for (int i = 1; i <= 10; i++) {result = i - result;} System.out.println(result); c) int result = 1; for (int i = 5; i > 0; i--) {result = result * i;} System.out.println(result); d) int result = 1; for (int...
1. public int add100(int[] array) { if (array.length < 100) { return 0; } int sum...
1. public int add100(int[] array) { if (array.length < 100) { return 0; } int sum = 0; for (int i = 0; i < 100; i++) { sum += array[i]; } return sum; } 2. int sum = 0; for (int i = 1; i <= n; i++) { for (int j = 0; j <= i; j++) { sum++; sum++; } } for (int i = 0; i < n; i += 2) { sum++; } 3. nt...
1. The conditon of a "while" loop and a "for" loop are executed at the ____________...
1. The conditon of a "while" loop and a "for" loop are executed at the ____________ of these loops. 2. What will the following code fragment print?    for (i = 0; i < 4; i++)        cout << i + 1; cout << i; 3. What is the result in answer below? int int1=16; int int2=5; int answer=0; answer = int1 / int2 + (5 * 2);
What is wrong with the following function: public static void funMethod() { int i=100; while (i...
What is wrong with the following function: public static void funMethod() { int i=100; while (i < 10) { System.out.println("i="+i); i++; } } Select one: a. loop control variable not declared b. loop control variable is never updated c. loop control variable not initialized d. loop control variable never resolves to true e. nothing is wrong with this code. What is wrong with the following function: public static void funMethod() { int i=1; while (i < 10) { System.out.println("i="+i); i++;...
public int linearSearch2(ArrayList<Integer> pList, Integer pKey) { for (int i = 0; i <= pList.size() /...
public int linearSearch2(ArrayList<Integer> pList, Integer pKey) { for (int i = 0; i <= pList.size() / 2; ++i) { if (pList.get(i).equals(pKey)) { return i; } else if (pList.get(pList.size() - 1 - i).equals(pKey)) { return pList.size() - 1 - i; } } return -1; } ----- Q1)Which function f(n) counts how many times the key operation(s) is(are) performed as a function of the list size n when pKey is not in pList (the worst case behavior of linearSearch2() occurs when pKey...
C++ for (double i=0; i<100000000; i++){ int *p = new int[100000000]; delete p; } Which of...
C++ for (double i=0; i<100000000; i++){ int *p = new int[100000000]; delete p; } Which of the following statement(s) is/are correct?   There is a run-time error There is a syntax error There is a memory leak There is no error
int array_with_loop(vector<int> data) {   int i;   data.push_back(6); data.push_back(9); data.push_back(2); data.push_back(-7); data.push_back(-4); int result = data[0]; for...
int array_with_loop(vector<int> data) {   int i;   data.push_back(6); data.push_back(9); data.push_back(2); data.push_back(-7); data.push_back(-4); int result = data[0]; for ( i =0; i < data.size(); i++ ) { if ( data[i] < result ) result = data[i]; } return result; } Hand execute the following code on paper for array data, variables i and result, and then indicate the returned value of array_with_loop function .
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT