Professional Documents
Culture Documents
تعليم c++للمبتدئين
تعليم c++للمبتدئين
& ++ # , -() *+
0 83+
67#5 & 123= 9: . 0@ ?
) )
. A
#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 ) B0C# -
,
= 5- C
* #s C g#+t t3 2- )
C #~ , = 2# 1
= 0 ) 2 = ( # 1 )
~-#+ {- )( 2#+ .
&
+3 include # # 9# 12 D+3
# 1+ (
B3
9#*g
, Preprocessor directive =#
0
(0
( 1+
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 #{ B3 st) #{
# * 0
)
#F , 5 B0C -+ # 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
9t
-+
- 3F , # -+
= * ) 2* 1& ~-#+
0 ( ,
-+
C {{s
#3 -
s
- -+
* 2* 1{ .
1 0#
*E- 2
C 15 ) - E 3 #5C (+
,0x270f222a 1{3 t
9t
Gt-+ ) 2
- # :
- #0 { #
C 0t #
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
;b= "<<b
"<<cout<<"a= "<<a
int ( * BE# , ( #+
= *
## (
:
;long a,b,c
? 15:
;float var1,var2
{ * : Double
1r
float ?
(- #+ #+
,*# #( :
;double speed,gravity
{: Character )#
9t{# &
g& 1 9 B
# @ , ! 1r st
*# :
;char a,b,c
3( {#
GC (*7# :
;'?'=a='A',b='7',c
) { ) #{ )# F
- # {{ & A =
#
# 5 2
9t ASCII code +C C 1r
F , {{s1
#F ? F & , C {# #g B I# ) =
(-
. 0
t AB
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 )#FB
#
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 =
(-) #st {
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
#
#
3
3
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++
,= =
bF
)
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= * #
B0C
, 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-
A&&B
False
False
False
False
True
False
True
False
False
True
True
True
A||B
False
False
False
False
True
True
True
False
True
True
True
True
# : ! Not
True
False
False
True
0g
: 1 C+
;)cout<<( !0
I :
) D+ t-= #0 = ~-#+ ) =
, ~-#+
# ) { ) #+~ #
G 3F -
C
g 8= V0) 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;
1sF 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# 10
) , () # - C 0
)
G #*-
2& #+
2& , #s
* 1{ ~-# g#
-r # , #r #+~ 3 - 3F 1303 1g=
- 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
1g 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* #+
{
B0C# :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 B3 , 0 =3
0 )
~-# ~-# 1 ++3
0
,
{
B0C 0 1# , =
* ) #
##* # (-) 0 2g
B3 # #{2 0
, 0 #C ) g )
3 * )# 1g , 0r
+ :
{ // first block
;int x=1
;{ // second block
;int y=10
& 6{s #* # cout<<x; //
}
? & #* # # ) g cout<<y; //
}
#* :
# * )# main
* ) )# 1g ) ,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
G C
1+C B0C 3 ) # g
3
# s
) r
7 #5 ) ) g# 0 ) 7# * B0C (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 # )#* # ) +32- ~-#+ ) #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
B0C 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)  D{( -& A 1)
&
)-r )
, +
#3 +
= 0) -r D{ & D{
=
. ~-#+ C# +
#5 1 +( = -) = & #5 D{
: Switch statement 1
{ 0
{ ) , )#F 20 { -
1t if 1 4 + D3 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 =
(-+ r3
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 :
t3~ -#+ 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
15 :
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)
for(int i=0;i<=10;i++)
: 1r F 20 #5
C #r 0{0
:
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)
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*
2t = 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 23 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
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;
}
# ~-#+ - D0* B0C rr -r 0{ 1
1*g = (0C = 2
. 1*
#W ~ rr C =~ -#+ - -r C D0* 9- = , #2E
5 B0C #{
(- , *: #{ 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* ,~ #+
1232*+
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:
B3 -+ , 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 D3 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;
}
s
*
acos(x)
g*
asin(x)
1E*
atan(x)
ceil(x)
cos(x)
e x )
exp(x)
0
fabs(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)
}
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
{
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 B3 & .... , 2 , 1 , 0 2#
. ) #* & { , 0
. *+
F
)
#s* ) #s* n C B0C
{
ar =
)
5
n #s* C , ar[n-1] , ....... , ar[2] , ar[1] , ar[0]
:
+) #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 #
# B0C # 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 tb B
t () =
# b
9t
temp t a B:
;temp=b
;b=a
;a=temp
) for 0F& =
B+ temp 1 #+*) arr[j] # -A
= t* # tempC t { F =
BF k #0 0
* , # C# { =
0+ t , D32- { 0
2 r #
C B0C
{
s 1 s #r* + :
)
. g
. C& C *
C
) #sC C
: 15
)
? #*
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 1sF 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 & 02
1G3 {#
2-. '\0' 0303
I t cin:
;cin>>s
I 2 63
# #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 .