Write a program in C++ to display ODD Number between 1 to 100 using for loop
Answers
Answered by
2
Solution:
The given problem is solved in C++.
#include <iostream>
using namespace std;
int main() {
for(int i=3;i<100;i+=2)
cout << i << " ";
return 0;
}
Explanation:
- Line 1: Tells the compiler to import iostream file which contains declaration of all the standard input and output library functions.
- Line 2: Imports the standard namespace library into the program.
- Line 3: Start of main() method.
- Line 4: A loop is created that iterates in the range (3 - 100), the value of i is incremented by 2 here so as to skip the even numbers present in the range.
- Line 5: Value of i is displayed on the screen.
- Line 6: Function returns 0 since the function is of return-type and not void.
- Line 7: End of main()
Refer to the attachment for output.
Attachments:
Similar questions
Science,
2 days ago
Math,
2 days ago
Math,
2 days ago
Accountancy,
4 days ago
Hindi,
8 months ago
Accountancy,
8 months ago
Math,
8 months ago