cpp day 1

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

// Useses of all Escape sequence

#include<iostream>
using namespace std;
int main ()
{
// 1) \n --> New line
cout<<"\nNepal is a beautyfull\ncountry";
// 2) \t --> Horzontal tab
cout<<"\nIndia\tis\tgreat";
// 3) \a Audible bell
cout<<"\nrajan \a rajak";
// 4)\b -->Backspace
cout<<"\nindia is\b greate";
// 5) \r --> Carrige return
cout<<"\nIndia is\r great";
// 6) \\ Shows backward slash(\)
cout<<"\nNumber1\\Number2";
// 7) \' Single quotes
cout<<"\nI\'m a good boy";
// 8)\" Double quotes
cout<<"\nMy name\"Rajan";
// 9) \? Question marks
cout<<"What is your name \?";
// 10) \0 Null character
cout<<"What is\0 this";
// 11) \x--> Hexadecimal
// 12) \o --> Octal number
// 13) \v --> Vertical tab
// 14) \f--> Form feed(feed one blank page before starting the printing)
}

// 02 Uses of reference
#include <iostream>
using namespace std;
int main()
{
int a=10;
int &b = a; // refernce variable
cout << "a ="<<a<<endl;
cout << "b="<<b<<endl;
b++;
cout << "new a ="<<a<<endl;
cout << "new b="<<b<<endl;
}

// 03 Uses of typedef
#include <iostream>
using namespace std;
int main()
{
typedef float currency;
currency amount;
amount = 1500;
cout << "\nAmount ="<<amount;

// 04 Uses of enum
#include <iostream>
using namespace std;
int main()
{
enum day {sun,mon,tue,wed,thu,fri,sat};
day d;
d=sun;
cout << "\nd ="<<d;
cout << "\nthu ="<<thu;
}

// 05 Uses of Input and Output Operators


#include <iostream>
using namespace std;
int main()
{
int a;
cout <<"hello"; // Insertion Operator
cin>>a; // Extraction Operator
}

// 06 Uses of Increment and Decrement Operator


#include <iostream>
using namespace std;
int main()
{
int a=10, b=5,c=9,d=3;
cout <<"Before a="<<a<<endl;
cout <<"Before b="<<b<<endl;
cout <<"Before c="<<c<<endl;
cout <<"Before d="<<d<<endl;
++a;
b++;
--c;
d--;
cout <<"After a="<<a<<endl;
cout <<"After b="<<b<<endl;
cout <<"After c="<<c<<endl;
cout <<"After d="<<d<<endl;

// 07 Uses of Arthemetic operetor


#include <iostream>
using namespace std;
int main()
{
int a, b, add,sub, mul,mod,did;
cin>>a>>b;
add=a+b;
sub=a-b;
mul=a*b;
did=a/b;
mod=a%b;
cout<<"addition ="<<add<<endl;
cout<<"subtraction ="<<sub<<endl;
cout<<"muliply ="<<mul<<endl;
cout<<"module ="<<mod<<endl;
cout<<"divide ="<<did<<endl;
}

// 08 Uses of relational Operator


#include <iostream>
using namespace std;
int main()
{
int a, b, lessThan,lessThanEqual, greaterThan,greaterThanEqual,Eualto,NotEualto;
cin>>a>>b;
lessThan=a<b;
lessThanEqual=a<=b;
greaterThan=a>b;
greaterThanEqual =a>=b;
Eualto=(a==b);
NotEualto=(a!=b);
cout<<"lessThan ="<<lessThan<<endl;
cout<<"lessThanEqual ="<<lessThanEqual<<endl;
cout<<"greaterThan ="<<greaterThan<<endl;
cout<<"greaterThanEqual ="<<greaterThanEqual<<endl;
cout<<"Eualto ="<<Eualto<<endl;
cout<<"NotEualto ="<<NotEualto<<endl;
}

// 08 Uses of Lofical Operater


#include <iostream>
using namespace std;
int main()
{
int a, b,c;
cin>>a>>b>>c;
cout<<"a>0 && b=0="<<(a>0 && b>0)<<endl;
cout<<"a>0 || b>0="<<(a>0 || b>0)<<endl;
cout<<"a>0 !b>0="<<!(a==b)<<endl;
}
https://1drv.ms/o/c/0afe201f7d584428/EvAHIbQBayBHrpBgwVMUi2oBRb_VA-
eyceX2aymLGPnlSA?e=6iFF7T
https://1drv.ms/o/c/0afe201f7d584428/EvAHIbQBayBHrpBgwVMUi2oBRb_VA-
eyceX2aymLGPnlSA?e=5SmdgT

// Swap two number


#include<iostream>
using namespace std;
{
int a,c,b;
cin>>a>>b;
// Before Swap
cout<<"Before a="<<a<<endl;
cout<<"Before b="<<b<<endl;
c=a;
a=b;
b=c;
cout<<"After a="<<a<<endl;
cout<<"After b="<<b<<endl;

You might also like