// A very simple program#include <iostream.h> main() { int one, two; one = 1; two = 2; cout << "One is " << one " and two is " << two << endl; return 0; }
Concept | Example |
---|---|
Declare integer | int i; |
Declare real number | real i; |
Declare string | char name[100]; |
Declare boolean | bool b;. |
Print variable 'i' | cout<< i; |
Print "hello world" | cout << "Hello World"; |
Read variable 'i' | cin >> i; |
For loop with i in 1..10 | for(i=1; i < 11; i++) cout << i << endl; |
If-then statement | if (i == 1) { cout << "I is one" << endl; } |
If-then-else statement | if (i==1) return 0; else return 1; |
Declare function | int double(int x) |
Return from function | return 10; |