You are on page 1of 68

c++

Hussein abed hilal // BSC graduated from al-imam alsadiq university // higher diploma // website ///student in
master first class //MSC// university of technology

) (

c++

()c++

( )c++

,

,
( ) math
( )sin ,cos ..ets
,
iostream
(
),math .
( )c++

,
.
( )c++ ( > )#include <iostream.h
( )c++ .
)#include <iostream.h> (
/
,
)c++
, (
2

( )

c++

,
( )iostream.h
) input output stream .h (
,
////// ( )c++
.
> ) #include <iostream.h
(
.

> # include <iostream.h


main

.

)( Main
{

) begin (

end of (
)program

( , )c++

( )

c++

(-: )c++

-: ( -: )cout

-:

; Cout << the value what you need print it


-:
( ) hello world
Ex(1):> #include <iostream.h
)( Main
{
; "Cout <<" hello world
}

( ) hello world
4

( )

c++
Ex (2) :> #include <iostream.h
)( Main
{
; "Cout <<" the world is beautiful
}

( )the world is beautiful


-: ( " " )
.
Ex (3):> #include <iostream.h
)( Main
{
Cout << " im c++ language , the world is beautiful ,
; "im play football game
}
-:
I m c + + l a n g u a g e , t h e w o r l d i s b e a u t i f u l , i m p l ay
f o o tb a l l g a m e

,
5

( )

c++

.
( -: )\n
) end line ( ,
- 1 ) \n (
- 2 )endl (

\n

Ex( 4):> #include <iostream.h


)( Main
{
;" Cout <<" hello \n
;" Cout <<" hussein
}


Hello
hussein
\n
Hello hussein

( )

c++
Ex (5 ):> #include <iostream .h
)( Main
{
; Cout << " hello "<< endl
;" Cout <<" world
}

Hello
world
( ) \n
-:
Hello world

,
.
7

( )

c++
Ex( 5):> #include <iostream .h
)( Main
{
} ; Cout << hi every one
c++

,
.


Ex(6):> #include <iostream .h
)( Main
{
;Cout << 150 + 100
}

250
,

, c++
8

( )

c++

.
-:
c++

( , ) integer
)float (
.
,
; Int x,y,zets

//// ( , ) main
( ) main
Ex(7):
? Z=x+y if x=100 ,y=150

( )

c++


\\ Sol
>#include <iostream .h
)( Main
{
; Int x=100,y=150,z
; Cout <<z=x+y
}


250

;Int x=100 ; int y=150 ; int z


> #include <iostream.h
)( Main
{
; Int x=100 ;int y=150 ; int z
;Z= x+y
;Cout << z
}
10

( )

c++

250
50
,

Z=250

;Cout << "z= " << z

, ) ) z
,
Ex(8):
********
** hussin
********

