Syntax:
for(<initialization>;<condition>;<increment/decrement>)
{
Statements;
.
.
}
/*————————————————————*/
//To display odd values between 1 and 10
#include<iostream.h>
#include<conio.h>
void main()
{
int oddval;
for(oddval=1;oddval<=10;oddval+=2)
cout<<oddval<<endl;
getch();
}
Output:
1
3
5
7
9
Not Satisfied ? Just search & get the result
Related posts:
- While loop in C++
- Do…while loop in C++
- C program to find the sum of first 50 natural numbers using for loop
- Java program – While loop
- C program to evaluate the given polynomial P(x)=AnXn + An-1Xn-1 + An-2Xn-2+… +A1X + A0, by reading its coefficients into an array. [Hint:Rewrite the polynomial as P(x) = a0 + x(a1+x(a2+x(a3+x(a4+x(...x(an-1+xan)))) and evaluate the function starting from the inner loop]
