You are on page 1of 61



       
          & ++  # ,  -( )  *+

0  83+
67#5 & 123=   9: . 0@ ?
) ) 
. A

 A  -  EFG * B0C D0  )   2


 # # I: -
Khal_i_l@Yahoo.com


#W+ V0
2007/11/2

#F 0
#F   ++  :
& * # . 0,1,2,3,4,5,6,7,8,9,10 &#F  :g2 A,B,C,,X,Y,Z  90g-I . a,b,c,,x,y,z 
# . ! % ^ & # 1r st   { 3F ++&#F . Cout 23 - 3 cout ~-#+& :
 ~-#+  + 83+# ++  ) ~-#+
>#include<iostream.h
// My first c++ programming
)(main
{
;"cout<<"Welcome to C++
;return 0
}
# : ~-#+
 #3& )( =   iostream.h 0
  +I I # , ++   0
 & A   I # I    )   # ,  0

  2 )    +
   , 0 =  t & include # ,  7 B3  2 0
 0  .h#  Header file
{
 C  ) B 0C#   -

 , = 5- C
 * #s C g#+t t 3  2- ) 
C #~ , =     2 #  1 =  0  )  2  = ( #  1 ) 
 ~-#+ {- )(  2#+ .

&
+3 include #   # 9# 1  2 D+ 3 #  1 +   ( 
 B 3 9 #* g
, Preprocessor directive  =#
 0     (0  
 (  1 + 

 ) G # 3&    ) ~ -#+ 


 =#    0
  # r ) , ~ -#+
) iostream.h ~-#+{  1+ . (#
 #3+ -r  , //  9# ? - *     9#  2- B B 3 # 3* 0
,
( + - B  ~# +     * 
0  C   ~ -#+*1 * #
 ~ -#+ ( g#+ B   , ( g#      # 5  1 ~ -#+  20C
#  , 2   =2 
# ( -& , ~ -#+  C  B   * ~ -#+

#=  )( *0 


 A-) {7 =2  (   &  0   A -  3
#
C (   !   , ) 
 ~ -#+     #  g#+   {

B 0C* 0 , *     * 0 )    1 ) #


   ~ -#+
*0 , -  
, ({7 = + ) 2&   {  B
6 7 
 { ) G. 20C D0*0 C
 #3
{ r B0C  main 3:#* 
 1  
 +
,   = 2   ++3 ~-# )   (-
 , =   1 g
 g#+{
. 20
)  #3#
 
 { ~*+ *    =3 . 3:#
 # 3 + V t  cout  0     Course output  0g0  ~2# t

5 ) E- , Unix cout

 :  #   ? *  B 0C 5 
#2 B3 #g I#.
  

 : *# )   A iostream +=  +3 2
1* B3 GI #  
 * GC cout <<  #+ *
- *

  ? *  B . cout :
{ g* #+*- -) G cout 5 *  G   2 # 5  B
g-+  )  1 5 :

*  * 1I #   + "Welcome to C++"  0g   + *  G 


 # =  =  GC  # ,  GC       1 # t ( -)
 0r
B0C5 , -~   ~-#+
 :

 0I#   3  ) (-& ; W


 0s  2- ++3g g# 0 1
 1s  2
, W 0g g#+  : 0 2
*2 3    1
* 0 B0C? * .
3-   0s
W #r ?  )( 
:+ .
 1+ #3&
{ # return 0; B0C

2-  , ~-#+ * # s =#2-
g ~-#+ .
 #3& () 
#
}  * =3  2- .3:#
# + 3 #7  ) .++ ~-# 1
0CI# :
 )  #   cout :
 { = )  #  -+ B 0C  {  ,
:
 #   )  {  ) (  #W)   #W 1   ) 2   1  F    g#+
 W3+#. -
 
- #  - # C   #r )  # g 
t   F * 1I #
 1+  #- #C 1#(  :

cout<<"first datum"<<" second datum";


 3{  0*
~ - 2C
- 1  C&   8) 
#

+
. 
: 2   5 B0C 5*8=40 #I G
r)
cout<<"5*8="<<5*8;

cout<<5<<"*"<<8<<"="<<5*8;
=   , ~# +  #    )    
*   # +  #F  * ++ 3 
, # I 1 * # 1 +  + { #  #r ) #I 0   
:  3 0g   
cout<<"5*8="
<<5*8;
:  1)
s )  
23  
cout<<"5*8="
<<5*8;
 2- end line     endl  0  t    = #  B   0
:  #I 0 ) )  #3
cout<<"first line"<<endl;
cout<<"second line";
: 2  
cout<<"first line"<<endl<<"second line";
Escape # 2 # { B 3    st)  #{
#  * 0
  ) 
  # F  ,  5 B 0C -+ #  C  * :
 
Characters
-  -g  - 
 GC  
  
#{  , ~#+0

 # ,  
    9  2 F \ 9 # # F   * 9  9 #
* 0* 1 , s2I  B0C \ 9#5   02I  :
;"\\"<<cout
g  * + {# :
{#

?#

\n

  #

\b

 )3 B0t

\t

#) 7 )

\r


#  B  #3

\a

-I #g

'\

 GC C+'

"\

 GC C+''

?\

 GC C+ 2 ?

# :
 #    
 )   # *
5 , RAM :  
  = )  2 9 t
