/* This Is A Simple Program Just To Understand The Basic OF g++ Style.
This Is A Program With g++ Compiler.
/ #include / include input and output functions / using namespace std; / we are using the std (standard) functions / int main() / declare the main function; you can have int main(void) too.
/ { cout « “\n Hello Daddy” ; / ‘\n’ is a newline (\t is a tab) */ cout « “\n Hello Mummy” ; cout « “\n This Is My First Program” ; cout « “\n Date 11/03/2007” ; return 0; }
/* This Program Calculates The Sum Of Two Numbers / #include using namespace std; int main() { float num1,num2,res; / declare variables; int, double, long.
.
work too / cout « “\n Enter the first number= " ; cin » num1; / put user’s value into num1 */ cout « “\n Enter the second number= " ; cin » num2; res = num1 + num2; cout « “\n The sum of “« num1 «” and “« num2 «” = “«res ‘\n’ ; return 0; }
/* Product Of Two Numbers */ #include using namespace std; int main() { float num1; int num2; double res; cout « “\n Enter the first number= " ; cin » num1; cout « “\n Enter the second number= " ; cin » num2; res = num1 * num2; cout « “\n The Product of two numbers = " « res ‘\n’ ; return 0; }
// Looping to find a math equation.
In this case, it figures out the answer to // Question #1 on Project Euler.
#include using namespace std; int main() { // Opening Main.
int sum1=0; int sum2=0; int sum3=0; int sum4=0; // Creates the integers needed in order to figure out the answer.
for (int a=0; a < 1000; a=a+3) {sum1 = sum1+a;} // Loops until a is 1000 or over, adding 3 to a every loop.
Also adds a to sum1.
for (int b=0; b < 1000; b=b+5) {sum2 = sum2+b;} // Loops until b is 1000 or over, adding 5 to b every loop.
Also adds b to sum2.
for (int c=0; c < 1000; c=c+15) {sum3 = sum3+c;} // Loops until c is 1000 or over, adding 15 to c every loop.
Also adds c to sum3.
sum4 = sum1 + sum2 - sum3; // sum4 takes the sum of sum1 and sum2, and subtracts sum3.
cout « sum4; // Outputs sum4, the answer.
cin.
get(); // Waits for user to press enter.
return 0; // Return statement.
} // Closing Main.
int main(){ int i = 0; if(1+1==2){ i = 2; } } /* This is Whitesmiths style / int main() { int i; if (1+1==2) { i = 2; } } / This is GNU style */ int main () { int i; if (condition) { i = 2; function (); } }