Sol //
> #include <iostream .h
)( Main
{
;Cout << " ********"<<endl
; Cout << " * hussein *"<< endl
; Cout << " ********"<< endl
11

( )

c++
}

*******
**Hussein
*******

) -- ( .1 .
) ++ ( .2 .
) > ( .3 .
)< ( .4 .
) >= ( .5 .
)< = ( .6 .

Ex(9): ) )m m=10
)) 10
Sol //
> # include <iostream .h
)( Main
{
; Int m = 10
; Cout << " m = " << m << endl
;Cout << " m = " << m + 10 << endl
; Cout << " m = " << m + 20 << endl
12

( )

c++
Cout << " m = " << m + 30 << endl
}

) m ( ,
10 , 20 10
, 30 10
40

10
M= 10
M= 20
M= 30
M= 40
Ex(10 ) :> #include <iostream .h
)( Main
{
; Cout << " hello " << endl
" << Cout
; "<<" hussein "<< endl
" << Cout
;"" << " your love football team germany

}

c++

.
13

( )

c++
Hello
Hussein
Your love football team germany


.
( -: ) cin c++


; Cin >> what you need input
Ex ( 11 ) :
Sol //
> # include <iostream .h
)( Main
{

int
;Int x,y,z,d,a,Q
;Cout << " enter five number "<<endl
;Cin >> x>> y>> z>>d>>a

;Q= x+y+z+d+a
; Cout << " Q=" << Q
}

Enter five number
,

- 10 20 30 40 50
14

( )

c++

Q= 150
// Q int cin
.
Ex ( 12 ) :
,
, .
( ) sum ( . ) avg
Sol //
> # include < iostream .h
)( Main
{
;Int x; int y ; int z; int d; int a
; Int sum = 0 ; int avg

; Cout << " enter five number "<<endl
.
;Cin >>x>>y>>z>>d>>a
;Sum = x+y+z+d+a

; Avg= sum / 5
; Cout << " avg ="<< avg
}

,
.
c++
.
15

( )

c++
1
2
3
4

. . .- .

Ex( 13 ) :
) Z= x+y / ( y* x
c++
,
x . z

Sol //
> # include < iostream .h
)( Main
{
; Int x , y
; Float z
; Cout <<" enter x,y " << endl
; Cin >> x>> y
;)Z= x+y / (y * x
;Cout << " z="<<z
}

Enter x,y

6

Z= 5.2
16

( )

-5

c++
///

.
Z=10

Ex (14): x=10,y=5
Z= x*y + d/c .
Sol //
x ,y , d,c

.
> #include <iostream.h
)( Main
{
;Int x=10 ,y=5,d,c
;Float z
;" Cout << " enter two value
;cin >> d>>c
;Z=x*y+d/c
;Cout <<"z="<<z
}

Enter two value
5,5

.

17

( )

Z= 51

c++

.
/// .

Ex(15 ):
( ).

.
Sol//
>#include <iostream.h
)( Main
{

;Float pi =3.14
.
; Float Area , Rad
; Cout << " enter the value of radius "<<endl
; Cin >> Rad

;Area = pi *Rad*Rad
; Cout << " the area of circle ="<<Area
}

:
Enter the value of radius
= 5
Area = 78.5
18

( )

c++
Ex ( 16 ):
( )32 + 9/5 *
:
Sol ///
> #include <iostream.h
)( Main
{

; Float fah , cel
; Cout << " please enter degree in Celsius "<<endl
; Cin >> cel


.

; Fah = cel * 9/5+32


; Cout <<" the degree in Fahrenheit is "<<fah
}

Please enter degree in Celsius
= 30
Fah = 86

( -: ) if if .

.

19

( )

c++
If ( condition ) statement

.



, if

) ) x is even number

.

Ex ( 17 ) :> # include < iostream .h


)( Main
{
; Int x
; Cout <<" enter x "<<endl
; Cin >> x
) If ( x % 2==0
; " Cout << " x is even number
}


Enter x
-4
X is even number
) (else ...... if -:
,
.
Ex ( 18 ):
> # include <iostream .h
)( Main
20

( )

c++

{
; Int x, y
; Cout << " enter two number "<< endl
; Cin >> x>>y
) If ( x>y
; Cout <<" the max number is "<< x
Else
; Cout <<" the max number is "<< y
}

-:

Enter two number

16 , 20

The max number is 20

,

, .
-: ) (if ,

( } .) {........
Ex (19): , ,
,
Sol ///
> # include < iostream .h
21

( )

c++
)( Main
{
; Int x,y
; Float div
; Cout <<" enter two number "<< endl
; Cin >> x>>y
) If ( x<y
{
; Int temp
Temp
; temp = x

; x= y
.
; y= temp
}
) If ( y != 0
; div = x/y

; Cout << " div = "<< div
.
}
Else
;" Cout << " no result found
}

Enter two number
5,6

Div =1.2
Ex ( 20 ):-


