| | |
Print Even Numbers
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Apr 2004
Posts: 8
Reputation:
Solved Threads: 0
I have a problem, I want to create a program in C++.
A simple program displaying all even number between 1 and 100, (such as 2, 4, 6, 8 etc.) in an out put. Can you tell me what wrong. Something like this.
#include <iostream.h>
int main()
{
int num1=1;
int num2=2
if(num1<num2
{
cout << num1<<num2*2endl;
num1=num1+1;
num2=num2*2;
}
return 0;
}
Can you help me with this. What do you think?
You help is appreciated.....Peter
A simple program displaying all even number between 1 and 100, (such as 2, 4, 6, 8 etc.) in an out put. Can you tell me what wrong. Something like this.
#include <iostream.h>
int main()
{
int num1=1;
int num2=2
if(num1<num2
{
cout << num1<<num2*2endl;
num1=num1+1;
num2=num2*2;
}
return 0;
}
Can you help me with this. What do you think?
You help is appreciated.....Peter
if you wanted to go beyond the call of duty you could do one of these:
C++ Syntax (Toggle Plain Text)
#include <iostream.h> #include <stdlib.h> void main() { int MAX; cout<<"Enter a number to count by two to: "; cin>>MAX; for (int x = 0; x <= MAX; x++) { if (x % 2 == 0) {cout << x << endl;} } system("pause"); }
A Hacker's Mind:
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes..." - J.D.Salinger
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes..." - J.D.Salinger
![]() |
Similar Threads
- java application that will print to patterns (Java)
- Help with arrays and numbers (Java)
- Printing numbers in ascending order (help) (C++)
- need help adding positive and negative numbers (C++)
- newb: Print ids, you get 1L, what is L? (Python)
- 500 ways to print [1..10]! (IT Professionals' Lounge)
- print odd and even numbers (Assembly)
Other Threads in the C++ Forum
- Previous Thread: C++ code for modem streaming
- Next Thread: C++ Error : opening file a second time for a read
| Thread Tools | Search this Thread |
api array arrays beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion convert count data database delete desktop developer directshow dll dynamiccharacterarray email encryption error file forms fstream function functions game generator getline google graph homeworkhelper iamthwee ifstream input int integer java lib linkedlist linux list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates test text tree unix url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets





