Professional Documents
Culture Documents
Nader-C
Nader-C
)(c++
: c++
.1 c++ .
c++ .2 .
c++ .3 )
.
.4 c++
.
c++ .5 ) : c++
(.
c++ .6 ). (.
c++ .7 ) ). (object oriented
.
c++ .8 .
.9 c++ .
.10 c++ :
.1 ; .
.2 255 .
.3 .
.4 ). ( .
.5 */ * / // :
*/ */
//
2
PDF created with pdfFactory Pro trial version www.pdffactory.com
: c++
:
) int signed ( ) unsigned ( .
signed int int .
:
.
:
A - Z a - z 9 -0 ) (underline) (-
.
:
4)a-65
2) sal . 2
3)ilam
1) ali2
3 .
;
:
; Int x,y
; Char ch
: 3 :
.1 :
;Int x,y=5
;'Char ch='a
;Int x,y,z,m
.2 :
;Char ch
.3 .
;X=5
;Y=z=10
;M=9
;'Ch='k
: .
:
.1 ) #define # ( number
.2
:
const
#define
#dene p 3.14
:1 #define ; .
: 2 # define .
:1 ).
(.
: :
; =
const
A + 5
:
.1
.2 ) (
.3
.4
:
5
PDF created with pdfFactory Pro trial version www.pdffactory.com
: Y=X++ X Y X .
Y=++X X X Y .
:
& :
& * :
& *
. :
X=10
; ) P =&X X P (
X
5 P ; *P=5
;*M=*P
(Question) :
: 3 2 ) = (1
;X=7
; J = (x >5) ? x *2 : x*5
: 1 2
1 3
.
:
;1) Int x,y
;X=10
;J=(x=3)?x*2 :x/2
--------------------------------;2) int x,j
;X=10
;J=(x==3)?x*2:x/2
----------------------------------
)( : . .
; ) , 2 =( 1
1 2 1 2
2 .
; Int x,y
;)J=(x=4 , x*4/2
:sizeof .
:
;Int x,y
;X= sizeof y
;)Y=sizeof (float
:
; sizeof
; ) ( sizeof
.
:
.1 ) (
.2 ! sizeof -- ++
.3 * % /
.4 +
.5 < = < > = >
.6 == =!
.7 &
.8 &&
.9 | |
.10
:
.
: ). (.
:
8
PDF created with pdfFactory Pro trial version www.pdffactory.com
;X=2 ; y=4
Z=k++x l+ y m+ sizeof (float)j = 12
Z=x++ + y = 6
: c++
>#include< heder file
)(Int main
{
;
; Return 0
}
:
.1 header #include
.2 ) begin {(
. c++ .
.3 #include header
main . : ; .
.4 # include > <
.
.5
return 0 .
:cout
iostream.h
.
; << . ...... <<2 cout<< 1
1 2 ...
" " (w cotation) .
.
.
\ . :
: \n .
:\t 8 .
:\a .
:\v 8 .
?\ : .
:\: : .
:
;X=5
;Y=7
;Cout<<"x="<< x<<"y="<<y
:
X=5 y=7
(2
;Int x=5 ; j=7
;Cout<<"x="<<x
10
;Cout<<"="<<j
:
j= 7
X=5
(3
;x=5 ; j=7
;'cout<<"x="<< x<<'\n
;cout<<"j="<<j
:
X =5
J=7
(4
;x=5 ; j=7
;cout<<"sum=" <<x +j
:
Sum=12
(5
;x=5 ; j=7
;cout<<"x="<<x<<endl
;cout<<"j="<<j
:cin
. iostream.h .
:
11
; cin>>x >> j
: cin
enter .
: ) (
.
#dene pi 3.14
>#include<iostream.h
)(Int main
{
;Int r
;Float p,s
;Cin>>r
;P=2*pi*r
;S=pi*r*r
;'Cout<<"mohit="<<p<<'\n
;Cout<<"masahat="<<s
;Return 0
}
: .
>#include<iostream.h
)( Int main
{
;Int x,j,p,s
;Cin >>x>>j
;)P=2*(x+j
;S=x*j
12
;'Cout<<"mohit="<<p<<'\n
;Cout<<"masahat="<<s
;Return 0
.
}
: 3 .
>#include<iostream.h
)( Int main
{
;Int a,b,c
;Float avg
;Cin>>a>>b>>c
;Avg=(float)(a+b+c)/3
;Cout<<"miangin="<<avg
;Return 0
}
: a,b,c
)(float .
type costing .
: )( clrscr )(conio.h .
: .
>#include<iostream.h
>#include<conio.h
>#include<stdlib.h
13
)( Int main
{
Char c1,c2 ;
Clrscr();
Cin>>c1;
C2=toupper(c1)
Cout<<c2;
Return 0;
}
. :
. tolower toupper :
. 3 :
a+b+c =
( )( )( )
#include<iostream.h>
#include<math.h>
Int main ()
{
Int a,b,c,p;
Float s,h;
Cin>>a>>b>>c;
P=a+b+c;
h=(oat)(p/2);
s=sqrt(h(h-a)(h-b)(h-c));
cout<<"mohit="<<p<<endl;
14
stdlib.h toupper 1
cout<<"masahat="<<s;
return 0;
}
. :
. stdlib.h toascii()
#include<iostream.h>
#include<stdlib.h>
Int main ()
{
Int f;
Char c;
Cin>>c ;
F=toascii(c);
Cout<<f;
Return 0
}
. :
#include<iostream.h>
Int main ()
{
Int a,b,max;
Cin >>a>>b;
Max=(a>b) ? a: b;
Cout<<"maximum="<<max;
Return 0;
}
15
PDF created with pdfFactory Pro trial version www.pdffactory.com
>#include<iostream.h
)( Int main
{
;Int a,b,min
;Cin >>a>>b
;min=(a>b) ? a: b
;Cout<<"minimum="<<min
;Return 0
}
:
.
>#include<iostream.h
)( Int main
{
;Float b,p,f
;Cin >>b>>p
;)F=b*(p/100
;Cout<<f
;Return 0
}
:
)( .
= %7 = %10
#dene m 10/100
16
#dene b 7/100
#include<iostream.h>
Int main ()
{
Float HN ,H;
Cin>> HN;
H=HN-m-b;
Cout<<H;
RETURN 0;
}
. N :
#include<iostream.h>
Int main ()
{
Int m,d,f,n;
Cin>> n;
If (n>186){
F=n-186;
M=7+f/30 ;
D=f% 30;
Cout<<"month="<<m<<"day="<<d;
} else {
M=n/31 +1 ;
D= n%31;
Cout<<"month="<<m<<"day="<<d;
}
17
Return 0;
}
.
: for
. .
) ; ; (= for
);(
)( {} .
.
:1 for for ( ; ;) :
:2 for.
;i=1
{);For(;i<=10
;Sum=sum+i or sum =sum+i++
; i++
}
18
PDF created with pdfFactory Pro trial version www.pdffactory.com
: 10 1
For(i=1 ; i<=10 ; i++)
Sum=sum+I;
. 100 1 :
#include<iostream.h>
Int main ()
{
Int n,sum,i;
Cin>>n;
For(i=1;i<=100;i++)
Sum+=i;
Cout<<sum;
Return 0;
}
. n 1 n :
#include<iostream.h>
Int main ()
{
Int n,sum,i;
Cin>>n;
For(i=1;i<n;i++)
Sum+=i;
Cout<<sum;
19
Return 0;
}
. n :
#include<iostream.h>
Int main ()
{
Int n,sum,i;
Cin>>n;
For(i=1;i<=n;i++)
{cin>>n;
Sum+=n*n;
}
Cout<<sum;
Return 0;
}
. 10 :
#include<iostream.h>
Int main ()
{
Int n,sum,i;
Float avg;
For(i=1;i<=10;i++)
{cin>>n;
Sum+=n;
}
Avg=(float)sum/10;
20
Cout<<avg;
Return 0;
}
n :
.
#include<iostream.h>
Int main ()
{
Int i,n,f;
Cin>>n;
F=1;
For(i=1 ; i<=n ; i++)
F*=i;
Cout<<f;
Return 0;
}
. 120 20 :
#include<iostream.h>
Int main ()
{
Int sum,i;
For(i=20;i<=120;){
Sum=sum+i;
i=i+2;
}
21
PDF created with pdfFactory Pro trial version www.pdffactory.com
Cout<<sum;
Return 0;
}
. h a :
#include<iostream.h>
#include<stdlib.h>
Int main ()
{
Char ch;
Int code ;
For(ch='a' ;ch<='h';ch++){
2
Code=ch;
Cout<<ch<<"="<<code; or <<"\n";
Cout<<endl;
}
Return 0;
}
. n :
1+
#include<iostream.h>
Int main ()
{int n;
Float sum;
22
PDF created with pdfFactory Pro trial version www.pdffactory.com
. code ch 2
1
+
2
)For(i=1; i<=n;i++
;Sum=sum+ 1/i
;Cout<<sum
Return 0
}
: 2 4 0.5 .
>#include<iostream.h
)( Int main
{
;Float f
);For(i=2;i<4
;{f=i+ 0.5
;Cout<<f
}
;Return 0
}
for :
.
: 10*10 .
>#include<iostream.h
)( Int main
;{int i,j
{)For(i=1;i<=10;i++
)For(j=1;j<=10;j++
23
PDF created with pdfFactory Pro trial version www.pdffactory.com
;"Cout<<i*j<<"\t
;"Cout<<"\n
}
;Return 0
}
) while ( :
:
)
( while
;
{ } .
: .
: while while(1) .
: 5 .
>#include<iostream.h
)( Int main
;{int i=1 , sum=0, x
{)While(i<=5
;Cin>>x
;Sum=sum+x*x
};i++
;cout<< sum
;return 0
}
3
4
8 .
) ( .
24
:do..while
:
{do
;
{ } .
; )(while
: .
while : dowhile
.
: .
>#include<iostream.h
)( Int main
{
;Int n,m
;Cin>> n
{)while(n>=0
;m=n%10
;cout<<m
};n=n/10
;return 0
}
25
PDF created with pdfFactory Pro trial version www.pdffactory.com
: if
)
( if
;
{ } .
Else
;
{ } .
: n n
) (.
>#include<iostream.h
)( Int main
;{int b,n,x,i,j
;Cin>>n
{)For (i=1;i<=n;i++
;Cin>>x
;X=x%2
)If(x=0
;b=b+1
else
};j=j+1
;cout<<"zoje="<<b
;cout<<"fard="<<j
;return 0
26
: n .
>#include<iostream.h
)( Int main
;{ int n,r,i
;Cin >>n
{)For(i=1; i<=n/2;i++
;r=n%i
)if(r=0
;cout<<I
}
};Return 0
: n .
>#include<iostream.h
)( Int main
;{ int n,r,i,p
;Cin >>n
;P=1
{)For(i=1; i<=n/2;i++
;r=n%i
)if(r=0
;p=p*i
}
;cout<<p
};Return 0
: n .
>#include<iostream.h
27
Int main ()
{ int n,r,i,j;
Cin >>n;
For(i=1; i<=n/2;i++){
r=n%i;
if(r=0)
j=j+1;
}
cout<<j;
Return 0;}
. n :
#include<iostream.h>
Int main ()
{ int n,r,i,j;
Cin >>n;
For(i=1; i<=n/2;i++){
r=n%i;
if(r=0){
if(i%2=0)
j=j+1;
}
}
cout<<j;
Return 0;
}
. n :
#include<iostream.h>
28
Int main ()
{ int n,r,,I,sum;
Cin >>n;
For(i=1; i<=n/2;i++){
r=n%i;
if(r=0)
sum=sum+i;
}
cout<<sum;
Return 0;}
. :
#include<iostream.h>
Int main ()
{ int n,f,i,j;
Cin >>n;
For(i=1; i<=n;i++){
f=n%i;
if(f=0)
j=j+1;
else
continue;
}
If(j=2)
Cout<<"number is aval";
Else
Cout<<"number is not aval";
Return 0;}
29
PDF created with pdfFactory Pro trial version www.pdffactory.com
: ):
.
#include<iostream.h>
Int main ()
{ int n,r,i=1,sum=0,h;
Cin >>n;
For(i=1; i<=n/2;i++){
r=n%i;
if(r=0)
sum=sum+i;
else
continue;
}
If(sum=n)
Cout<<"is taam";
Else
Cout<<"is not taam";
}
Return 0;
}
. ( n) n :
*
* *
* *
* *
* *
* * *
#include<iostream.h>
Int main ()
{int i,j;
30
Cin>>n;
For(i=1;i=<=n;i++){
For(j=1;j=<=i ; j++)
Cout<<"*";
Cout<<"\n";
}
Return 0;
}
1
1
1 2
1 2 3
#include<iostream.h>
Int main ()
{int i,j;
Cin>>n;
For(i=1;i=<=n;i++){
For(j=1;j=<=i ; j++)
Cout<<"j";
Cout<<"\n";
}
Return 0;
}
1
2
3 3
4 4 4
#include<iostream.h>
Int main ()
{int i,j;
31
Cin>>n;
{)For(i=1;i=<=n;i++
)For(j=1;j=<=i ; j++
;"Cout<<"i
;"Cout<<"\n
}
;Return 0
}
: break
.
:continue
.
:switch
.
:
{)(switch
: case1
;
;
{ } .
;Break
: case2
32
PDF created with pdfFactory Pro trial version www.pdffactory.com
;
;Break
...........
Defult:
}
:switch
switch
break switch
defult .
:1 switch defult .
switch .
:2 case .
:3 switch .
:4 case break case or .
:5 switch . case
switch .
: if switch
.
: .
{)Switch(ch
Case ' R':
; "Case 'r': cout<<"red
;Break
33
Case'G':
: 4
.
>#include<iostream.h
)( Int main
; {Int x
;Cin>>x
{)Switch(x
;"Case 1..9 : cout<<"1 ragham
;Break
;"Case 10..99: cout<<"2 ragham
;Break
;"Case 100..999: cout<<"3 ragham
;Break
;"Case 1000..9999: cout<<"4 ragham
;Break
;"Defult: cout<<"bish az 4 ragham
}
;Return 0
}
:
.
34
.
c++ sin() :
)( cos .
:
) (
{
:1 .
:2 ) (
.
: 3 main .
.
;) (
>#include<iostream.h
;)Void sample (int x, int y5
)(Int main
{
;Int a,b
.
Sample(a,b);7
..
;Return 0
}
5
6
7 ) (a,b .
35
PDF created with pdfFactory Pro trial version www.pdffactory.com
:1 main .
:2 .
:3 .
:4 .
:5 .
:6 . .
: sample .
Void sample(int,int)8
:7 void .
c++ 3 :
.1 )(void
.2 .
.3 ) . (.
: 3
.
>#include<iostream.h
;)Void maximum (int, int,int
)(Int main
;{int a,b,c
;Cin>>a>>b>>c
8 ; .
36
PDF created with pdfFactory Pro trial version www.pdffactory.com
Maximum(a,b,c);
Return 0;
}
Void maximum (int x, int y,int z)
{int max;
Max=(x>y) ? x:y;
Max=(max>z) ? max:z;
Cout<<max;
Return 0;
}
. :
#include<iostream.h>
Int maximum (int, int,int);
Int main()
{int a,b,c;
Cin>>a>>b>>c;
Cout<<Maximum(a,b,c);
Return 0;
}
Int maximum (int x, int y,int z)
{int max;
Max=(x>y) ? x:y;
Max=(max>z) ? max:z;
Return max ; or return(max)
}
37
#dene h 3.14
#include<iostream.h>
Int s (int);
Int main()
{int r;
Cin>>r;
Cout<<s(r);
Return 0;
}
Int s (int d)
{ int f;
F=h*d*d;
Return f;;
}
:
.
#include<iostream.h>
Int factorial (int);
Int main()
{int n;
Cin>>n;
Cout<<factorial(n);
Return 0;
}
Int factorial (int)
{ int fact , i;
Fact=1;
For(i=2; i<=n;i++)
Fact*=I; or fact=fact*I;
Return fact ;
38
:
.1 )(local
.2 )(global
: 1 .
: main .
:2 main .
: .
:
.
:
) void(.
>#include<iostream.h
;)Void aval (int
)(Int main
;{int n
;Cin>>n
)Void aval (int x
;{ int i,j,r
{)For(i=1;i<=x;i++
;R=x%i
)If(r=0
;j=j+1
10
else
; continue
9 .
10 cout<<j; :
39
}
If(j==2)
Cout<<"adad aval";
Else
Cout<<" aval nist !;
Return 0;
}
. .. m,n 2 :
#include<iostream.h>
Int fbmm (int,int);
Int main()
{int m,n;
Cin>>m>>n;
Cout<<"\n B.M.M ="<<fbmm(m,n);
Return 0;
}
Int fbmm(int a,intb)
{int r;
Do{
r=a%b;
a=b;
b=r;
}
While(r!=0);
Return (a);
}
m n . ( m>n) m,n 2 :
.
40
#include<iostream.h>
a,b 2 :
.
#include<iostream.h>
Int sum (int,int);
Int main()
{int a,b,f;
Cin>>a>>b;
F=sum(a,b);
Cout<<f;
Return 0;
}
41
){ if(y==1
;Return x
Else
;)Return x+sum(x,y-1
}
: a,b a/b
) ( .
>#include<iostream.h
;)Void tafrigh(int,int
)(Int main
;{int m, n
;Cin>>n
;)Tafrigh(m,n
;Return 0
}
)void tafrigh ( int x, int y
{
)For(i=1 ; a>=b; i++
;a=a-b
;cout<<I
;Return 0
}
:
.
.1 : .
.2 2 : .
42
PDF created with pdfFactory Pro trial version www.pdffactory.com
!4! =4*3
!3!=3*2
!2!=2*1
1!=1
2=2*1
6=3*2
24=6*4
) ( if
;
Else
;
: n=1
: n>1
n!= 1
!)n!=n*(n-1
n=1.
4 3 3 2
2 1 1 1
.
2 :
:
)Fact(int n
;{int f=1,i
)For(i=2;i<=n;i++
;F=f*I
;)Return(f
43
: n
.
>#include<iostream.h
;)Int fact(int
)(Int main
{
;Int n
;Cin>>n
;)Cout<<fact(n
;Return 0
}
)In t fact (int b
{
)If(b==1
;)Return (1
Else
;))Return(b*fact(b-1
}
44
: a,b a b .
>#include<iostream.h
;)Int sum (int,int
)(Int main
;{int a,b,f
;Cin>>a>>b
;)F=sum(a,b
;Cout<<f
;Return 0
}
)Int sum ( int x, int y
){ if(y==1
;Return x
Else
;)Return x+sum(x,y-1
}
:
)Zarb(2,3
))Return(2+zarb(2,3-1
))Return(2+zarb(2,2-1
)Return(2
: 3 n
.
.
: n=1,2
:n>2
1,1,2,3,5,8,13,..
b(n)=1
)fib(n)=fib(n-1)+b(n-2
45
PDF created with pdfFactory Pro trial version www.pdffactory.com
:1 main.
:2 .
: 3 .
) #include<iostream.h> (3
;)Int fib(int
)(Int main
{
;Int n
;Cin>>n
;)Cout<<fib(n
;Return 0
}
)Int fib (int a
;{ int h
)If(a=1
;)Return(1
Else
;))Return(fib(a-1+b(a-2
}
: :
.1 .
.2 .
.
46
c++
)(external
)(static
)(auto
)(register
;
:
; static int x
;j
char
Register
: auto
auto
. auto
.
float m; :
Auto
auto
. :
.1 : .
.2 : ) (
.
:
47
PDF created with pdfFactory Pro trial version www.pdffactory.com
) (cpu
.
:
.1 .
.2 .
.3
.
.4 .
:
.1 : .
.2 : .
: .
: .
>#include<iostream.h
;)Void test(void
)(Int main
{
;Register int i
)For(i=0; i<5 ; i++
)(Test
;Return 0
}
;)Void test(void
;Int x=0
;Sts c int y=0
'Cout<<" \n auto x="<< x<< "static y="<<y
;X++
48
;Y++
}
: test 5 x,y
x y
1 y
x y )
1 ( x y 1 x,y
x y 2 .
y=0
sta c
x =0
Auto
y=1
sta c
x =0
Auto
y=2
sta c
x =0
Auto
y=3
sta c
x =0
Auto
y=4
sta c
x =0
Auto
x . x=1 1 .
:
>#include<iostream.h
;)Void f1(void
;)Void f2(void
)( Int main
{
;)(F1
..
;)(F2
;Return 0
;} static int x,y
;)Void f1(void
{
49
..
}
;)Void f2(void
{
:
) ( .
:
.1 .
.2 .
:
main
)( .
: in line inline
.
:
. 20 20
) (
: inline 2
.
>#include<iostream.h
)Inline int maximum (int a,int b
; { int max
))Max=(a >b) ? a: b; or return((a>b)?a:b
; Return max
50
}
)(Int main
{
; Int x,y
;Cin>>x>>y
;)Cout<<maximum(x,y
;Return 0
}
: c++
.
)Int fact (int
)Int fact (int,int
)Int fact (float
:
.
.
: .
.
:
* =
] ; : [
; ]a [611
Int
. c++ A[0] .
11
6 5
51
PDF created with pdfFactory Pro trial version www.pdffactory.com
10 :
.
#include<iostream.h>
Int main()
{ int a[10] , sum=0,i;
For(i=0;i<10;i++)
A[i]=i;
For (i=0;i<10;i++)
Sum=sum+a[i]*a[i];
Cout<<" majmo morabat="<<sum;
Return 0;
}
( 200 )n :
.
#include<iostream.h>
Int main()
{ int a[200] ,n, sum=0,i;
Float ave;
Cin >>n;
For(i=0;i<n;i++)
Cin>>a[i];
For (i=0;i<n;i++)
Sum=sum+a[i];
Ave=(float)(sum/n);
Cout<<" sum="<<sum;
Cout<<"average"<<ave;
Return 0;
}
52
PDF created with pdfFactory Pro trial version www.pdffactory.com
: 5
) ( .
>#include<iostream.h
)(Int main
;{ int a[5] , i
)For(i=0;i<5;i++
;]Cin>>a[i
)For (i=4;i<0;i--
;]Cin>>a[i
;]Cout<<a[i
;Return 0
}
: 5
) ( .
>#include<iostream.h
)(Int main
;{ int a[5],b[5] , i
)For(i=0;i<5;i++
;]Cin>>a[i
)For (i=4;i<0;i--
;]B[4-i]=a[i
)For(i=0;i<n;i++
;]Cout<<b[i
;Return 0
}
: 5
.
53
>#include<iostream.h
Int main()
{ int a[5],max, i;
For(i=0;i<5;i++)
Cin>>a[i];
Max=a[0];
For (i=1;i<4;i++)
If(a[i]>max)
Max=a[i]
Cout<<"maximum=" <<max;
Return 0;
}
) max, min :
.
#include<iostream.h>
Int main()
{ int a[100],max,min, i;
Min=max=a[0]12;
For(13i=1 ; i<100 ; i++){
Max=(a[i]>max) ? a[i] = max;
min=(a[i]< min) ? a[i] = min;
} cout<<"minimum="<<"\n";
Cout<<"maximum="<<max;
Return 0;
}
100 :
.
#include<iostream.h>
Int main()
54
. i=1 a [ ] a[0] 12
. 13
;{ int a[100],max, i
)For(i=0 ; i<100 ; i++
;]Cin>> a[i
;]max=a[0
)For(i=1 ; i<100 ; i++
;Max=(a[i]>max) ? a[i] = max
;Cout<<"maximum="<<max
;Return 0
}
) ( )(bubble sort
.
) (.
9 3 1
.I
.II
.III
4 3 1 9
3 1 4 9
1 3 4 9
{ )]If (a[j] >a[j+1
;]Temp = a[j
;]A[j]= a[j+1
; A[j+1]= temp
}
= n-1
= n-i
: .
>#include<iostream.h
55
)(Int main
;{ int temp ,j,i
For (i=0; i<=100-1; i++)14
For (j=0; j<=100-i ;j++)15
{ )]If (a[j] >a[j+1
;]Temp = a[j
;]A[j]= a[j+1
; A[j+1]= temp
}
)For (i=0; i<100; i++
;]Cout<< a[i
;Return 0
}
:
:
.I
.II
:1
.
: 100 )
( .
>#include<iostream.h
)(Int main
;{ int a[100],k,j=0 , i
)For(i=0 ; i<100 ; i++
14
15
56
PDF created with pdfFactory Pro trial version www.pdffactory.com
Cin>> a[i];
Cin>> k;
For(i=1 ; i<100 ; i++)
If (a[i]==k){16
J++;
Break;
}
If(j==1)
Cout << " number was found";
Else
Cout << " number was not found";
Return 0;
}
:
.
#include<iostream.h>
Int main()
{ int a[100],k,n, i;
Cin>> n;
For(i=0 ; i<100 ; i++)
Cin>> a[i];
Cin>> k;
For(i=1 ; i<n ; i++)
If (a[i]==k){
S=i
Cout<< s;
Return 0;
}
57
PDF created with pdfFactory Pro trial version www.pdffactory.com
:
.
>#include<iostream.h
)(Int main
;{ int a[100],k,n,j, i
;Cin>> n
)For(i=0 ; i<100 ; i++
;]Cin>> a[i
;Cin>> k
)For(i=1 ; i<n ; i++
{)If (a[i]==k
;F=j++
;Cout<< f
;Return 0
}
)(:
.
.
.
)H(
)M(
) L(
:
L=0 ;17
17
58
PDF created with pdfFactory Pro trial version www.pdffactory.com
H= n-1;18
M=(L -h)/2;19
)If (a[m]< k20
;L=m+1
)If (a[m]> k
;H=m-1
)If(a[m]==k
;
: n ) n ( 100 n
) (
.
>#include<iostream.h
)(Int main
; { int a[100],k,n,j=0, i,h,L=0 , m
;Cin>> n
;H=n-1
)For(i=0 ; i<100 ; i++
;]Cin>> a[i
;Cin>> k
While (L<=h){21
;M=(L+h)/2
{)If(a[m]==k
;J++
;Break
}
18
19
20
21
)(k
59
PDF created with pdfFactory Pro trial version www.pdffactory.com
Else If (a[m]< k)
H=m+1;
Else
H=m-1;
}
If(j==1)
Cout << " number was found";
Else
Cout << " number was not found";
Return 0;
}
:
:
[1 [ ] 2 ] ........
. 10*10 :
#include<iostream.h>
Int main()
{ int x[10][10],j, i, ;
60
}
: 3*3 )tras
( .
>#include<iostream.h
)(Int main
; { int x[3][3],j, i,sum=0
)For(i=0 ; i< 3; i++
)For (j=0 ; j<3; j++
;]Cin>>x[i][j
)For(i=0 ; i< 3; i++
)For (j=0 ; j<3; j++
)If (i==j
;]Sum=sum+x[i][j
;Cout<<sum
;Return 0
}
: 2 ) A(m*n ) B(m*n
)m,n
( 3
22 for .
23
24 .
61
PDF created with pdfFactory Pro trial version www.pdffactory.com
#include<iostream.h>
Int main()
{ int x[3][3],b[3][3],c[3][3],j, i,n,m ;
Cin>>m>>n;
For(i=0 ; i< m; i++)
For (j=0 ; j<n; j++)
Cin>>a[i][j];
-----------For(i=0 ; i< 3; i++)
For (j=0 ; j<3; j++)
Cin>>b[i][j];
..............
For(i=0 ; i< 3; i++)
For (j=0 ; j<3; j++)
C[i][j]=a[i][j]+ b[i][j];
For(i=0 ; i< 3; i++){
For (j=0 ; j<3; j++)
Cout<<c[i][j];
Cout<<"\n";
}
Return;
}
A(m*p),B(p*n) 2 :
.
C(m*n)= A(m*p) * B(p*n)
[ ][ ] =
62
PDF created with pdfFactory Pro trial version www.pdffactory.com
: n ) n (200 n
.
= :
: :
>#include<iostream.h
)(Int main
;{ int a[200] , n, i
;Cin>> n
)For (i=0 ; i<n; i++
;]Cin >>a[i
{)If(n%2==0
;F=n/2
;Cout<<(a[f] + a[f+1]) /2
25
}
{ Else
; f=n/2 +1
;]Cout<<a[f
or
;F=(n-1)/2
;]Cout<<a[f+1
}
;Return 0
}
: 100
.
25 2 .
63
#include<iostream.h>
Int main()
{ int x[200],y[100] ,n, j,h,sum=0,i;
Float ave;
For(i=0;i<100;i++)
Cin>>x[i];
For (i=0,h=0;i<100;i++)
If(x[i]%2=0){
Y[h]=x[i];
H=j++;
}
For(j=0;j <h; j ++)
Sum=sum+y[j];
Ave=(float)(sum/n);
Cout<<" sum="<<sum;
Cout<<"average"<<ave;
Return 0;
}
. :
#include<iostream.h>
Int main()
{ int a[100] ,n, sum=0,i;
Float ave;
For(i=0;i<100;i++)
Cin>>a[i];
For (i=0;i<100;i++)
Sum=sum+a[i];
Ave=(oat)(sum/100);
64
;Cout<<" sum="<<sum
;Cout<<"average"<<ave
;Return 0
}
:
main ) (
) ( .
.
:
; } { = ][ ]] [1 [2
:
Int p[]= { 1,3,5,9]26
Int x[10] ={5,12}27
26 .
27
. error .
65
s 9
' '\0 :
]Char s[10
.
:
Char s[ ] = "computer" ; 9 .1
Char st[ 12]=" algorithm" .2
Char str[]={ 'p','r','9', '10'} 4 .3
;) (cin. get
.II
;) ( cin.get
.III
) (Cin.get
: 1
('\n') . .
28
ch .
66
PDF created with pdfFactory Pro trial version www.pdffactory.com
2 .
;]Char s[20
;)Cin.get(s , 15
;)'Cin.get(s , 15, '.
: s 20 .
: 15 s enter
.
: 15
15
.
get : cin
get enter )
( ) (space tab )8
( cin ) (space tab
.
:
;]Char s[50
;)Cin.get(s , 30
;Cin>> s
67
: upper
32 32
. ' '0 ' '9 48 .
c++ s="ali" :
c++ s [ ] = "ali" :
: 2 2
). 1 ( ( .(
.
29
] [ . ] [ .
30 ' '\0
31 .
32
for .
68
:
: strcmp strcmp( s1 , s2); . s1 , s2
.
.I
: S1=s2 .
.II
:S1>s2 ) ( .
.III
: S1<s2 .
.
d>b Alid > ALib :
5>4 324 > 325 :
) (string.h .
:strcat
2 str cat(s1,s2).
s2 s1 . ) (string.h
. .
69
:strcpy
. ) (string.h
s2 s1 :
;)Str cpy(s1 , s2
) ( : str len Str len(s) .
: 5
.
): (pointers
.
: .
.
.
.
:
70
PDF created with pdfFactory Pro trial version www.pdffactory.com
.1
.2
.3
.4
:
.
:
; *
; Int *p
p : int p
. p .
:
;Int *p1, *p2,v1,v2
;Double *f1 , *f2
;Char * ch
:
& :
.
* : .
;Int *p,m,s
;M=5
P=&m;33
34
S=*p
33 m p .
71
PDF created with pdfFactory Pro trial version www.pdffactory.com
50
P1
100
P2
;Int *p1,*p2,x,y
;X=50
;Y=100
;P1=&x
100
;P2=&y
P1
;*p1= *p2
100
P2
*p1=*p2 p1=p2 .
p1 p2 y .
50
P1
y
100
P2
34 p s .
72
p1=p2 p1 p2 .
: . : p
int 1000 p++ p
1002 .
1000+ 2byte = 1002
p char p++ 1000 + 1 byte = 1001 :
: *p++ p .
:
.
:
.
.
;Int x,y.*p1,*p2
;P1=&x
;P2=&y
)If(p1==p2
p1 1000 p2 1200 .
.
.
73
: .
; > < = new .
; delete
) malloc ( memory allocation malloc.h
.
:
;)36) malloc (size35 *( =
)(x = malloc
.
: malloc
) (null .
: .
:
; Int *p
;))P=( int * ) malloc (size of (int
: ) size of (int p
) ( )( free
:
; ) ( free
: new , delete
35
) ( .
36
.
74
PDF created with pdfFactory Pro trial version www.pdffactory.com
:
. = new <; >
delete[] ;
Int *x;
X= new int
Or
75
PDF created with pdfFactory Pro trial version www.pdffactory.com