Basics of C++
Basics of C++
system("pause");
return 0;
}
Computer Programming 3/20/2021 12
#include<iostream>
#include<math.h> Area of a triangle having sides a,
using namespace std; b and c is given by,
int main( ) s = ( a + b + c )/2
{ area = ( s * (s-a) * (s-b) * (s-c) )1/2
float a, b, c, s, area;
s = (a + b + c) / 2;
area= sqrt( s * (s-a) * (s-b) * (s-c) );
Triangle
cout << "Area = " << area << endl;
return 0;
}
Computer Programming 3/20/2021 13
Syntax:
const datatype CONSTANTNAME = value;
𝐸. 𝑔. 𝒂𝒓𝒆𝒂 𝒐𝒇 𝑪𝒊𝒓𝒄𝒍𝒆 = 𝝅 × 𝒓𝒂𝒅𝒊𝒖𝒔 × 𝒓𝒂𝒅𝒊𝒖𝒔
Circle
system("pause");
return 0;
}
Computer Programming 3/20/2021 16
#include <stdio>
int main ( ) {
int n = 4, k = 2;
cout << ++n << endl; cout << n << endl;
cout << n++ << endl; cout << n << endl;
cout << -n << endl; cout << n << endl;
cout << --n << endl; cout << n << endl;
cout << n-- << endl; cout << n << endl;
cout << n + k << endl; cout << n << endl;
cout << k << endl;
cout << n << k << endl; cout << n << endl;
cout << " " << n << endl; cout << " n" << endl;
cout << "\n" << endl;
cout << " n * n = "; //CAREFUL!
cout << n * n << endl;
cout << 'n' << endl;
return 0;
}
Computer Programming 3/20/2021 17
int x, a, b, c;
a = 2;
b = 4;
c = 5; x
x = a-- + b++ - ++c;
int x, a = 4;
x = ++a + ++a + ++a;
x
bool b = true;
int i = b;
cout << b << endl;
cout << i << endl;
Computer Programming 3/20/2021 33
1, Explain the differences exist in the expressions
below, given that x = 7 :
( 6 < x++ ) || ( ++x < 8 )
vs.
( 6 < x++ ) | ( ++x < 8 )
3, 𝑆ℎ𝑜𝑤
𝑡ℎ𝑎𝑡→ !((y < 3) || (y > 7)) = !(y < 3) && !(y > 7)