-+
- 3F  , # -+ = *  )  2* 1& ~ -#+ 
0  ( ,
 -+  
 C {{ s  # 3  -
s
-    -+
 * 2* 1{ .
1  0# *E- 2 
C 15  )  -   E 3  # 5C   (+
,0x270f222a   1{ 3  t    9 t  Gt -+ )  2 

{ C 2 = t #  CI   Gt  { 7  0C 12 3* 1


 # , #  
&  *g   # r  0 #  =   0t

F ) {  .#
#    , g#+  F ~-# 1 {
. 20C
 1+t( .
)  ) ++   #  1* ( #GCI (C
 : #
   = ) 2 9t  0t   Gt* =   2C # + , #     #
  = 1#  #  3F. ~#+

- # :

- # 0 {    #
 C 0t   #
 

- F -+  3* 2* 1    (0 -+.


&
- : 3:#

{: Integer 6


  9t 63&C {{ ) ( ,*   

  +  ,  +
* = # # int 0 Gr #F & Integer  B* =  #
# * 2 # :
;int number
* # 0 ) #  #rF =   1 #   0s :

;int Day,size,ID
: t
= t  = ) 2 9t#   =  # = * 1=  t
=  # t0) , 2t a #0 10   - b #0 5 
:
;int a,b
;a=10
;b=5
   0 + t#5  * 3  0s  2 1 :
;a=10,b=5
 t  )  #0 10 :
;a=b=10
  t B3. 1303
    t
*#+   7C V  { #s :
;a=5*10/2+6
3F = F -~ * 0{ 3= . #0 (t
  
 1* #+: 1r # 7 #
;b=10+a
G :
   t0
 303
;b=(a=10)+5
= : :
  #0 t =  0 ) :GCI 2C :
;int a=10,b=a+5
    0g 3:
;int b=a+5, a=10

 #2E =# ? & A 0C* # +    3   = )  a #


*# *  , b # *) A  a
b B #* # a # .
=    # 0  # 3 { ) 6 *   # 3  = ( )F =  9 t 
{{ ). 8
&  #5 #
C B ) 0# )   (-{
B 0C  *
 t
* 1*
:
;cout<<&a
# s   (  #  1     B EC -+   *
  2* 1   2 9t
 ( 9t  #r * BE   1 # ,   =       # +
 * BE  #s #   :  B3{ overflow  3

5C  2 :# .
) =  (- , 2 9t9t 
) {  { ( -   -    # +  * = ( -) B E   B 
#  9  3{ 2 #W  +  *  BE 3 .
    * B E  # = gF =#    0t # B , #
 
 Byte  +
 # 0 { C 6  
    2   4)   =#
Borland C++
,   2   * =gF )#t # * sizeof 1:
;)cout<<sizeof(int
* # #= 3F (gF:
;int a
;)cout<<sizeof(a
 = gF # { )   2 6  ( 
 32767 (  #
. -32768
C 
 :
;int a,b
;a=32767
;b=a+1

;b= "<<b

"<<cout<<"a= "<<a

) g  :

 +   #  2 * BE# ,  :{  3 ? { 


   ~-#+  F )  1 *   ~ -#+  #  ( , 0 5 # + )  
 ? tF  )#*   ( - (   ) + 3 ( -& A 2-  ~ -#+
 (  1 * 1
 *+W 1 5 ~-#+    ~:
,  *+W *+W g{  

)( .

{ 6
: Long 1


int ( * BE# , ( #+ = * ## (  
:
;long a,b,c

  0s*: float :


*  1&C { {{  ,  *  #3* ##   

?  1 5:
;float var1,var2

{ * : Double

 1r
float ? (-  #+  #+  ,*# #( :
;double speed,gravity

{: Character )#


  9 t{ # &  g&    1 9 B
# @ , ! 1 r  st
*#  :
;char a,b,c
3( {# 
GC  (*7#   :

;'?'=a='A',b='7',c
) { )  #{ )# F
-  #  {{  & A    = #
# 5  2 9t ASCII code      +C  C  1 r F , {{ s 1
# F ?  F  &  ,  C  { #  # g B I # ) = ( -   
.    0
   t  A B
G{ # A ( 0   ) 65 #      
) r
 2 :
 # t  65
;char c=65
cout<<c;// will print A
I#   #{0 0  - :
;)cout<<int(c
& # { )#   #  I ( -) {{ s #   t  )#F B
#  
int* . V
{
 1
- # :
) G t :
   =#0{
 1
- #
  r) , A
;int a=5
;float b=a
) 1 + ( -  t a # = b B{
1  # a # B
float = =
, (t {
1
{ B3 1 :0 & A 
 =#  ( ,  :0# 5
{
(
= gF # t   # s t ( , = gF
float
. int  #+
  # t =gF #+ # B = gF = (-) #s t {
1
#3 , (s :
;)var1=type(var2
 :

var1=(type)var2;
G
r ) . # + = &g{ # 
var2 #  var1 # 
-
type F
:  1r A = 6{s # B F #  t
float a=100;
int b=int(a);
: # 3 #
:   #  = 8
7 
. =# + . _ under score 0 3 W#5 9# r st
# B0C {
 2  0 :       0   ,  0
)  g{ 0 
 . 2) s
*
:
g{ 0 
auto break case catch char class const continue default
delete do
double else enum extern float for friend
goto if int inline long new operator private protected
public register return short signed sizeof static struct
switch template this throw typdef union unsigned virtual
void volatile while
: 
r
,# +  2 #*  C  2 t    2 #     2- # 1r 
r
:  1r , const 0   
+3 # #* 1r 2 #*
const int a=100;
const float pi=3.14;
: Expression #+*
. # 2 8#
= -  C
 #  #+* 

# *G : Operators


*G  
 s
* * 1C 2
- .
# {: 3
  
  *0 { 3*  1r g# ,  :
#

*

g

#

#

3

 3

1*G  3t3  &C {{ { B0C


3 r *   1
  1*3 (-) 3&C {{  ~  (C
 F 3  -~  3
2 B 0C 5  3  C G  ) 5/2  ~
2 & A *  
 C r ) ,  # 3
{{ s  = ) ~  C , 6{ s     1
2)  3 & A 4=2*2 1 B +

s
0  , 5 B   *  )#t   + *     +C  C b , a 
: {{s
a%b=a-(a/b)*b
* #+C 3F (3F = 7 # &
 0# { F  3 
   2
&
 & B 0C*  * G  #   3      3 3  B  =
G*: #+
* 0 g#  3  B r) ,
)5+6*7/(2.5+4
= (3F :
5+6*7/6.5
5+42/6.5

5+6.4615
11.4615
) { ) ) 1* 1 ( 0
 {  V*G {.8) 3
# { 3#: +
 # -   g# { 1*  3 , = t 1*3
G )    *= :

=/

=+

. %= =-

G
 :
) r
;int i = 10
; i += 5
 #3 * -r 5 7 i  B= =  t~  , i B
 ):#30
;i = i + 5
#  9  :
G*3  9 -  #*  . 6{s F
* i  G
 
: 11
* 1 9
, ++* 1
r) , --
; int a = 10
;a++
a *
: 10
;a--
* G  9    
*    )    r  3   0+ ?  A
+3=  #:
;++a
;--a
 #  2
(-   # 9  )  *+*  #+ # * #+ :
;int a,b=20
;a = b++

, = =   
 b F
) 
 a 20 (-& A = b    t a B
. 21 6+ 6{s
 
   # #   0+ :
;a = ++b
)  a
 g 21 = (-& A )7 F 21 6+ b B=  2  t
 g. a B
    ##  #  )#) G  , 2 )#    #3 :
;a++
;++a
  B0C D+ B # .
# *: :G
    ) 1* 3* 0    +*    G = *  #

B 0C
, 2)#W) G*  
0 :GC :
#

*

==

3

=!

3

>

 #+

=>

 #+ 3

<

 #s

=<

 #s 3

g- *
{ #+  B0C  :GC #    True 6{ s ? , False)   
 0 G
 ++ True 1r  g* ) #+ 1 =# :GC # r ) , #  False
 C+ : 1 +
;)cout<<(5>2

. 
  :G* #+* 

:  #
  2g-  F # +*  20*g   # sC #+*  8# 
# 
:   , False True 
: && And #
 {{s 2 8#  0  #*  #+* G{{  s #+* g-

:   #+*  #C B A #) (0C   +  g


A

A&&B

False

False

False

False

True

False

True

False

False

True

True

True

: 7  #+ 3 5 &# s C+W =  0g) 


cout<<(10==10 && 5>7);
: || #
: A 67
g{{  s  #* F{{  s #+* g- )(

A||B

False

False

False

False

True

True

True

False

True

True

True

True

 #  : ! Not

 #F * #C B0C 1 * #+ F


 g {{s
 * #+  W ?  *  {{s #+ :
!A

True

False

False

True

 0g 
: 1 C+
;)cout<<( !0
I :
)  D+ t-= #0  =  ~ -#+  )   =   
  , ~-#+    #     )  {  ) # +~    #
G 3F - 
  C
g 8= V 0) r 3
= 20+3   r) ,
     *- )  
  g#+ #  1   2) # =    
-
 =  ~-#+0 .
=  = #0 t #g  1* (*+ cin 1I >>  :
;int i
;float f
;char c
;cin>>i>>f>>c
: 0r
G? - 

) 1
 ) : EFG&  0r
   1 ~-#+
  3:#G A .
 0  g-#   1t3  C 6{s 
 # C+* .

int number;
cout<<"Enter number : ";
cin>>number;
cout<<number<<"^2 = ";
cout<<number*number;
1 sF 2# 7  2* ~ -  C+ {{ = 
s  C +  ~ 
-# -2
: -r B0C  &3 1sF  & -r #W
float no1,no2;
cout<<"Enter two numbers :";
cin>>no1>>no2;
cout<<no1<<" + "<<no2<<" = "<<no1+ no2<<endl;
cout<<no1<<" - "<<no2<<" = "<<no1 - no2<<endl;
cout<<no1<<" * "<<no2<<" = "<<no1 * no2<<endl;
cout<<no1<<" / "<<no2<<" = "<<no1 / no2<<endl;
: 13 8{ F3 3{ ~-# -3
float area,length,width, circumference;//F3 ,
W , #C , 8{
cout<<"Enter the length : ";
cin>>length;
cout<<"Enter the width : ";
cin>>width;
cout<<"\nArea = "<<length*width<<endl;
cout<<"Circumference = "<<2*(length+width);
:  *1{ ~-# 4

x+y=no1
x-y=no2
: y x  #t no2 no1  G F
float x,y,no1,no2;
cout<<"Enter no1 : ";
cin>>no1;
cout<<"Enter no2 : ";
cin>>no2;
x=(no1+no2)/2;
y=x-no2;
cout<<"\nx = "<<x<<endl<<"y = "<<y;
. y  g I x 
* = x  g y  * {g 1{ =
: 0
: ~ -#+  & ) - 1
int a=10;
cout<<a*5
float b=14.5;
cin<<b;
=   B   2
{ #
0   ) 3  C # +*  F C 1+ 3 g-#  2
. #
0 1.60934 = F 
1= 0*  , 2C+ 

#5 
 *   D+ ) 0    g# 1 0    ) , ( ) # -  C  0 
)   G #*- 2& #+ 2& , #s    * 1{ ~-# g#   
  -r # , #r #+~   3  -   3F 1 303 1 g = 
  -   1C  # 3F#E ,    1# 5    
 , A = )  1g W#5 F  . g#+
G
 1g W#5
 {   F =   * 1 B0C{ D#5 r ) , (C
 
 3)  g#+ { ,  )#
(+ 5# 5
  0g    0 : W#  *
 : g#+   - # ) 10  #+
.10
  
 1 g W# 5*  

+    C# #*  2-& 1 (   * )#
  B0C#5  
* 1)  . 2
 0 : If statement
 0   0#5  ) 3:# , 0# 2+ :
) #5 (
0

)if(condition
statement

#5
+C C*  #+  {
 B 0C#  :GC    
(6>5) G ) (4==8 # .
r) ,
r :
 ~-#+ C 1+3 #  . 10  #+
;int i
;cin>>i
)if(i>10
;"cout<<i<< " > 10
 1 +  -# 1* (    # +  1 # s  #  False 1
=  C  #
. True
 * (0  =##5
{      C  g* # +  = #+t  ,
) G ~-#+ ~-#+#  D3  I B  , 15&  2- ) 10   # +  
) r
* #+ , 1  { #5 6+  :
)if(1
  G  # 5
    + # 5  #  V
*# +   r ) ,
 )  , ~-#
#  { D :
;"if(0) cout<<"It's zero .
 #5  ) D{
2:  :
;" if(4) cout<<"True always
  0  #r { D# 5 ) = ( - 
-
  g*+  
   =2  
0  B3 g#+ : 0
)if(Condition
{
;Statement 1
;Statement 2

;
}
  0:Block g#+
  = 1 C
g  *    {
B0C #sC 1 ,  0 +  
   0
}    2 { ,    
   g B 3   ,  0 = 3 
   0 )
 ~-# ~-# 1 ++3
 0  ,   {
  B 0C  0 1 # , =
* ) # ##* # (-) 0   2g B3  #  #{ 2  0
  , 0 #C ) g  )
3 *  )# 1g  ,  0 r  
+ :
{ // first block
;int x=1
;{ // second block
;int y=10
& 6{s #* # cout<<x; //
}
? & #* # # )  g cout<<y; //
}
 #* :


# *  )#  main
*  )  )# 1 g  ) , r  
C # x # :
;int x=10
)(main
{
;cout<<x
;return 0

}
 0 : if else statement
)  r D3  + ~ -#+   i    - 10   # + 
  5  =
 , 1*g#s ~-#+ B0C* 1 ,
 0# 5   -# #  # ,
  # + *~  
,
s 2 :
)if (condition

)#(

Statement

0

else

Statement

0

(- { D#5 )  0g  1g * = if  , = {) D 0g


 1g * else  =  .
 r  D3 :
;int i
;cin>>i
)if(i>10
;"cout<<i<<" > 10
else
;"cout<<i<<" <= 10
* ) #5 # +  t3 *G  && || ) =  (-+ 9 g
G# 5
  -r#5
  , A    r ) , short-circting #  B 3
)
  (p&&q  {{ s  {{ s #  p    - false  = =  +
 , q ) A#5 ) =  (p||q+  q . True {{s p  -
g     (-& #   -F2- . ~-#+


  G  C    1 + C B 0C  3 ) #     g  3
# s
) r

7 #5 ) ) g# 0 ) 7# *  B 0C ( 3 a*  ) b  0
#5 {{  A :
)if(b>0 && a%b==0
 
 * +- C  #+* && 1 :
)if(a%b==0 && b>0
) 2-G 7#C 6+ ~-#+ , (-& A  b    - 3  { = 3) # 
 B0C 3 #   )#* #  ) + 3 2-  ~ -#+  )  # 5 & )  =
  b = 0) # s  #++ *a%b==0 #+
 1 : 0
  
  1g W#5F 1&#  1r :
)if(condition
{
;statement
)if(condition
;statement
}
)else if(condition
;statement
else
;statement
?
s # , =2 (+ B else 1 if + + 20+# .
)  r D3 =  i  C+W = 3) 10   #+  
( -   # s  3
, 10  - #*- 1
10 t3- -) 2 #s  0:
;int i

cin>>i;
if(i>10)
cout<<i<<" > 10";
else if(i==10)
cout<<i<<" = 10";
else
cout<<i<<" < 10";
: 0r
: = G   A + 0  #+ C+W -1
int i,j,k;
cout<<"Enter three numbers : ";
cin>>i>>j>>k;
if(i>=j && i>=k)
cout<<i<<" is the largest";
else if(j>=i && j>=k)
cout<<j<<" is the largest";
else
cout<<k<<" is the largest";
 (  = -
#7 # (-& A #( =  * - # &else ) FG
. k 2-  G) j #+  &i
: r
:  #)    0  1 #* ~-# 2

# s  3  
(-) 2 B0C =3  9 *  * B0C #* # )

B0C ~ 
-#+ ,
 
G) 2 B0C (3 C #  *
: 
int number;
cin>>number;
if(number%2==0)
cout<<number<<" is even.";
else
cout<<number<<" is odd.";
( 3   ) 4
( 
*  -& A , (!(number%2)) : #5   
,  { # 5 6+  F #   0 !   1 *   = 

# s
2 B0C
B 0C   1 * 
   & 1 *  * 
 =  ,  C 4  = )
. 3  1* 

: ~ -#+     -2
int i;
cout<<"Enter number : ";
cin>>i;
if(i=0)
cout<<"The number equal zero.";
else if(i>0)
cout<<"The number is positive.";
else
cout<<"The number is negative.";
3

    1 1 * B0C #* ~ 
-#+ # 
. A  =  : *  C+ 
1*  (  , # 


# 0 #   t(  = - ) { , (i==0) V( i=0)
#5&
 +  -? ,  -r B   &C+  0   = 0) # s 2-& , + = i
if(0)
Blue + B b G
r ) , 1  #{ 3F
0 = C+ ~ 
-# 4
:
char c;
cin>>c;
if(c=='b' || c=='B') cout<<"Blue";
else if(c=='g' || c=='G') cout<<"Green";
else if(c=='r' || c=='R') cout<<"Red";
else if(c=='y' || c=='Y') cout<<"Yellow";
: else t~  -#+   I 
if(c=='b' || c=='B') cout<<"Blue";
if(c=='g' || c=='G') cout<<"Green";
if(c=='r' || c=='R') cout<<"Red";
if(c=='y' || c=='Y') cout<<"Yellow";
,   #   Gr + = 0) &#5 D{( -& A 1)  
&
 ) - r   )  
,  +  # 3  +  = 0) -r D{ & D{ =
. ~-#+  C#  + #5 1 +( = -) = & #5 D{

: Switch statement 1
{ 0

 {  )  ,  )#F 20 {     - 
1 t   if 1  4  + D 3  r) 
G
F V  9 ! ?  2  = # & 3 
1 )& G
 1*

 C , ! +-  )( #{s
- #{ ) ~#+  A- 
1t 
 2+# 1
{ 0 t 1) G
F #)
 0 , 1*   ( D 3:
(# #+*
) F
}
: F
1

: F
1

............
::0
0
{
switch(expression or variable)
{
case constant:
statement;
break;
case constant :
statement;
break;

.
default:
;statement
}
F *   #+
 3F    =23F = (- ( .
 {  case  C = ( - +  r  3 1   * # +  #

 C
) switch  3 ( ) D{ (- 0g  1g *  {  ) = ( - {  
{ , { = (-) default   1g * = { D{    3 
 3 ) #  A .2+
 : break 0
{ { ) * (-   1g* ) 2 break
 #t     0{
, 1
 #7  & (- =  ){ B = { D{  ) =  ( -    ,  20 
  6 0 #{ . break B
  V - 0g   F ) 1g {  {  {  )      A
& :
case constant:
case constant:
;statements

: 0r
 ~-#&
:
;char c
;cin>>c
)switch(c

{
case 'b':
case 'B':
cout<<"Blue";
break;
case 'g':
case 'G':
cout<<"Green";
break;
case 'r':
case 'R':
cout<<"Red";
break;
case 'y':
case 'Y':
cout<<"yellow";
}
   3F  g
  # C =  3F G
* = C 1+3 +F  ~#+ 2
: 3{ 1*
float i,j;
char op;
cout<<"Enter number and math operator and another number : ";
cin>>i>>op>>j;
swich(op)
{

case '+':
cout<<i+j;
break;
case '-':
cout<<i-j;
break;
case '*':
cout<<i*j;
break;
case '/':
cout<<i/j;
break;
case '%':
cout<<int(i)%(int)j;
break;
}
: 
B0C : + ~-# -3
Choose number to find :
1 Volt .
2 Current.
3 Resistance.
Enter your choice :
 t 3 ~   -#+  0  *
-   2g  3F = 1 { = 
.  #  t0 1r , 2g 
: ~-#+

float V,I,R;
int choice;
cout<<"Choose number to find :\n";
cout<<"1 - Volt.\n2 - Currrnt.\n3 - Resistance.\n";
cout<<"Enter your choice : ";
cin>>choice;
switch(choice)
{
case 1 :
cout<<"Enter Current value : ";
cin>>I;
cout<<"Enter Resistance value : ";
cin>>R;
V=I*R;
cout<<"\n\n\t\t*****************\n";
cout<<"\t\t* V = "<<V<<" V *";
break;
case 2 :
cout<<"Enter Voltage value : ";
cin>>V;
cout<<"Enter Resistance value : ";
cin>>R;
I=V/R;
cout<<"\n\n\t\t*****************\n";
cout<<"\t\t* I = "<<I<<" A

*";

break;
case 3 :
cout<<"Enter Voltage value : ";
cin>>V;
cout<<"Enter Current value : ";
cin>>I;
R=V/I;
cout<<"\n\n\t\t*****************\n";
cout<<"\t\t* R = "<<R<<" Ohm *";
break;
}
cout<<"\n\t\t*****************";

{0  # 
  t - #5 *  # g#~   #r    , 2-  A
9 #+~     {  2g# ,     
 #      g#
 #~ # + # r) , 1    { 0  #    
 #  
 0C  C 1 {     #   ( ) : 
 #
  
  g#+
 = 2   # ( )    g#  ~ -# # *     2- #
{0 
)     # g#~ #F  2{0 .

2 {0 :
{ 0   C
g& = #  &#  #r 3F# {  
2{7
 1 5 :

 
 0{0# )
:2-  0F = # C # { # .
{0  #  ) : 0

 )  ++3G
-  {0  :
: While loop  0F 1
# 2+ :

(# )
}
;# # 1g
;  9
{
while (condition)
{
statements;
increment or decrement value;
}
C  -  9    
9  1g # 6{s #5* 
. #5 D{ BF #5 #+*  
) +  0{
10 B 1  C& C+ ~  
-#+ : r
int i=1;
while(i<=10)
{
cout<<i<<" ";
i++;
}
:  0{ #   
while(i<=10)
cout<<i++<<" ";
. i+=2;  
9*  - 8)  #  C& C+ 
:     :2- 0{ 

while(1)

: do-while loop -1*) 0F


:  2+#
do
{
statement;
increment or decrement value;
}
while(condition);
 1g=  3)  0 #5 D{ =  0{ ( ) - while 0F (+5
.  0  = 0) while 0F )  , F # 0{ 1)
: for loop 1& 0F
: 2+#
* -# #r &0{
for(0{ * :; #  #  ;9)
{
statement;
}
: for   D3 10 B 1  C& r G
r)
int i;
for(i=1;i<=10;i++)
cout<<i;
: 0{ # 1)
(-? #5 # =
  , i++ ; 10 3  #s i  ; 1 3 i
. for 0{  #r   A0*g ( 2)( :# &, while 0{ ) #
: 0{ 
 1 :   t  

for(int i=0;i<=10;i++)
: 1r F 20  #5
C  #r 0{0   

for(int i=1,j=-1;i<=10 && j>=-10;i++,j--)


:= 
2 V =20= 2  0{ #sC F  

int i=0;
for(;;)
cout<<i++;
.  2- B i   9 +  

:  
B #E-
int i=1;
for(;i<=10;)
cout<<i++<<" ";
:0 #E- , while 0F ) (-? #5 # 1)&(  -  + 0 
 #  , while for  1
{0  #W for(;i<=10;) == while(i<=10)
:  2) 

: break continue 0


      = , 0{   B 2-   0 continue
g{ 0  t3
: 20C 67
 r , 0{  #t  
2) break ,
 
*

for(int i=0;i<10;i++)
{
cout<<i<<" ";
if(i==5)break;
continue;
cout<<i*i;
}
. cout<<i*i; 0g(  =  -  , 5 B 1  C& C+W = r) 
: 0r

5 # G
r) ,  *B 1  C& #7 1sF
* # - 1
: 6{s C &# g  ~  
-#+, 5*4*3*2*1
int i;
long fact=1;
cout<<"Enter the number : ";
cin>>i;
for(int a=1;a<=i;a++)
fact*=a;
cout<<"Factorial of "<<i<<" = "<<fact;
    #   = :  1  t a *#**  * =
. 1   * , ( g # * 3  #s*
2 t = a )    * fact #    # 7 = 0{ 1  ) 0g)
.
0 #
fact  
0{ 2- C { fact # B
   =  0
F  3 int 6{  #  & long ( - B0C fact )#C
.() 8   *9t   )   2 (gF 
G
r) , C&
:  V - )  &C+W 2

 0: C+
;cout<<1<<" "<<2

 C+*   C#3? 2- ,  * +   - - #  F ~ -#+ C+
)  t { 0 :
;long a,b=0
;for(a=1;a<10000000;a++)b+=a
& A {? 0       9 1 10000000 B 9 +   
9 ? # 1 (-9  C#, C+  {  0F 2 3  0 ? , # 
=    #) * 2 C+ ~-#+  1 C+W :
;" "<<cout<<1
;long a,b=0
;for(a=1;a<10000000;a++)b+=a
;cout<<2
  C+& C   1 V -  ) 100 B   t # F # 2 \r  

  # B   #3:


)for(int i=1 ;i<=100;i++
;cout<<"\r"<<i
C    # 3  C+W =   3&  )  V -  C+W  * ( -& , # 3  
 *
  2C+W 7
 #     2-    -  ,    # - * 
C#    100 ,  C+  # - 1& C )t 3  -  0F ? # 1{ 0
 3  :
)for(int i=1 ;i<=100;i++
{
;long a,b=0
;for(a=1;a<10000000;a++)b+=a

cout<<"\r"<<i<<"%";
}
 # {  +r~ # ) #  1r #2E C+ 0 ) % 9#) 7=
.
:    C+W 3
for(int i=0;i<255;i++)
cout<<i<<" "<<char(i)<<" ";
:
g  # 2   
0{ 4
for(int i=0;i<10;i++)
{
int j;
cout<<"

";

for(j=0;j<=i;j++)cout<<"\b";
cout<<'*';
for(j=0;j<i;j++)cout<<'*';
for(j=0;j<i;j++)cout<<'*';
cout<<endl;
}
  #  ~ -#+  - D 0*   B0C rr -r 0{  1
1*g = (0C  = 2 
. 1*  #W ~ rr C =~ -#+  - -r C D0* 9- = , #2E
 5 B 0C  # { ( -  ,  *:  #{ 0{~  

 -#+ 5
:  + B # F   =  B 3
for(int i=0;i<60;i++)
{

long a,b=0;
for(a=1;a<40000000;a++)b+=a;
cout<<"\r";
for(int j=0;j<=i;j++)
cout<<" ";
cout<<"We "<<char(3)<<" C++";
}
cout<<'\r';
for(int i=0;i<75;i++)
cout<<" ";
for(int i=0;i<60;i++)
{
long a,b=0;
for(a=1;a<40000000;a++)b+=a;
cout<<"\r";
";

cout<<"
for(int j=0;j<=i;j++)
cout<<"\b";
cout<<"We "<<char(3)<<" C++";
cout<<"
}

";


* =E#+~     #r  #+# +~    #   #  1 * ,~ # + 12 3 2*+


g#+  = 3# +~   3:# #  B~ ) . sub programs  C#  # +~
 ++  ) C# B3   . functions  #  + # +~   C# 1
F B0C C t# ) 2~ .  0t
 =3  , C
- B  # ) .
# +
{ ~-#+ *:5 B0C :
>#include<iostream.h
GCI C type function_name();//
)(main
{
C  function_name();//
}
* # type function_name() //
{
 =3 //
}
1*3 FGCI *#   main     2  =  g ,  2C {+

1*3   =3  
  *   , 3:#  
 3)  20+  ) :
 , 2   
* # 1   1 +  3:#  , 2:C  1 

BF 
,  {7  ) 6* #  =  

   
+ 3  ) A
* , 2 #
-  
F&
- #0 3    -    #
,   =  ) 
 
void )  ,  =  
-    1 + 2:C
)
3   
. int

8: 
 B 3  -+  , 2:C       - 1+ 3   
:  ) 
  8:
  7
, #+
function(a,b);
. 8:
  b a F
:  # 
    
G
r ) , C    B  
    2:C   C   
:2 1# * # 
int square(int x);
main()
{
int i;
cin>>i;
cout<<square(i);
return 0;
}
int square(int x)
{
return x*x;
}
 
-

  - ,    
   ? *return 0  F
1+ 3 , square    = integer D 3  r   )  2C  
  
. 6{  
F 
. G) 2 #*   #  , W
 0s  2  C GCI # (- #2E
:    #+  
 : r
float max(float x,float y)

{
if(x>y)
return x;
else
return y;
}
:  +
 = 1   #r   #+ g I  C  
main()
{
cout<<"Enter number of values : ";
int n;
cin>>n;
int max_value=0;
for(int i=1;i<=n;i++)
{
int val;
cout<<"Enter the value "<<i<<" : ";
cin>>val;
max_value=max(val,max_value);
}
cout<<max_value;
return 0;
}

   : void function


  
     )
, void  2C
-   t 2 ( -   
C # 25 1  ) 2  ) 3:#   #r ) (-  C  2  #
=  ) 2 ) = =  C         ) 8 ) 2    #  
 , () 1gr  +   

 *  C+  0#: 2
)void cube(float x
{
;cout<<x*x*x<<endl
}
)(main
{
)for(int i=1;i<10;i++
{
;" = cout<<i<<"^3
;)cube(i
}
;return 0
}
  ) 0#   0) g#+ #* # )  #* # )  # .
  ) +: 0
 0 C  + {
B 0C  9   B 0C ~# +   +  2 =
. 7 #
  2:C
0 .r B0C  
t     g  7 #    ) math.h 0   , ~ -#+   
 7 #

:



s

*
 

acos(x)

g*

asin(x)

1E*

atan(x)

x  #+{{ s  #s& x  #

ceil(x)

 

cos(x)

e  x )

exp(x)

0

fabs(x)

x  #s{{ s  #+ &x  #

floor(x)

*+= r
0

log(x)

10  =r
0

log10(x)

xy

pow(x,y)

g

sin(x)

*# g

sqrt(x)

1E

tan(x)

: (* * = += r


0* # g g C+   
r
#include<iostream.h>
#include<math.h>
main()
{
const double Pi=3.141592654;
double x;
cin>>x;
cout<<"Sin "<<x<<" = "<<sin(x*Pi/180)<<endl;
cout<<"Square root of "<<x<<" = "<<sqrt(x)<<endl;

;)cout<<"ln "<<x<<" = "<<log(x


;return 0
}
= #7 9  )   C 180 B0C 23  g    1
{0  g E  #:  B
 .
 0 # :
 
-     0   {
B 0C  2+ -  *: *  C { ,
{ # ) 2
-  g    0 =   , 2:C 0# 
 - 0

 .
 2 83
{ .h B0C
  #- 
  +
C( ) (t3- - B 0g {
 0 B0C  ~-#+  #- ( ) ( ,
= )  0 #  - ~-#+0 3:# :
"#include "file_name.h
  =  GC  0#* (-&   1+ ~#+  0  ?
  =) 0 2 . 1+  iostream.h 7
r  +*  1 0 # :
)  0#      ,& B  delay() 2  
 ?t  #  0F
? , #  -r type() 2
 C+{ #  # + =  # ,  )#F  )#F
2-t3  )( , delay =  0#   )( :
>#include<iostream.h
)(void delay
{
;long a,b=0
;for(a=1;a<40000000;a++)b+=a

}
void type()
{
for(char i='A';i<='z';i++)
{
if(i>'Z' && i<'a')continue;
if(i=='a')cout<<endl;
delay();
cout<<i<<" ";
}
}
,  3:# ~ -#+ 0    
- = , our_finctions.h   (  ?  = E { 
- =
:
)(
#include <iostream.h>
#include"our_functions.h"
main()
{
type();
return 0;
}
. 0g V - ) 0
g

* * B0C )# )  0C ( - # -   -##E-   { ,  g#+  -


 g-# ~#+ ) # - { 1  ~-#+ B ,  ) C= +     :
1   ~-#+#+  {  +*5   (g#  0 F * # 3 ( 0C
*
. #
2  ) #  g# 1 ~-#+ #r , =     2 #  1 = ) 20
) ,= C   .
3  ) 9 ~-#+    ) #~ , #  9g  C ,  =
= ( ) )  0  . 1
: 0r
- 1 
 g { = 4   #+t3  )( max 
      # +
 
  :
)int max4(int a,int b,int c,int d
{
;))return max(max(a,b),max(c,d
}
2 
+ {#  1# 2  {{s ( F B0C   
 )#F#+ #s  )#F :
)int WhatIsChar(char c
{
;if(c>='0' && c<='9') return 0
;else if(c>='A' && c<='Z') return 1
;else if(c>='a' &&c<='z') return 2
}
)(main

{
while(1)
{
char c;
cout<<"Enter char , to end enter '.' : ";
cin>>c;
if(WhatIsChar(c)==0)
cout<<"It is digit."<<endl;
else if(WhatIsChar(c)==1)
cout<<"It is capital letter."<<endl;
else if(WhatIsChar(c)==2)
cout<<"It is smal letter."<<endl;
else if(c=='.')break;
}
}
  V - ~#+   , math.h # 0 

) sqrt()  0C  3
. # 
:  * #  =* # g g #W F
Xi+1=Xi2+n/2*Xi
# *  n * 0 - 1   B * *  D + )   - *# g  X F
9 *#+ 0 , # 4 # = 4 * # g g I , # C *
. 
+ 
g  , # 15 #  {- , # 
: 
double sqrt(double n)
{

double x=1;
for(int i=1;i<=15;i++)
x=(x*x+n)/(2*x);
return x;
}

Arrays
=  #sC B3 #  , 
V -  20 #
 
subscripts 1:  index # 2  B 3 &   .... , 2 , 1 , 0    2#
. ) #* & {    , 0
. *+  F

)
 
# s*  )   # s*   n C B 0C {
ar    =
)  
5
n # s*  C , ar[n-1] , ....... , ar[2] , ar[1] , ar[0]
: 

. 6  B0C ar[1] #* 13  B0C ar[0] &#* {


F
: 1 5 
? #*
type array_name[n];
: #sC 10 B0C {
6{  
#sC )
 #*  #3 F
int array[10];
: r= 
) gF #*  -F 1
const size=10;
int array[size];
: 
) 0 : = t  
int array[10]={0,4,8,2,7,2,3};
 2 t3) #s*   , B &#s** +30 2+# 3F = t F
. 0 
: A = #*  I
array[4]=14;


 +) #s* 1  = t , )
 ) Vt #*0 14  t F
: 1r 0{ t 1) 
A = #s* 1  D3 #3 
for(int i=0;i<10;i++)
cin>>array[i];
. cout<< cin>> + )
 #sC 1 C+W =
: 0r
# sC +- = ,  20 # sC *  #- , # C 50  2gF )
 1
=  ,  2 #  # s*  C  = , #sC   #+
)
:   
max()  t
#include<iostream.h>
int max(int x,int y)
{
if(x>y)return x;
else return y;
}
main()
{
int array[50],n,max_value,i;
cout<<"Enter number of elements : ";
cin>>n;
for(i=0;i<n;i++)
{
cout<<"Enter the element "<<i+1<<" : ";
cin>>array[i];
}

max_value=array[0];
for(i=1;i<n;i++)
max_value=max(max_value,array[i]);
cout<<"The array is : ";
for(i=1;i<n;i++)
cout<<array[i]<<" ";
cout<<"\nThe largest number is: "<<max_value;
return 0;
}
C + 3  C&  C  +
  C&  C  C+W {{ s )
 2
: 2) s&
int matrix[10],i,positive=0,negative=0,zero=0;
for(i=0;i<10;i++)
cin>>matrix[i];
for(i=0;i<10;i++)
{
if(matrix[i]>0) positive++;
else if(matrix[i]<0) negative++;
else zero++;
}
cout<<"Number of positive numbers is "<<positive<<endl;
cout<<"Number of negative numbers is "<<negative<<endl;
cout<<"Number of zeros is "<<zero<<endl;
:  C  +# 
) #sC # 3
: F   # #0 #W C 

main()
{
const int n=5;
int l,i,j,k,temp,arr[n];
for(i=0;i<n;i++)
cin>>arr[i];
for(i=0;i<n;i++)
{
temp=100;
for(j=i;j<n;j++)
if(temp>arr[j]){temp=arr[j],k=j;}
arr[k]=arr[i];
arr[i]=temp;
for(l=0;l<n;l++)cout<<" "<<arr[l];
cout<<endl;
}
cout<<"\n\nThe array after sorting : ";
for(i=0;i<n;i++)cout<<" "<<arr[i];
}
:#5
B  100    =   2  )  -r for  0F  )  =  
-+) *  
. )
 20C    {
#+ 2- +C { = temp  #
#    B 0C #  1  { {
#   1 + temp # t =
: 
b a  #   1 +   G
r) , -r
a=b;

;b=a
& A )  0g&? B b   a  ( & , B{  B)   # 3- r
)   t a b   a  , b )#   #3 -r: #3
;b=b
= = a    t b B
   t  ( ) =   # b    9 t
temp  t a B:
;temp=b
;b=a
;a=temp
) for 0F& = B+ temp  1   #+* ) arr[j] #   - A
=    t*  # temp C    t { F = B F k # 0  0

 * , #  C # { =  0 +   t , D 3 2- {  0

  temp  )   # s


) ,     #   ) t0 = ( - C {+
)  #s
) =  + # * 2&  + * #& * # 
{
B0C  ,=  1r5  * #    2- B{ , 0 2  6
      *  : {  0  0& B     C {  0t  , A
  1 +0* #& #C #s= * # -r #C #s= . ....
*  # t   {  0& = B +  =   * #    # ]arr[k
* #& ) 
) ]. arr[i
 { 0 0
) -r  C+
) * 0C 1# BF + { .

)  :: *+
) 
) &F   *+ = 

s & 1   2) #C ,  F  )  


)
 : = (-) *+

s  0 #*0 1& #5 B  -r B*


,

 2 r # 
C B0C {
s 1 s  #r*  + : 
)
. g
. C& C *  
C

) #sC C
: 1 5  
 
) ? #*
type array_name[size of rows][size of columns];
: C
 s G 2 float *  
+ :  
) #*
float array[3][4];
I = ,  C  -r
0 B   &0F t  # sC  2 =
:   -r =
- (C  & #sC 
for(int i=0;i<3;i++)
for(j=0;j<4;j++)
cin>>array[i][j];
: 
) = C+W
for(int i=0;i<3;i++)
{
for(j=0;j<4;j++)
cout<<array[i][j];
cout<<endl;
}
  C+W =   #   C+W = = i  # sC  C+W =  0  0{) 
. )
  2- B -r
 3:#  2 # # sC # 7 1 sF  C+W 44 2gF )
  {
C+W : r
:
-r

 1G3 :
 1G3 Strings  1r
 1r& #  +C )
 C
)#FF   - 030 #*) , *+  9t 2) C++ 0 = 2C+W:

;"char s[4]="C++
;cout<<s
 = GCI C
) {  4 =g   0
  3# F &   0 2
 1G3 {#  2-. '\0' 0303
  I t cin:
;cin>>s
  I    2 6 3   #    # r ,  0 I  
  C
)# ,I  - 1G{
#) B0C = t   ) F getline(s,i
s  0303 , C i &#F #  , 2   0I :
;)cin.getline(s,i
 #5  1G30  V +  ) ,2#5 - ) V 15    .

You might also like