Saturday, 19 October 2013

Add numbers in C++

# include<iostream>
using namespace std;
void main()
{
int a,b,c;
cout<<"enter first number"<<endl;
cin>>a;
cout<<"Enter second number";
cin>>b;
c=a+b;
cout<<"The sum is"<<c<<endl;
}
here,
int is used for  integer (positive and negative)type....
here are all c++ data types and there ranges
signed char: -127 to 127 (note, not -128 to 127; this accommodates 1's-complement platforms)
unsigned char: 0 to 255
"plan" cha: -127 to 127 or 0 to 255 (depends on default char signedness)
signed short: -32767 to 32767
unsigned short::0 to 65535
signed int: -32767 to 32767
unsigned int: 0 to 65535
signed long:-2147483647 to 2147483647
unsigned long 0 to 4294967295
signed long long: -9223372036854775807 to 9223372036854775807
unsigned long long:0 to 184467440737095516
then,
cin is used for saving the required data type a value.
and 
c=a+b;
if a=4,b=4;
then c=8;
so,the answer is 8
Plz like my blog and feel free for suggestions

0 comments: