Question

In: Computer Science

(C++)Change the following loop to a while loop: int i; for (i=0; i<10; i++) {    ...

(C++)Change the following loop to a while loop:

int i;
for (i=0; i<10; i++)
{
    cout<<i<<endl;
}

Solutions

Expert Solution

Dear Student ,

As per the requirement submitted above , kindly find the below solution.

Here a new c++ program with name "main.cpp" is created, which contains following code.

main.cpp :

//header files
#include <iostream>
using namespace std;
//main method
int main()
{
int i;//declaring variable
i=0;//initilizing variable
//using while loop
while(i<10)
{
cout<<i<<endl;//print value of i
i++;//increment i
}
return 0;
}

======================================================

Output : Compile and Run main.cpp to get the screen as shown below

Screen 1 :main.cpp

NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.


Related Solutions

How many times will the following while loop iterate? int i = 1; while (i <...
How many times will the following while loop iterate? int i = 1; while (i < 5) {     i = i + 1;     System.out.println(“Hello!”); } Group of answer choices 4 0 5 It will iterate infinitely
Here is a traditional loop in C:   while (A{i} == 0)                A{i} = A{5} + A{i+3};...
Here is a traditional loop in C:   while (A{i} == 0)                A{i} = A{5} + A{i+3}; (NOTE: please consider braces {} here as usual square brackets for array index). Assume that i is stored in register $s1, and the base address of the array A is in $s2. Fill in the multiple blank spaces in the following MIPS program that is supposed to be compiled from the above C loop: loop: sll $t0, $s1,                add $t0, $t0,                lw $t1, 20($s2)...
int f2 (int n) j = 0; while (j <n) {for (int i = 0; i...
int f2 (int n) j = 0; while (j <n) {for (int i = 0; i <n; ++ i) {cout << "j =" + j; j = j + 5; }}
#include <iostream> using namespace std; int main() { int even=0,odd=0,sum=0,sum2=0,largest,smallest; int num,i; for ( i=1; i<=10;...
#include <iostream> using namespace std; int main() { int even=0,odd=0,sum=0,sum2=0,largest,smallest; int num,i; for ( i=1; i<=10; i++){ cout << " Enter " << i << " number: "; cin >> num; if ( num%2==0){ even++; sum+=num; } else { odd++; sum2+=num; if(num>largest){ largest = num; } if(num<largest) { smallest = num; } } cout << " The sum of even number is : " << sum << endl; cout << " The total-count of even number is : " <<...
What is the ouput of the following code? void loop(int num) { for(int i = 1;...
What is the ouput of the following code? void loop(int num) { for(int i = 1; i < num; ++i) { for(int j = 0; j < 5; ++j) { cout << j; } } } int main() { loop(3); return 0; }
REWRITE FOLLOWING CODES USING DO...WHILE LOOP. BY USING C LANGUAGE #include <stdio.h> int main(void) {     ...
REWRITE FOLLOWING CODES USING DO...WHILE LOOP. BY USING C LANGUAGE #include <stdio.h> int main(void) {      int count =2; // COUNT TAKEN 2 AS TO PRINT 2 TIMES           while(count--){                printf("\--------------------------------------------\ \n"); printf("\          BBBBB               A                   \ \n"); printf("\          B    B             A A                  \ \n"); printf("\          BBBB              A   A                 \ \n"); printf("\          B    B           AAAAAAA                \ \n"); printf("\          BBBBB           A       A               \ \n"); printf("\---------------------------------------------\ \n");             }                                 return 0; }
14. How many times does "#" print? for(int i = 0; i < 10; ++i) {...
14. How many times does "#" print? for(int i = 0; i < 10; ++i) { if(i == 2 || i==4 || i==6) { continue; } cout << "#"; }
C language and it has to be a while loop or a for loop. Use simple...
C language and it has to be a while loop or a for loop. Use simple short comments to walk through your code. Use indentations to make your code visibly clear and easy to follow. Make the output display of your program visually appealing. There is 10 points deduction for not following proper submission structure. An integer n is divisible by 9 if the sum of its digits is divisible by 9. Develop a program that: Would read an input...
Change the following C++ functions to Assembly x86: int problem1_ ( ) { int numberArray [3]...
Change the following C++ functions to Assembly x86: int problem1_ ( ) { int numberArray [3] = {1, -2, 15 }; int result = 0, index = 0; int numElements = 3; while (index < numElements) { if ( index >= 1 && numberArray[index] > 3 ) { result += numberArray[index] ; } else { result -= 3; } index++; } return result; } int problem2_ ( ) { int a, modulo int answer = 0, b = 3; for...
Change the following C++ functions to Assembly x86: int problem1_ ( ) { int numberArray [3]...
Change the following C++ functions to Assembly x86: int problem1_ ( ) { int numberArray [3] = {1, -2, 15 }; int result = 0, index = 0; int numElements = 3; while (index < numElements) { if ( index >= 1 && numberArray[index] > 3 ) { result += numberArray[index] ; } else { result -= 3; } index++; } return result; } int problem2_ ( ) { int a, modulo int answer = 0, b = 3; for...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT