for loop C++ programs

Programs to give numbers with the output according to the loop:



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


In the following program we starts our loop from 1 and ends at 10. We gives the ending condition
as less than and equals to 10 so that the loop will starts from 1 and ends at 10
And also we uses the variable j in the display syntax so that the numbers will display in the output according to
the loop.

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


In the following program we starts our loop from 0 and ends at 10 means that the program
will run 10 times.
and in the display syntax we uses j+1 means that in the loop , first j=0 and according to the codition
1 will be added in it to show the output as 1 and so on.

Comments

Popular posts from this blog

How to display the output in C++