Computer Science, asked by nandrajogyukti1405, 3 months ago


write a program in C++ to exicute 1 to
10 number using for loop while loop do while loop​

Answers

Answered by pandeyanushka612
3

Answer:

// C++ Program to print numbers from 1 to 5

#include <iostream>

using namespace std;

int main() {

int i = 1;

// while loop from 1 to 10

while (i <= 10) {

cout << i << " ";

++i;

}

return 0;

}

Explanation:

hope its help you

Answered by anindyaadhikari13
4

Required Answer:-

Correct Question:

  • Write a program in C++ to execute and display 1 to 10 numbers using for loop, while loop and do while loop.

Solution:

1. Using for loop.

#include <iostream>

using namespace std;

int main() {

for(int i=1;i<=10;i++)

cout << i << " ";

return 0;

}

2. Using while loop.

#include <iostream>

using namespace std;

int main() {

int i=1;

while (i<=10) {

cout << i << " ";

i++;

}

return 0;

}

3. Using do-while loop.

#include <iostream>

using namespace std;

int main() {

int i=1;

do {

cout << i << " ";

i++;

} while(i<=10);

return 0;

}

Algorithm:

  1. START
  2. Initialise i = 1
  3. If i <= 10, display value of i or else goto step 4.
  4. STOP

Refer to the attachment for output ☑.

Attachments:
Similar questions