0% found this document useful (0 votes)
36 views10 pages

CPlusPart3 (WWW Yasbooks Com)

The document discusses conditional structures in C++ programming, specifically the switch-case structure. It provides an overview of switch-case syntax and usage, with an example of a program that takes a single character input and prints different outputs depending on whether the character is an uppercase letter A-D, lowercase a-d, number 1-4, or other character. The document is part of a C++ e-learning series in Farsi.

Uploaded by

dtramir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views10 pages

CPlusPart3 (WWW Yasbooks Com)

The document discusses conditional structures in C++ programming, specifically the switch-case structure. It provides an overview of switch-case syntax and usage, with an example of a program that takes a single character input and prints different outputs depending on whether the character is an uppercase letter A-D, lowercase a-d, number 1-4, or other character. The document is part of a C++ e-learning series in Farsi.

Uploaded by

dtramir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

www.IrPDF.

com

Farsi e-learning series

: C++


: c++
) (

-1-

C++

www.IrPDF.com

Farsi e-learning series

: C++

:
( if ) .

: 1

#include <iostream.h>
int main()
{
int a,b,c,max;

cout<<" Enter your numbers ";


cin>>a>>b>>c;
max=a;
if (b>max)
max=b;
if (c>max)
max=c;
cout<<" The max is " <<max<<endl;
return 0;
}

( if ) . : 2
#include <iostream.h>

int main()
{
int a,b,c,max,min;
cout<<" Enter your numbers ";
cin>>a>>b>>c;
max=a;
min=a;
if (b>a)
{
max=b; min=a;
}
else
{
max=a; min=b;
}
if (c>max)
max=c;
if (c<min)
min=c;
cout<<" The max is " <<max<<endl;
cout<<" The min is " <<min<<endl;
return 0;
}

-2-

www.IrPDF.com

Farsi e-learning series

: C++

. :3
#include <iostream.h>

int main()
{
int a,k,b,c;
cout<<"enter 3 numbers
cin>>a>>b>>c;
if ( b>a)
{
k=a; a=b; b=k;
}
if ( c>a)
{
k=a; a=c; c=k;
}
if ( c>b)
{
k=b; b=c; c=k;
}
cout<<"max number is :
cout<<"mid number is :
cout<<"min number is :
return 0;
}

-3-

";

"<<a<<endl;
"<<b<<endl;
"<<c<<endl;

www.IrPDF.com

Farsi e-learning series

: C++

:swich-case
.
:

)switch (variable
{
case 'value1-1':
case 'value2-1':

case 'value N-1':

;
;break
case 'value1-2':
case 'value2-2':

case 'value N-2':

;
;break

case 'value1-N':
case 'value2-N':

case 'value N-N':

;
;break
default:
5

;
}

:
= )) - switch (variable ( 1
value1-1 value1-3 value1-2 ... ) . ( 2
value2-1 value2-3 value2-2 ... ) . ( 3 ) ... . (4
; break .
) . ( 5

: 8 A B C D Big character :
a b c d little Character :
1 4 a figure ! :
unknown character ! :

-4-

www.IrPDF.com

Farsi e-learning series

: C++

#include <iostream.h>

int main()
{
char a;
cout<<" Enter your
cin>>a;
switch (a)
{
case
case
case
case

case
case
case
case

case
case
case
case

selected character ! :

";

'A':
'B':
'C':
'D':
cout<<"Big character ! ";
break;
'1':
'2':
'3':
'4':
cout<<" a figure ! ";
break;
'a':
'b':
'c':
'd':
cout<<" little character ! ";
break;
default:
cout<<"unknown character ! ";
break;

}
return 0;
}

: C++

: )( C++
for
do while
while


-1
-2
-3

-5-

www.IrPDF.com

Farsi e-learning series

: C++

: for
for :

) ; ; (for
{

}

: .

: 9 100 .
>#include <iostream.h

)(int main
{
;"cout<<"figures which are less than 100 : \n
)for(int i=0; i<100; i++
{
;cout<<i<<endl
}
;return 0
}
: 10 1 99 .

>#include <iostream.h

)(int main
{
;int s
;" cout<<"majmo is :
)for(int i=0; i<100; i++
{
;s=s+i
}
;cout<<s
;return 0
}

-6-

www.IrPDF.com

Farsi e-learning series

: C++

. 1000 100 : 11

#include <iostream.h>

int main()
{
int s,k;
cout<<"even numbers between 100 and 1000 are : ";
for(int i=100; i<1001; i++)
{
k=i%2;
if (k==0)
cout<<i<<" ";
}
return 0;
}
. 10 5 : 12

#include <iostream.h>

int main()
{
long int

p;

p=1;
for(int i=5; i<10; i++)
{
p=p*i;
}
cout<<" zarbe adade 5 ta 10 : " <<p;

return 0;
}

: while

while( )
{

}

-7-

www.IrPDF.com

Farsi e-learning series

: C++

: 13 9999 :
10 30 50 70 90 ...

>#include <iostream.h

)(int main
{
;long int a
;a=10
{)while (a<9999
"<<cout<<a
;"
;a+=20
}
;return 0
}

: 14 ) .
( .

>#include <iostream.h

;"<<endl

)(int main
{
;long int s,a
cout<<"enter your numbers :
;cin>>a
;s=a
{)while (a>0
;cin>>a
;s+=a
}
;cout<<"Sum is "<<s

;return 0
}

:do while

{do

) (}while
do while while
.

-8-

www.IrPDF.com

Farsi e-learning series

: C++

14 do while :
>#include <iostream.h

;"<<endl

)(int main
{
;int s,a
cout<<"enter your numbers :
;s=0
{do
;cin>>a
;s=a+s
;)} while (a>0
;"<<s

cout<<"Sum is

;return 0
}

: 15 ) .
(

>#include <iostream.h

;"<<endl

)(int main
{
;int s,max,min,a
cout<<"enter your numbers :
;cin>>a
;max=a; min=a
{)while (a>0
)if (a>max
;max=a
)if (a<min
;min=a
;cin>>a
}
;"<<max
;"<<min

cout<<"max is
cout<<"min is
;return 0
}

:
) -1 :(16 . .
:
0!=1

a!= 1*2*3**a

-9-

www.IrPDF.com

Farsi e-learning series

: C++

) -2 :(17 10 .
) -3 :( 18 .
) -4 :( 19 .
) : (
) -5 :( 20 1 5000 .
) -6 :( 21 ) .
( .
) -7 :(22 5 1 100 .
) -8 :( 23 .
) -9 :( 24 7 5 1 10000 .
) : 7 ( 5
)-10 :( 25 10 .
) -11 :( 26 :
1,1,2,3,5,8,13,21
:

n3

Fn1 + Fn2

Fn

Fn

F2 =1

F1 =1

) -12 : (27 .

:
:

www.mrh.ir
www.majidonline.com

:: 1385
!
- 10 -

You might also like