Make a program in C++ that tells Area of Rectangle and Perimeter of Rectangle

#include<iostream>

using namespace std;

int main()

{

    int width,height,area,perimeter;

    cout<<"Enter  Width of Rectangle = ";

    cin>>width;

    cout<<"Enter  Height of Rectangle = ";

    cin>>height;

    area=height*width;

    cout<<"Area of Rectangle ="<<area<<endl;

    perimeter=2*(height+width);

    cout<<" Perimeter of rectangle are = "<<perimeter<<endl;

    return 0;}


Ø Output of Program

Make a program in C++ that tells the Area of Traingle

#include <iostream>

#include<cmath>

using namespace std;

int main()

{

int a,b,c,s,A;

cout<<"Enter Value of first side"<<endl;

cin>>a;

cout<<"Enter Value of second side"<<endl;

cin>>b;

cout<<"Enter Valueof third side"<<endl;

cin>>c;

s=(a+b+c)/2;

cout<<"Sum of all sides is ="<<s<<endl;

A=sqrt(s*(s-a)*(s-b)*(s-c));

cout<<" The Area of Traingle is = "<<A<<endl;


}


Ø Output of Program



Make a program that take two integers and Swap their Values

#include <iostream>
using namespace std;
int main()
{
int a,b;
cout<<"Enter first Integer"<<endl;
cin>>a;
cout<<"Enterr second Integer"<<endl;
cin>>b;
a=a+b;
b=a-b;
a=a-b;
cout<<"Swapping of first integer is\n"<<a<<endl;
cout<<"Swapping of Second number is\n"<<b<<endl;
}

Ø Output of Program


Bitwise Operator

#include <iostream>
using namespace std;
int main() {
int a = 17;
int b = 15;
cout << "Bitwise Operators\n";
cout << "a & b = " << (a&b) <<endl;
}


Output of Program

Write a program that tell remainder and Qoutient

include<iostream>

using namespace std;

int main()

{ int a = 20, b = 4;

cout << "Quotient = " << a / b << endl;

cout << "Remainder = "<< a % b << endl;

return 0;



}

 

 


Ø Output of Program




Write a program that perfom addition on two numbers

#include<iostream>
using namespace std;
int main()
{
int a = 3, b = 5;
cout << a << '+' << b << '=' << (a+b);
return 0;
}


Ø Output of Program

Getting Familiar with Operators in C++


OPERATORS IN C++
Operators are special type of functions, that takes one or more arguments and produces a new value.
• For Example:  addition (+), subtraction (-), multiplication (*) etc,
Are all operators and operators are used to perform various operations on variables & constants.
Following are the types of Operators used in C++.
1.      Assignment Operator
2.      Arithmetic Operators
3.      Relational Operators
4.      Logical Operators
5.      Bitwise Operators
6.      Shift Operators
7.      Unary Operators
·         Assignment Operators
The Assignment Operator evaluates an expression on the right of the expression and substitutes it to the value or variable on the left of the expression.
·        Arithmetic Operators
All the basic arithmetic operations can be carried out in C++, these are operators used to perform basic mathematical operations. Addition (+) , subtraction (-) , diversion (/) multiplication (*) and modulus (%) are the basic mathematical operators. Modulus operator cannot be used with floating-point numbers.
·        Relational Operators
These operators establish a relationship between operands. The relational operators are : less than (<) , grater that  (>) , less than or equal to (<=), greater than equal to (>=), equivalent (==) and not equivalent (!=).

·        Logical Operators

The logical operators are AND (&&) and OR (||). They are used to combine two different expressions together.  If two statement are connected using AND operator, the validity of both statements will be considered, but if they are connected using OR operator, then either one of them must be valid.


·        Bitwise Operators

There are used to change individual bits into a number. They work with only integral data types like char, int and long and not with floating point values.

·        Shift Operators

Shift Operators are used to shift Bits of any variable. It is of three types,
1.      Left Shift Operator <<
2.      Right Shift Operator >>

·        Unary Operators


These are the operators which work on only one operand. There are many unary operators, but increment ++and decrement -- operators are most used., other examples are unary minus - and unary plus +.

Total Pageviews