C++ Program to Print 1 to 100

In this post, we will learn how to print 1 to 100 using the C++ Programming language.

We will be using the following approaches to print numbers from 1 to 100.

  1. Using For Loop
  2. Using While Loop
  3. Using Do While Loop

So, without further ado, let’s begin this post.

C++ Program to Print 1 to 100 Using For Loop

// C++ Program to Print 1 to 100 Using For Loop
#include <iostream>
using namespace std;

int main(){
    int i;
    
    for (i = 1; i <= 100; i++){
        cout << i << " ";
    }
    return 0;
}

Output

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 

How Does This Program Work?

    int i;

In this program, we have declared an integer data type variable named i.

    for (i = 1; i <= 100; i++){
        cout << i << " ";
    }

Then, we used for loop to iterate numbers from 1 to 100. In the for loop, we print the value of i and then increment the value of i by 1.

This process keeps on executing until i <= 100. This gives us all the numbers from 1 to 100.

C++ Program to Print 1 to 100 Using While Loop

// C++ Program to Print 1 to 100 Using While Loop
#include <iostream>
using namespace std;

int main(){
    int i = 1;
    
    while (i <= 100){
        cout << i << " ";
        i++;
    }
    return 0;
}

Output

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 

C++ Program to Print 1 to 100 Using Do While Loop

// C++ Program to Print 1 to 100 Using Do While Loop
#include <iostream>
using namespace std;

int main(){
    int i = 1;
    
    do{
        cout << i << " ";
        i++;
    } while (i <= 100);
    return 0;
}

Output

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 

Conclusion

I hope after going through this post, you understand how to print 1 to 100 using the C++ Programming language.

If you have any doubt regarding the program, then contact us in the comment section. We will be delighted to assist you.

Also Read:

Leave a Comment

Your email address will not be published. Required fields are marked *