C++ Programming/Code/Variables/Examples
Appearance
From Wikibooks, open books for an open world
Variables
Adds two numbers and prints their sum
// This program adds two numbers and prints their sum. #include<iostream> intmain() { inta; intb; intsum; sum=a+b; std::cout<<"The sum of "<<a<<" and "<<b<<" is "<<sum<<"\n"; return0; }
// This program adds two numbers and prints their sum, variation 1 #include<iostream> #include<ostream> usingnamespacestd; intmain() { inta=123,b(456),sum=a+b; cout<<"The sum of "<<a<<" and "<<b<<" is "<<sum<<endl; return0; }