1. Write a program to print number from 1 to 10.

While Loop:

#include<iostream> using namespace std; int main() { int i = 1; while(i<=10) { cout<<i<<"\t"; i++ ; // i = i +1 } return 0; }

For Loop

#include<iostream> using namespace std; int main() { for(int i = 1; i<=10;i++) { cout<<i<<"\t"; } return 0; }

Do -While Loop

#include<iostream> using namespace std; int main() { int i = 1; do { cout<<i<<"\t"; i++; }while(i<=10); return 0; }

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s