Int main()
Float num 1,num 2,sum,avg;
Cout << “enter the numbers = “;
Cin >> enter 1 number;
Cin >> enter 2 number;
Sum =num 1 + num2;
Avg =Sum/2;
Cout <<”sum=”<<Sum”\n”;
Cout <<”Avg=”<<Avg”\n”;
Return 0;
Data types
User defined types struct,union,class,enum
Derived types- Arrays, functions,pointers,reference
Built in
(i)Integral –Int and char
(ii)Floating –Float and double
Inline float mul(int x,int y)
Return (x*y);
Inline float div(float p,float q)
Return (p/q);
}
Int main()
Float a =10;
Float b=20;
Cout<<mul(a,b)<<”/n”;
Cout<<div(a,b)<<”/n”;
Return 0;
--------------------------------------------------------------------------------------------------------------------------------------
For loop
Main()
For (int i=1;i<=2;i++)
Cout<<”ankit”<<endl;
Output
ankit
ankit
simple without loop
main
{
Cout<<”Ankit”<<endl;
Cout<<”Ankit”<<endl;
While Loop is used when we don’t know the iterations in advance
Known as entry or Pre-test loop
Main()
Int pwd =1234;
Int =mypwd;
Cout<<”enter your password =”;
Cin>>mypwd;
While (mypwd >0)
If (pwd!=mypwd)
Cout<<”enter your password =”;
Cin>>mypwd;
Else
Cout<<”correct Password !!”;
Break;
}
}
Do while loop (integer declaration-do-statements -increment in loop-check the while condition)
Main()
Int i=1;
Do
Cout<<”ankit”<<endl;
i++;
While (i<0);
#include <iostream>
using namespace std;
int main()
// int num;
cout<<"enter the number =";
// cin>>num;
// for(int i;i<=10;i++)
//{
// cout <<num *i<<endl;
//}
return 0;
--------------------------------------------------------for loop-----------------------------------------------
#include <iostream>
using namespace std;
int main()
int a;
cout <<"enter the number = ";
cin>>a;
cout <<"Multiplication of table ="<<a<<endl;
for (int i=1;i<=10;i++)
cout<<a<<"*"<<i<<"="<<a*i<<endl;
return 0;
Output
Multiplication of table
-----------------------------------if condition----------------------------------------------------------------------------
#include <iostream>
using namespace std;
int main()
string a; //string is declared
cout <<"enter the weather = "; //Input from the user in the form of weather
cin>>a; //Input into the system
// cout <<"Multiplication of table ="<<a<<endl;
if (a=="rainy")
cout<<"Pls use umbrella"<<endl;
// if(a=="green")
// {
// cout<<"Go"<<endl;
// cout<<"Once the signal is green u can go";
// }
else
cout<<"Don't use umbrella'"<<endl;
return 0;
-----------------------------else if ladder-------------------------------------------------------------------
It is used when we have more than 2 conditions
#include <iostream>
using namespace std;
class Person
private:
int age;
string name;
string address;
public:
void input()
cout <<"enter the age :";
cin>> age;
cout <<"enter the name :";
cin>> name;
cout <<"enter the address :";
cin>> address;
void show()
cout <<"Age is ="<<age<<endl;
cout <<"Name is ="<<name<<endl;
cout<<"Address is ="<<address<<endl;
cout <<"My name is "<<name<<" My age is "<<age<<" My address is
"<<address<<endl;
};
main()
Person ankush,ankit,rohit;
ankush.input();
ankush.show();
------------------------------------------------------constructor---------------------------------------------------------------
#include <iostream>
using namespace std;
class A
{
public:
int a,b;
A()
a=10;
b=20;
void show()
cout<<a<<endl;
cout<<b<<endl;
};
main()
A obj =A();
obj.show();