sol ///
> # include <iostream .h
)( Main
{
; Int x , y , z
22

( )

c++
; Cout <<" enter three number "<<endl
;cin >> x>>y>>z
)if ( x>y
; {int max
;Max =x
Else
; Max =y
) If ( z>max
;Max = z
}; Cout <<" the largest number is "<<max

Enter three number
101112
The largest number is 12
if , if
.
-:




.
Ex ( 21 ):
Sol ///
> #include < iostream .h
23

( )

c++
Main ()
{
Int x,x1,x2,x3,x4;
Cout <<" enter five number "<<endl ;
Cin >>x>>x1>>x2>>x3>>x4;
If ( x %2==0 ) {

Int k=0;

K=k+1;
Else
If ( x1%2==0 )
K=k+1;
Else
If ( x2 % 2==0)
K=k+1;
Else
If ( x3%2==0 )
K=k+1;
Else
If ( x4 %2==0 )
K=k+1;}
Cout <<" the number of even number is ="<<k;
}

Enter five number
5,6,4,7,8
.
The number of even number is = 3
Ex ( 22 ) : 24

) (

c++
,

1234 . 4321
Sol ///
> # include <iostream .h
)( Main
{
; Int a,k,b,c,d
;"= Cout <<" enter your number as four digit number
;Cin >> a
;K= a/1000
;A=a%1000
;B=a/100
;C=a%100
;a=c/10
;d=c%10
;" = cout <<"the number is revers order is
;cout << d
;cout << a
;cout <<b
;cout << k
}

Enter your number as four digit = 1997
The number in revers is = 7991

Ex(23):
1
2
3
12345 4 5
Sol///
> #include <iostream .h
)( Main
25

( )

c++
{
long number ;
Cout <<" enter the number have five digite =";
Cin >>number ;
Cout << number/10000<<"\t"; number = number %10000;
Cout <<number/1000<<"\t"; number =number %1000;
Cout <<number /100 <<"\t";number =number %100;
Cout <<number /10<<"\t";number =number %10;
Cout <<number <<"\t";
}

Enter the number have five digite = 12345


1
2
3 4 5
Ex (24 ):
#include <iostream.h >
Main ()
{
Int gread ;
Cout <<" enter your degree "<<endl ;
Cin >>gread ;
If ( gread >= 90 )
Cout <<"A";
Else
If ( gread >=80 )
Cout <<"B";
Else
If ( gread >=70 )
26

) (

c++
else
Cout
<<"C";
If ( gread >=60 )
Cout <<" D";
Else
Cout <<"success \a\a\a"<<endl ;
If ( gread <=49 )
Cout <<" fail ";
}
Enter your degree
90
A

Ex ( 25 ) :

Sol///
#include <iostream .h >
Main ()
{
Int a,b;
Cout <<" enter two number "<<endl ;
Cin >> a>>b;

If ( a%b==0)

Cout <<a<<"is multiply of "<<b<<emdl ;

Else

Cout <<a<<" is not multiply of <<b<<endl ; true
}

.folse
27

) (

c++

Enter two number
6
12
6 is multiply of 12

Ex (26 ):-: z

a-b*b/a

if x>=1

Z=
a*a-b

if x<=-1

sol///
#include <iostream .h >
Main ()
{
Int a,b;Int x;
Float z;
Cout <<" enter the value of a and b "<<endl;
Cout <<"the value of a=";
Cin >>a;
Cout <<" the value of b=";
Cin >>b;
28

) (

c++
;"=Cout <<"enter the value of x
;Cin >>x
{)if ( x>=1
;z=a-b*b/a
}; cout <<" z="<<z<<endl
{) if ( x<=-1
;z=a*a-b
};cout <<"z="<<z<<endl
}

Enter two value of a and b


Enter the value of a=1
Enter the value of b=4
Enter the value of x= 2
Z= -15

-: c++ go to
.
goto
.
: = int
; + loop:

) ex :- ( 27
loop go to
29

( )

c++
Sol ///
# include < iostream .h >
Int main ()
{
loop
Int counter =0 :

Loop :counter ++ ;
Cout << counter = << counter << endl ;

If ( counter <5 )


Go to loop ;
Cout << complete counter <<counter <<endl ;
Return 0;
}

Counter =1
Counter =2
Counter =3
Counter =4
Counter =5
Complete counter =5
Ex (28 ):

Sol///
#include <iostream.h >
Void main ()
Int x,y;
Cout <<enter two number <<endl;
Cin >>x>>y;
30

) (

c++
Cout <<the sum = << x+ y << endl ;
Cout << the difference = <<x-y <<endl ;
Cout << the product = << x*y <<endl;
Cout << the quotient = <<x/y<<endl ;
}

Enter two number
6 5
The sum = 11
The difference = 1
The product = 30
The quotient = 1.2
-: ) while (

1- while ( expression )
statement ;

2-while ( expression )
{
statement 1;
statement 2;
.
.
.
Statement n;
}
31

) (

c++

Cin >> inpt ;


While ( inpt !=*;
Cin >>inpt ;
Cout << thank you ;
) while ( ) 27(

Sol///
# include <iostream .h >
Int main ()
{
Int counter =0;
While ( counter <=0 )
{ counter ++;
Cout << counter = << counter << endl ;
}
Cout << complete counter << counter << endl ;
Return 0 ;
}
Counter =1
Counter =2
Counter =3
Counter =4
Counter = 5
Complete counter =5
32

) (

c++
Ex (29 ) : ( ) 10 1 ( ) while
Sol///
> # include < iostream .h
)( Int main
{
; Int i=0

;Int sum =0

) While ( ++i<=10
.
{

;Sum = sum +I
10 I
}
; Cout << the sum is = << sum << endl
; Return 0
}

The sum is = 55
( -: ) do while
-:
Do
;Statement 1
.
.
;Statement 2
; ) While ( expression
33

( )

c++
Do
; Cin >> num
; Cout << num
;) While ( num != 0

Ex ( 30 ): ( ) 10 -1 ( ) while

> # include < iostream .h


)( Int main
{

; Int x=1

)While ( x<=10
{

;Cout <<x<< <<\n
;++x

}
; Return
}

1 2 3 4 5 6 7 8 9 10
Ex ( 31 ): ( ) 3 10
Sol///

> # include < iostream .h


)( Main
{
; Int i=10
)While ( i>=3
{

34

( )

c++

;Cout <<\n<<I
;--I
}
;Return 0
}

10
9
8
7
6
5
4
3
3 .
Ex (32):

Sol///
> #include <iostream.h
)( Main
{
; Int x;int number ;float avg
;Int sum =0
;number =0
;cout << enter many number <<endl
;cin >>x
)while ( x!=0

35

( )

c++

.

{

;Sum =sum+x
;number =number + 1
;cin >>x
}
;Cout << sum =<<sum <<endl
;Cout <<avg= << sum/number <<\n
};Return 0

Enter many number


2
3
4
5
0

.
-:
Sum = 14
Avg= 3.5
Ex (33):
Sol///
> #include <iostream.h
)( Main
{
;Int x,I,p

36

( )

c++
; Cout << enter the x value <<endl
;Cin >>x

;I=x
.
;P=1
)While (i>=1

{
;p=p*I
;I--
}
;Cout<<x<<!=<<p<<endl
;Return 0
}
.
x 5 x I
I , 5

I .

Enter the x value
5
5!=120
Ex ( 34 ):
Sol///
> #include <iostream.h
)( Main
{
;Int i=1;int j

37

( )

c++
{)While (i<=3
;j=0

)While (j<=5
{
; <<Cout <<j
; << Cout
;++j
}
;++i
}
;Return 0
}
loop I , 1
loop j 0 j 5
j ,
I 1 I , 3 I
2 loop
j ,
I 3 = I

.

012345012345012345

3=I

j
5 0

2=I


1 = I

j
5 0

5 0 j

38

( )

c++
Ex (35 ): ( ) do while
Sol///
> #include <iostream .h
)( Main
{

; Int i=0
.
;int sum =0
do
(
{ Do
) while
;I++
I


;Sum =sum+I
sum
;Cout <<i<<sum=<<sum <<\n

10 = I
}

;)While ( i<10
.
;Return 0
}

I=1 sum =1
I=2 sum =3
I=3 sum = 6
.
.
.
.
I=10 sum =55
1 10

sum = 55 .
};Sum =sum + I
Ex ( 36 ): y k
39

( )

c++
> # include <iostream .h
)( Main
{
;Int k,y,i=1
;unsigned long int p=1
Cout << enter two number where is first number is power
;for second number <<endl
;Cin >> y>>k
)While ( i<=k
{
;p=p*y
.
;i++
}
;Cout <<y <<power <<k<<is <<p<<\n
;Return 0
}
,
y,k I k
p*y k
(while )
.

enter two number where is first number is power for


second number
24
2 power 4 is 16
Ex (37 ):
Y=X*X+X+1/X x 42 0,2
> #include<iostream .h
)( Main
40

( )

c++
{
; Float x,y
x x 0.2
; X=1.8
2 4 x 2=0.2+1.8
{ Do
;X+=1.8
;Y=x*x+x+1/x
;Cout <<y=<<y<<endl
}
;)While (x<=4.0
;Return 0
}

2 y= 3.5
.
.
.
.
4 y= 20.25
Ex ( 38 ): ) 20 -1 (
> #include <iostream .h
)( Main
{
;Int sum =0
;Int x=2
)While (x<=20
{
;Sum =sum +x
;x= x+2
41

( )

c++
}
; Cout << the sum = <<sum << endl
}

the sum = 110

Ex ( 39 ): ) 20 1 (


x
2
. 2

Sol///
> #include < iostream .h
)( Int main
{
; Int sum =0

;Int x=0
{ Do
) If ( x % 2!=0
; Sum =sum + x
; Cout << the sum = << sum << endl
;x++
}
;) While ( x<=20
; Return
}

The sum = 100



;Int x=1;int sum =0
42

( )

c++

if

.

{ Do
;Sum = sum + x
; Cout << the sum = <<sum <<endl
;X+=2
}
;) While ( x<=20
};Return 0

Ex (40 ): ( -0 )
Sol///
> #include <iostream.h
)( Main
{
;Int i=0
; Int num
;Cin >> num
) While ( i<=num
{
; <<Cout <<i
;I=i+5
}
;Cout << the out loop<<endl
}

40
0 5 10 15 20 25 30 35 40
Ex (41 ):
43

( )

c++
Sol///
> #include <iostream.h
)( Main
{
;Int max-num,min num ,z
;Cout << enter two number <<endl
;Cin >> max-num>>min-num
;Z=min-num
)While ( z>1
{
)If ( max-num %z==0&&min-num%z==0
;Break
;Z--
}
;Cout <<z=<<z
}

( )6 -3
6 -2

.

6 2
2= z

(-:) for
( ) for
. ) while (



44

( )

c++
) for ( loop begin ; loop condition ; update loop
; statement

) for ( loop begin ; loop condition ; update loop
{
;Statement 1
;Statement 2
;Statement 3
.
.
.
.
;Statement n
}
-: loop begin
.
for (i=1 i=1 I

.
loop condition -:


.

; For ( i=1 ; i<=100 1


100 .
update loop -:
, 100 100-1
45

( )

c++

1 2, 3
( 1 2 3
, ..... 1 2 +
( )......9753 1 .

Ex:)for ( i=1 ; i<=10 ; i++


;sum =sum +I
1 ++I, 10
1 i=1
i=2 i=3 i+2
1 9 (
.(i=1,i=3,i=5,i=7,i=9
( . ) for
Ex ( 41 ): ( 10 0 (
( ) while for
Sol///
> # include <iostream .h
)( Int main
{
0 loop 10
.
;Int I
10+8+6+4+2+0
; Int sum =0
)For ( i=0 ;i<=10 ; 1+2

; Sum =sum + i
.
; Cout << the sum = << sum <<endl
0+2+4+6+8+10
}
46

( )

c++
10
0 2 10
. loop . 1

The sum = 30
-: for
loop . loop

)For ( i=1 ; i<=10 ; i++


{
) If ( i% 2==0
; Sum =sum + I
}
Ex (42 ): ( ) 10 -1 for
Sol///
> # include <iostream .h
)( Main
{
;Int I
; Int sum =0
)For ( i=1 ; i<=10 ;i++
; Sum =sum + I
; Cout << the sum of 10 number = <<sum
}

The sum of 10 number = 55
47

( )

c++
Ex ( 43 ) : ( ) 10 100 10
Sol///
> # include <iostream .h
)( Main
{
;Int I
;Cout << the result is <<endl
) For ( i=100 ; i>=10 ;i-10
{
;Cout <<i:<<I
};Cout <<\n
}

, for ,
I 100 10
10
.

I: 100
I: 90
I: 80
I: 70
I: 60
I: 50
I: 40
I: 30
I: 20
I: 10
48

( )

c++
( -: ) for

( ) for

Ex ( 44 ): ) 20 2 (
Sol///
> # include <iostream .h
,
)( Main
for

{
( ) while
;Int I
. . for
;Int sum =0
) For ( i=2 ; i<=10 ;sum + =2 , i+=2
; Cout <<sum is << sum + 2 <<endl
;Return 0
}

Sum is 2
2+4 =6
Sum is 6
for
Sum is 12
20 , 20= 8 + 12 , 12=6+6 .
Sum is 20
. 30= 10 +
Sum is 30
Ex ( 45 ) :
*****
****
***
**
*
Sol///
49

( )

c++

loop .
Loop 10 1 loop
10
I 1 . loop

> # include <iostream .h


)( Main
{
)For ( int i=10 ; i>=1;i--
{
)For ( int j =1 ; j<=I ; j++
;*<< Cout
; Cout <<endl
}
;Return 0
}

**********
*********
********
*******
******
*****
****
***
**
*
Ex ( 46 ) :
Y= 2/4+3/5+4/6+.+(n+1)/(n+3).
Sol///
> # include <iostream.h

)( Main
I = 1 1
{

) C= ( 1.0 + 1.0 50
I 3
( )
) C= ( 1.0 + 1.0 ) / ( 1.0 + 3.0

c++
;Float I
; Float sum =0
;Float c
)For ( i=1.0;i<=5.0 ; i++
{
) C= ( i+1.0 )/ ( i + 3.0
; Sum =sum + c
; Cout << sum << I << = << sum << endl
}
;Cout << the total sum is = << sum << \n
;Return 0
}

Sum1 = 0.5
Sum 2 = 1.1
Sum 3 = 1. 76667
Sum 4 = 2.48095
Sum 5 = 3.23095
Ex ( 47 ):
*******
*****
***
*
*
***
*****
*******
Sol///
51

( )

c++

Loop :
i 4

k . j

I

4= I k
1
7
loop k
.2*i-1

break

> #include <iostream.h


)( Main
{
;Int I,j,k
)For ( i=4;i>=1;i--
{
)For (j=1;j<=4-i;j++
;" " << Cout
)For ( k=1;k<=2*i-1;k++
;" * "<< Cout
;"Cout <<"\n
}
)For (i=1;i<=4;i++
{
)For (j=1;j<=4-i;j++
;" "<< Cout
)For ( k=1;k<=2*i-1;k++
;" * "<< Cout
;"Cout <<"\n
}
;"Cout <<"\n
;Return 0
}

-:


)If ( k==3
; Break
k = 3
. break
Ex ( 48 ): 52

( )

c++
y 6 = break
Sol///
? # include < iostream .h
)( Main
{
;Int y
)For ( y=1;y<=11;y++
) If ( y==6
; Break
;" "<<Cout <<y
; Cout <<"\n broke out of th loop "<<y<<endl
;Return 0
}

6
Broke out of loop 6
Ex ( 49 ): ( ) 10 1
Sol///
> #include < iostream .h

)( Main
.
{
;Int I
; Cout <<" number "<< " \t "<<" squ "<< "\t "<<" cube "<<endl
)For ( i=1;i<=10 ;i++
;"Cout << I << " \t "<<i*i<<"\t "<<i*i*i<<"\n
;Return 0
}
.

Number
squ
cube
1
1
1
2
4
8
3
9
27
53

( )

c++
64

16

1000

100

10
Ex ( 50 ):-


0+1+2+3 + ..n
2
Sol///

> # include < iostream.h



> #include < math .h
. c++
)( Main
{
; Int x,I,sum =0
;Cin >> x
)For ( i=0 ; i<=x;i++
pow
{
pow
math
;)Sum = sum + pow ( I,2
.
}
; Cout <<" the sum "<< sum << endl
}
Ex ( 51 ): R
R= 2/4+3/5+4/6n
Sol///
> #include <iostream .h
54

( )

c++
)( Main
{
;Float x,r=0
)For ( x=1;x<=8;x++
{
;)) R+ = ( float ) (( x+1 ) / ( x+3
; Cout <<"r="<<r<<endl
}
; Return
}

R= 0.5
R= 1.1
R=1.76667
R= 2.48095
R= 3. 23-95

R= 5.62691
Ex ( 52 ):
?) ( 1/10 )+ ( 2/15 ) + (3/20 ) + ..( 10 / 55
Sol///
> #include <iostream .h
)( Main
{

; Float x=1,y=10

;Float sum = 0
1 I
)For ( int i=1;i<=10 ;i++

{
sum
;Sum = sum + x/y
x/y
;"Cout <<"i="<<i<<"the sum ="<<sum <<"\n
1/10
.
X++
x
;Y+=5
+1

.
y + 5

sum .

55

( )

c++
}
Cout <<" the total sum for the series is "<< sum ;
Return 0;
}

I=1 the sum = 0.1


I=2 the sum = 0.2333333
I=3 the sum = 0. 383333
.
.
.
I=10 the sum = 1. 59602
Ex ( 53 ): loop 9-1
Sol///
#include < iostream.h >
Main ()
{
Int I,j;
Cout <<" this is multiplication of nine number "<<endl ;
For ( i=1 ;i<=9 ;i++)
For ( j=1;j<=9 ;j++)
{
Cout <<"\t"<<"i*j="<<endl;
i.j
Cout << "\t"<<i*j<<" ";
Cout <<"\n";}
}

I*j=
1 2 3 4 5 6 7 8 9
2 4 6 8 10 12 14 16 18
3 6 9 12 15 18 21 24 27
4 . . . . .
. .
.
56

) (

c++
5 . . . . .
. . .
6 . . . . .
. . .
7 . . . . .
. . .
8 . . . . .
. . .
9 18 27 36 45 54 63 72 81

Ex (54 ): float
number
> #include<iostream.h
)( Main
{
; Float x ,sum =0.0
;Cout <<" enter float number "<<endl
)For ( int i=1;i<=10;i++

{
1.2 = x
;Cin >> x
0.2 1

,
; )) Sum =sum + ( int x) x

) Sum = 0.0+ ( 1)- 1.2
}

) ( 1)- 1.2

. x

;" Cout <<" the sum = "<< sum << "\n


}

57

( )

c++
Enter float number
. x 0.2
0.2
The sum = 0.2
sum
1.2
The sum = 0.4
2.4
The sum = 0.8

sum
3.4
.
The sum = 1.2
Ex ( 55) : ( ) 1-10
Sol///
> #include < iostream .h
)( Main
{
; Int I
)For ( i=1;i<=10 ; i++
{
; Int sum =0

i* i . 10-1
;)Sum = sum +( i* i
}
;Cout <<" the sum ="<<sum <<end
}

58

( )

c++
The sum = 415

Ex ( 56 ): ( ) 5-1

!1!+2!+3!+4!+5
Sol///
> #include <iostream .h
)( Main
{
; Int sum =0
)For ( int i=1 ;i<=5 ;i++
{
;Int p=1
)For ( j=1;h>=1;j++
;p=p*j
;Sum =sum + p
}
; Cout << " sum ="<<sum <<endl
;Return 0
i=1 p , i=5
}
1-5
. 1-5
j
.

59
i=1 j j=I 1
sum
p

)
(
1
4 ,
j=4 j=1

c++


Sum = 153
Ex ( 57 ): ( ) 9-1
( ) while ) for (
Sol///
> # include < iostream .h
)( Main
{
; Cout << " the product by using while is "<<endl
;Int num = 1 , n=1
while

) While ( num <=9


,
n=9
; n = n* num

;num ++
.
}
; Cout <<" the product =" << n << endl
; n=1
60

( )

c++
; num =1
; Cout <<" the product by using for is = " <<endl
)For ( num=1;num<=9 ;num++
; n= n* num
for

;Cout <<n<<endl
, while
}
.

the product by using while is
the product =362880
the product by using for is =362880
ex ( 58 ): R
;R=2/4+3/5+.+9/11
Sol///
> #include <iostream.h
)( Main

{
9-2
;Float n

11-4
;Float R=0

)For ( n=2;n<=9;n++

n + 2 n=2
{
n+ 2 4
;)R+=n/(n+2
.
}
; Cout <<" R= "<<R<<endl
;Return 0
61

( )

c++

) R=R+ n/(n+2
n=2

) R=0+2/(2+2R= 0+ 2/4
.

}

R= 5.62691
Ex ( 59 ):-

for
,

,
9/3

.
Sol///
> # include < iostream .h
)( Main
{
true = prime
; Boolean prime = true
.
; Int num
; Cin >> num
1,2,3 )For ( int i=2;i<num/2;i++

{
.
) If ( num %i==0

{


; Prime = false
.
; Break
62

( )

c++
}
}
If ( prime= = true )
Cout <<num <<" is prime number "<<endl ;
Else
Cout <<num <<" is not prime number "<<endl ;}

2
2 is a prime number
Ex ( 60 ): Z
Z= cos ( y) * sin ( x)
Sol///
#include <iostream .h >
# include < math .h >
Main ()
{
Float z; int x,y ;
Cin >>y>>x;
Z= cos ( y )* sin ( x);
Cout <<" the value of Z= "<<Z<<endl ;
}

sin ,cos
63

) (

c++
> <math .h
.
Ex (61): y
?!Y = x/1!+x2/2!..........xn/n


x 1 xn
, 1
. x

.


1- x . ,

Sol///
> # include < iostream .h
)( Main
{
; Int x; float sum =0
; Float f=1; float y
;Int I,j
; Cout <<" enter x "<<endl
;Cin >> x
)For ( i=1 ;i<=x ;i++
{
;Sum =sum + I

64

( )

c++



. x-1

}
)For ( j= 1; j< =x; j++
{
}; F=f* j
; Y = sum / f
; Cout <<" y= "<< y << endl

( -: ) switch case

if

,

.

. ) switch case (


{) Switch ( statement
; Case 1
Case 2 :
.
.
.
.
} Case n :
Ex ( 62 ) :

Sol///
65

( )

c++
# include < iostream .h >
Main ()
{
Int day ;
Cout << " enter the number of day "<<endl ;
Cin >> day;
Switch ( day )
{
Case 1 : cout <<" the day is Saturday "<<endl ; break ;
Case 2 : cout <<" the day is Sunday " << endl;break ;
Case 3 : cout <<" the day is Monday "<<endl;break;
Case 4 : cout <<" the day is tusday "<<endl;braek ;
Case 5:cout <<" the day is wensday "<<endl;break ;
Case 6 : cout<<" the day is thersday "<<endl ; break;
Case 7 : cout <<" the day is Friday "<<endl;break ;
}
}

Enter the number of day


2
The day is Sunday

66

) (

c++

67

( )

c++

68

( )

You might also like