SlideShare a Scribd company logo
1 of 14
Chapter 3
Control Structure
Ragia A. Ibrahim, Ph.D. Student
1
‫القاهرة‬ ‫جامعة‬
‫االحصائيه‬ ‫والبحوث‬ ‫الدراسات‬ ‫معهد‬
‫مركز‬‫والبرمجيات‬ ‫المعلومات‬ ‫قواعد‬ ‫بحوث‬
‫االحصائيه‬ ‫والبحوث‬ ‫الدراسات‬ ‫معهد‬ ‫القاهرة‬ ‫جامعة‬
‫والبرمجيات‬ ‫المعلومات‬ ‫قواعد‬ ‫بحوث‬ ‫مركز‬
2
Types of Control Structure
•Sequence Structure
•Selection Structure
•Repetition Structure
int x;
x++;
Cout<<x;if
if/else
switch
For
While
do while
‫االحصائيه‬ ‫والبحوث‬ ‫الدراسات‬ ‫معهد‬ ‫القاهرة‬ ‫جامعة‬
‫والبرمجيات‬ ‫المعلومات‬ ‫قواعد‬ ‫بحوث‬ ‫مركز‬
3
Selection Structure
If (condition)
Statement;
If/else
Syntax Example
If (x>y && x>z)
cout<<x;
If (x>y)
{
t=x;
x=y;
y=t;
}
if
If (condition)
statement1;
else
statment2;
If (n>0)
m=n;
else
m=-n;
If (x%2==0)
cout<<x<<“is Even”;
else
cout<<x<<“is Odd”;
swap
‫االحصائيه‬ ‫والبحوث‬ ‫الدراسات‬ ‫معهد‬ ‫القاهرة‬ ‫جامعة‬
‫والبرمجيات‬ ‫المعلومات‬ ‫قواعد‬ ‫بحوث‬ ‫مركز‬
4
Selection Structure- Example-1
Finding the largest number among three numbers
Enter the numbers
12
20
8
The Largest number is 20
#include<iostream.h>
Int main()
{
int x,y,z,l;
cout<<“Enter the numbers/n”;
If(x>y)
l=x;
else
l=y;
If(z>l)
L=z;
cout<<“The Largest number is ”>>l;
Return 0;
}
Stop
Start
“Enter three Numbers”
Store Value In
X, Y, Z
Print L
IF X>Y L=X
L=Y
L=Z
Print L
IF Z>L
‫االحصائيه‬ ‫والبحوث‬ ‫الدراسات‬ ‫معهد‬ ‫القاهرة‬ ‫جامعة‬
‫والبرمجيات‬ ‫المعلومات‬ ‫قواعد‬ ‫بحوث‬ ‫مركز‬
5
Selection Structure- Example-2
Converting Exam Percentage into Grade
#include<iostream.h>
Int main()
{
int p; char g;
cout<<“Enter Exam Percentage”;
cin>>p;
If(p>=90)
g=‘A’;
else if (p>=80)
g=‘B’;
else if (p>=70)
g=‘C’;
else
g=‘D’;
cout<<“the grade is”<<g;
Return 0;
}
Stop
Start
“Enter Exam Percentage”
Store Value In
p
IF p>=90 g=‘A’
g=‘B’
Print “the grade is” g
IF p>=80
IF p>=70 g=‘C’
g=‘D’
Enter the Percentage
the grade is C
#include<iostream.h>
Int main()
{
int p; char g;
cout<<“Enter Exam Percentage”;
cin>>p;
If(p>=90)
g=‘A’;
if (p>=80)
g=‘B’;
if (p>=70)
g=‘C’;
if (p<60)
g=‘D’;
cout<<“the grade is”<<g;
return 0;
}
‫االحصائيه‬ ‫والبحوث‬ ‫الدراسات‬ ‫معهد‬ ‫القاهرة‬ ‫جامعة‬
‫والبرمجيات‬ ‫المعلومات‬ ‫قواعد‬ ‫بحوث‬ ‫مركز‬
6
Selection Structure- switch
Multiple selection.
Case a action
actionCase b
Case c action
Case z
Default
actions
break
break
break
action break
switch(Expression)
{
case constant1:
statement(s);break;
case constant2:
statement(s);break;
case constant3:
statement(s);break;
default:
statement(s);
}
‫االحصائيه‬ ‫والبحوث‬ ‫الدراسات‬ ‫معهد‬ ‫القاهرة‬ ‫جامعة‬
‫والبرمجيات‬ ‫المعلومات‬ ‫قواعد‬ ‫بحوث‬ ‫مركز‬
7
Selection Structure- switch
#include<iostream.h>
#include<manip.h>
Int main()
{ float x,y; char op;
cout<<“Enter Operand Operator and another operand”;
cin>>x>>op>>y;
switch(op)
{
case ‘+’:
r=x+y;break;
case ‘-’:
r=x-y;break;
case ‘*’:
r=x*y;break;
case ‘/’: if(y!=0.0) r=x/y;
else {cout<<“Division by zero not allowed n”; r=0.0;}break;
default: cout<<“Unknown Operator”<<op<<“/n”; r=0.0;
}
cout<<“The result=“<<setw(7)<<r;
return 0; }
Enter Operand Operator and another operand
12.3+16.4
The result= 28.7
‫االحصائيه‬ ‫والبحوث‬ ‫الدراسات‬ ‫معهد‬ ‫القاهرة‬ ‫جامعة‬
‫والبرمجيات‬ ‫المعلومات‬ ‫قواعد‬ ‫بحوث‬ ‫مركز‬
8
Repetition Structure
while (condition)
{ statement (s) ; }
do/while
Syntax Example
fact=1; //factorial
while(n>1)
{
fact=fact*n;
n=n-1;
}
While
do
{statement (s); }
while (condition)
fact=1;
Do
{
fact=fact*n;
n=n-1;
}
while(n>1)
for
{ statement (s) ; }
‫االحصائيه‬ ‫والبحوث‬ ‫الدراسات‬ ‫معهد‬ ‫القاهرة‬ ‫جامعة‬
‫والبرمجيات‬ ‫المعلومات‬ ‫قواعد‬ ‫بحوث‬ ‫مركز‬
9
e.g. investing example. Compute & print the amount invested in
n’th years for each year , for each year the amount(1+rate)^
number of years
#include<iostream.h>
#include<math.h>
#include <iomanip.h>
Int main()
{
double amount,p,r;
cout<<“Enter the origional amount invested”;
cin>>p;
cout<<“Enter the annual rate”;
cin>>r;
cout<<“Year”<<setw(21)<<“amount on deposit<<end;
for(int year=1;year<=10;year++)
{
amoun=p*pow(1+r, year);
cout<<year<<setw(21)<<setprecision(2)<<amount<<endl;
}
cin.get();
return 0;
}
set it to display in (21) right aligned
columns using setw(21)
Returns base raised to the power exponen
double
pow ( double base, double exponent )
- ios::left and ios::right, control
and right justification in your
output.
- precision, used to format floa
point
Set format flags
‫االحصائيه‬ ‫والبحوث‬ ‫الدراسات‬ ‫معهد‬ ‫القاهرة‬ ‫جامعة‬
‫والبرمجيات‬ ‫المعلومات‬ ‫قواعد‬ ‫بحوث‬ ‫مركز‬
10
Nested loops
‫االحصائيه‬ ‫والبحوث‬ ‫الدراسات‬ ‫معهد‬ ‫القاهرة‬ ‫جامعة‬
‫والبرمجيات‬ ‫المعلومات‬ ‫قواعد‬ ‫بحوث‬ ‫مركز‬
11
Example1:
#include<iostream.h>
Int main()
{ int linenumber, i ;
for(linenumber=1; linenumber<=5;linenumber++)
{
for(i=1;i<=linenumber;i++)
cout<<i;
//when:
cout<<endl;
}
cin.get();
return 0;
}
‫االحصائيه‬ ‫والبحوث‬ ‫الدراسات‬ ‫معهد‬ ‫القاهرة‬ ‫جامعة‬
‫والبرمجيات‬ ‫المعلومات‬ ‫قواعد‬ ‫بحوث‬ ‫مركز‬
12
#include<iostream.h>
Int main()
{ int linenumber, i ;
for(linenumber=1; linenumber<=5;linenumber++)
{
for(i=1;i<=5-linenumber;i++)
cout<<‘ ‘;
for(j=1;j<=2*linenumber-1;j++)
cout<<‘*’;
cout<<endl;
}
cin.get();
return 0;
}
Example2:
‫االحصائيه‬ ‫والبحوث‬ ‫الدراسات‬ ‫معهد‬ ‫القاهرة‬ ‫جامعة‬
‫والبرمجيات‬ ‫المعلومات‬ ‫قواعد‬ ‫بحوث‬ ‫مركز‬
13
#include<iostream.h>
Int main()
{ int linenumber, i ;
for(linenumber=1; linenumber<=5;linenumber++)
{
for(i=1;i<=linenumber;i++)
cout<<' ';
for(j=10;j> 2*linenumber-1;j--)
cout<<'*';
cout<<endl;
}
cin.get();
return 0;
Example3:
‫االحصائيه‬ ‫والبحوث‬ ‫الدراسات‬ ‫معهد‬ ‫القاهرة‬ ‫جامعة‬
‫والبرمجيات‬ ‫المعلومات‬ ‫قواعد‬ ‫بحوث‬ ‫مركز‬
14
#include<iostream.h>
Int main()
{ int linenumber, i ;
for(linenumber=1; linenumber<=5;linenumber++)
{
for(i=1;i<=linenumber;i++)
cout<<' ';
for(j=10;j> 2*linenumber-1;j--)
cout<<'*';
cout<<endl;
}
cin.get();
return 0;
Example3:

More Related Content

Viewers also liked

Viewers also liked (9)

R programming Fundamentals
R programming  FundamentalsR programming  Fundamentals
R programming Fundamentals
 
Version Control With GitHub & RStudio
Version Control With GitHub & RStudioVersion Control With GitHub & RStudio
Version Control With GitHub & RStudio
 
Step by Step Guidance to Study Abroad
Step by Step Guidance to Study AbroadStep by Step Guidance to Study Abroad
Step by Step Guidance to Study Abroad
 
R program
R programR program
R program
 
R Programming: First Steps
R Programming: First StepsR Programming: First Steps
R Programming: First Steps
 
R programming intro with examples
R programming intro with examplesR programming intro with examples
R programming intro with examples
 
R Programming: Introduction to Matrices
R Programming: Introduction to MatricesR Programming: Introduction to Matrices
R Programming: Introduction to Matrices
 
Getting Up to Speed with R: Certificate Program in R for Statistical Analysis...
Getting Up to Speed with R: Certificate Program in R for Statistical Analysis...Getting Up to Speed with R: Certificate Program in R for Statistical Analysis...
Getting Up to Speed with R: Certificate Program in R for Statistical Analysis...
 
RMySQL Tutorial For Beginners
RMySQL Tutorial For BeginnersRMySQL Tutorial For Beginners
RMySQL Tutorial For Beginners
 

Recently uploaded

امتحانات النحو وإجاباتها.pdfrrrrrrrrrrrrrr
امتحانات النحو وإجاباتها.pdfrrrrrrrrrrrrrrامتحانات النحو وإجاباتها.pdfrrrrrrrrrrrrrr
امتحانات النحو وإجاباتها.pdfrrrrrrrrrrrrrr
mhosn627
 

Recently uploaded (20)

REKOD TRANSIT BAHASA ARAB SK Tahun 3.pptx
REKOD TRANSIT BAHASA ARAB SK Tahun 3.pptxREKOD TRANSIT BAHASA ARAB SK Tahun 3.pptx
REKOD TRANSIT BAHASA ARAB SK Tahun 3.pptx
 
محمد احمد سيد احمد محمد سباق عمر يوسف عبدالكريم
محمد احمد سيد احمد محمد سباق عمر يوسف عبدالكريممحمد احمد سيد احمد محمد سباق عمر يوسف عبدالكريم
محمد احمد سيد احمد محمد سباق عمر يوسف عبدالكريم
 
أدب درس النقائض إعداد سلوي أحمد بديرأحمد
أدب درس النقائض إعداد سلوي أحمد بديرأحمدأدب درس النقائض إعداد سلوي أحمد بديرأحمد
أدب درس النقائض إعداد سلوي أحمد بديرأحمد
 
اهمية ملحمة جلجامش تاريخيا وفكريا وأدبيا
اهمية ملحمة جلجامش تاريخيا وفكريا وأدبيااهمية ملحمة جلجامش تاريخيا وفكريا وأدبيا
اهمية ملحمة جلجامش تاريخيا وفكريا وأدبيا
 
امتحانات النحو وإجاباتها.pdfrrrrrrrrrrrrrr
امتحانات النحو وإجاباتها.pdfrrrrrrrrrrrrrrامتحانات النحو وإجاباتها.pdfrrrrrrrrrrrrrr
امتحانات النحو وإجاباتها.pdfrrrrrrrrrrrrrr
 
.العروض التقديمية والرسومات التعليمية bdf
.العروض التقديمية والرسومات التعليمية bdf.العروض التقديمية والرسومات التعليمية bdf
.العروض التقديمية والرسومات التعليمية bdf
 
السرقات الشعرية إعداد غادة محمد عبد الراضي
السرقات الشعرية إعداد غادة محمد عبد الراضيالسرقات الشعرية إعداد غادة محمد عبد الراضي
السرقات الشعرية إعداد غادة محمد عبد الراضي
 
دمشق تاريخ معطر بالياسمين - ماهر أسعد بكر
دمشق تاريخ معطر بالياسمين - ماهر أسعد بكردمشق تاريخ معطر بالياسمين - ماهر أسعد بكر
دمشق تاريخ معطر بالياسمين - ماهر أسعد بكر
 
عرض تقديمي عن اسم المفعول.امل عرفات محمد العربي جامعة جنوب الوادي تربيه عام ...
عرض تقديمي عن اسم المفعول.امل عرفات محمد العربي  جامعة جنوب الوادي تربيه عام ...عرض تقديمي عن اسم المفعول.امل عرفات محمد العربي  جامعة جنوب الوادي تربيه عام ...
عرض تقديمي عن اسم المفعول.امل عرفات محمد العربي جامعة جنوب الوادي تربيه عام ...
 
.. مهارات ادارة الوقت و مهارات تنظيم الوقت.ppt
.. مهارات ادارة الوقت و مهارات تنظيم الوقت.ppt.. مهارات ادارة الوقت و مهارات تنظيم الوقت.ppt
.. مهارات ادارة الوقت و مهارات تنظيم الوقت.ppt
 
1 علم الخلية الم.pdf............................................................
1 علم الخلية الم.pdf............................................................1 علم الخلية الم.pdf............................................................
1 علم الخلية الم.pdf............................................................
 
أسامه رجب علي أحمد (عرض تقديمي عن الجمل التي لها محل من الاعراب والتي ليس لها...
أسامه رجب علي أحمد (عرض تقديمي عن الجمل التي لها محل من الاعراب والتي ليس لها...أسامه رجب علي أحمد (عرض تقديمي عن الجمل التي لها محل من الاعراب والتي ليس لها...
أسامه رجب علي أحمد (عرض تقديمي عن الجمل التي لها محل من الاعراب والتي ليس لها...
 
عرض تقديمي لعملية الجمع للاطفال ورياض الاطفال
عرض تقديمي لعملية الجمع للاطفال ورياض الاطفالعرض تقديمي لعملية الجمع للاطفال ورياض الاطفال
عرض تقديمي لعملية الجمع للاطفال ورياض الاطفال
 
"الدعامة الأساسية التي يقوم عليها التقويم الذاتي
"الدعامة الأساسية التي يقوم عليها التقويم الذاتي"الدعامة الأساسية التي يقوم عليها التقويم الذاتي
"الدعامة الأساسية التي يقوم عليها التقويم الذاتي
 
درس المنادي للصف الاول الثانوي اعداد إسراء محمد
درس المنادي للصف الاول الثانوي اعداد إسراء محمددرس المنادي للصف الاول الثانوي اعداد إسراء محمد
درس المنادي للصف الاول الثانوي اعداد إسراء محمد
 
by modar saleh في التصوير التلفزيوني أحجام اللقطات .ppt
by modar saleh في التصوير التلفزيوني أحجام اللقطات .pptby modar saleh في التصوير التلفزيوني أحجام اللقطات .ppt
by modar saleh في التصوير التلفزيوني أحجام اللقطات .ppt
 
سلسلة في التجويد للدورات التمهيدية والمتوسطة والمتقدمة.pdf
سلسلة في التجويد للدورات التمهيدية  والمتوسطة والمتقدمة.pdfسلسلة في التجويد للدورات التمهيدية  والمتوسطة والمتقدمة.pdf
سلسلة في التجويد للدورات التمهيدية والمتوسطة والمتقدمة.pdf
 
الصف الثاني الاعدادي - العلوم -الموجات.pdf
الصف الثاني الاعدادي - العلوم -الموجات.pdfالصف الثاني الاعدادي - العلوم -الموجات.pdf
الصف الثاني الاعدادي - العلوم -الموجات.pdf
 
عرض تقديمي دور مجتمعات التعليم في تحسين جودة الحياة الجامعية .pdf
عرض تقديمي دور مجتمعات التعليم في تحسين جودة الحياة الجامعية .pdfعرض تقديمي دور مجتمعات التعليم في تحسين جودة الحياة الجامعية .pdf
عرض تقديمي دور مجتمعات التعليم في تحسين جودة الحياة الجامعية .pdf
 
اللام الشمسية واللام القمرية لصف الرابع
اللام الشمسية واللام القمرية  لصف الرابعاللام الشمسية واللام القمرية  لصف الرابع
اللام الشمسية واللام القمرية لصف الرابع
 

Chapter 3

  • 1. Chapter 3 Control Structure Ragia A. Ibrahim, Ph.D. Student 1 ‫القاهرة‬ ‫جامعة‬ ‫االحصائيه‬ ‫والبحوث‬ ‫الدراسات‬ ‫معهد‬ ‫مركز‬‫والبرمجيات‬ ‫المعلومات‬ ‫قواعد‬ ‫بحوث‬
  • 2. ‫االحصائيه‬ ‫والبحوث‬ ‫الدراسات‬ ‫معهد‬ ‫القاهرة‬ ‫جامعة‬ ‫والبرمجيات‬ ‫المعلومات‬ ‫قواعد‬ ‫بحوث‬ ‫مركز‬ 2 Types of Control Structure •Sequence Structure •Selection Structure •Repetition Structure int x; x++; Cout<<x;if if/else switch For While do while
  • 3. ‫االحصائيه‬ ‫والبحوث‬ ‫الدراسات‬ ‫معهد‬ ‫القاهرة‬ ‫جامعة‬ ‫والبرمجيات‬ ‫المعلومات‬ ‫قواعد‬ ‫بحوث‬ ‫مركز‬ 3 Selection Structure If (condition) Statement; If/else Syntax Example If (x>y && x>z) cout<<x; If (x>y) { t=x; x=y; y=t; } if If (condition) statement1; else statment2; If (n>0) m=n; else m=-n; If (x%2==0) cout<<x<<“is Even”; else cout<<x<<“is Odd”; swap
  • 4. ‫االحصائيه‬ ‫والبحوث‬ ‫الدراسات‬ ‫معهد‬ ‫القاهرة‬ ‫جامعة‬ ‫والبرمجيات‬ ‫المعلومات‬ ‫قواعد‬ ‫بحوث‬ ‫مركز‬ 4 Selection Structure- Example-1 Finding the largest number among three numbers Enter the numbers 12 20 8 The Largest number is 20 #include<iostream.h> Int main() { int x,y,z,l; cout<<“Enter the numbers/n”; If(x>y) l=x; else l=y; If(z>l) L=z; cout<<“The Largest number is ”>>l; Return 0; } Stop Start “Enter three Numbers” Store Value In X, Y, Z Print L IF X>Y L=X L=Y L=Z Print L IF Z>L
  • 5. ‫االحصائيه‬ ‫والبحوث‬ ‫الدراسات‬ ‫معهد‬ ‫القاهرة‬ ‫جامعة‬ ‫والبرمجيات‬ ‫المعلومات‬ ‫قواعد‬ ‫بحوث‬ ‫مركز‬ 5 Selection Structure- Example-2 Converting Exam Percentage into Grade #include<iostream.h> Int main() { int p; char g; cout<<“Enter Exam Percentage”; cin>>p; If(p>=90) g=‘A’; else if (p>=80) g=‘B’; else if (p>=70) g=‘C’; else g=‘D’; cout<<“the grade is”<<g; Return 0; } Stop Start “Enter Exam Percentage” Store Value In p IF p>=90 g=‘A’ g=‘B’ Print “the grade is” g IF p>=80 IF p>=70 g=‘C’ g=‘D’ Enter the Percentage the grade is C #include<iostream.h> Int main() { int p; char g; cout<<“Enter Exam Percentage”; cin>>p; If(p>=90) g=‘A’; if (p>=80) g=‘B’; if (p>=70) g=‘C’; if (p<60) g=‘D’; cout<<“the grade is”<<g; return 0; }
  • 6. ‫االحصائيه‬ ‫والبحوث‬ ‫الدراسات‬ ‫معهد‬ ‫القاهرة‬ ‫جامعة‬ ‫والبرمجيات‬ ‫المعلومات‬ ‫قواعد‬ ‫بحوث‬ ‫مركز‬ 6 Selection Structure- switch Multiple selection. Case a action actionCase b Case c action Case z Default actions break break break action break switch(Expression) { case constant1: statement(s);break; case constant2: statement(s);break; case constant3: statement(s);break; default: statement(s); }
  • 7. ‫االحصائيه‬ ‫والبحوث‬ ‫الدراسات‬ ‫معهد‬ ‫القاهرة‬ ‫جامعة‬ ‫والبرمجيات‬ ‫المعلومات‬ ‫قواعد‬ ‫بحوث‬ ‫مركز‬ 7 Selection Structure- switch #include<iostream.h> #include<manip.h> Int main() { float x,y; char op; cout<<“Enter Operand Operator and another operand”; cin>>x>>op>>y; switch(op) { case ‘+’: r=x+y;break; case ‘-’: r=x-y;break; case ‘*’: r=x*y;break; case ‘/’: if(y!=0.0) r=x/y; else {cout<<“Division by zero not allowed n”; r=0.0;}break; default: cout<<“Unknown Operator”<<op<<“/n”; r=0.0; } cout<<“The result=“<<setw(7)<<r; return 0; } Enter Operand Operator and another operand 12.3+16.4 The result= 28.7
  • 8. ‫االحصائيه‬ ‫والبحوث‬ ‫الدراسات‬ ‫معهد‬ ‫القاهرة‬ ‫جامعة‬ ‫والبرمجيات‬ ‫المعلومات‬ ‫قواعد‬ ‫بحوث‬ ‫مركز‬ 8 Repetition Structure while (condition) { statement (s) ; } do/while Syntax Example fact=1; //factorial while(n>1) { fact=fact*n; n=n-1; } While do {statement (s); } while (condition) fact=1; Do { fact=fact*n; n=n-1; } while(n>1) for { statement (s) ; }
  • 9. ‫االحصائيه‬ ‫والبحوث‬ ‫الدراسات‬ ‫معهد‬ ‫القاهرة‬ ‫جامعة‬ ‫والبرمجيات‬ ‫المعلومات‬ ‫قواعد‬ ‫بحوث‬ ‫مركز‬ 9 e.g. investing example. Compute & print the amount invested in n’th years for each year , for each year the amount(1+rate)^ number of years #include<iostream.h> #include<math.h> #include <iomanip.h> Int main() { double amount,p,r; cout<<“Enter the origional amount invested”; cin>>p; cout<<“Enter the annual rate”; cin>>r; cout<<“Year”<<setw(21)<<“amount on deposit<<end; for(int year=1;year<=10;year++) { amoun=p*pow(1+r, year); cout<<year<<setw(21)<<setprecision(2)<<amount<<endl; } cin.get(); return 0; } set it to display in (21) right aligned columns using setw(21) Returns base raised to the power exponen double pow ( double base, double exponent ) - ios::left and ios::right, control and right justification in your output. - precision, used to format floa point Set format flags
  • 10. ‫االحصائيه‬ ‫والبحوث‬ ‫الدراسات‬ ‫معهد‬ ‫القاهرة‬ ‫جامعة‬ ‫والبرمجيات‬ ‫المعلومات‬ ‫قواعد‬ ‫بحوث‬ ‫مركز‬ 10 Nested loops
  • 11. ‫االحصائيه‬ ‫والبحوث‬ ‫الدراسات‬ ‫معهد‬ ‫القاهرة‬ ‫جامعة‬ ‫والبرمجيات‬ ‫المعلومات‬ ‫قواعد‬ ‫بحوث‬ ‫مركز‬ 11 Example1: #include<iostream.h> Int main() { int linenumber, i ; for(linenumber=1; linenumber<=5;linenumber++) { for(i=1;i<=linenumber;i++) cout<<i; //when: cout<<endl; } cin.get(); return 0; }
  • 12. ‫االحصائيه‬ ‫والبحوث‬ ‫الدراسات‬ ‫معهد‬ ‫القاهرة‬ ‫جامعة‬ ‫والبرمجيات‬ ‫المعلومات‬ ‫قواعد‬ ‫بحوث‬ ‫مركز‬ 12 #include<iostream.h> Int main() { int linenumber, i ; for(linenumber=1; linenumber<=5;linenumber++) { for(i=1;i<=5-linenumber;i++) cout<<‘ ‘; for(j=1;j<=2*linenumber-1;j++) cout<<‘*’; cout<<endl; } cin.get(); return 0; } Example2:
  • 13. ‫االحصائيه‬ ‫والبحوث‬ ‫الدراسات‬ ‫معهد‬ ‫القاهرة‬ ‫جامعة‬ ‫والبرمجيات‬ ‫المعلومات‬ ‫قواعد‬ ‫بحوث‬ ‫مركز‬ 13 #include<iostream.h> Int main() { int linenumber, i ; for(linenumber=1; linenumber<=5;linenumber++) { for(i=1;i<=linenumber;i++) cout<<' '; for(j=10;j> 2*linenumber-1;j--) cout<<'*'; cout<<endl; } cin.get(); return 0; Example3:
  • 14. ‫االحصائيه‬ ‫والبحوث‬ ‫الدراسات‬ ‫معهد‬ ‫القاهرة‬ ‫جامعة‬ ‫والبرمجيات‬ ‫المعلومات‬ ‫قواعد‬ ‫بحوث‬ ‫مركز‬ 14 #include<iostream.h> Int main() { int linenumber, i ; for(linenumber=1; linenumber<=5;linenumber++) { for(i=1;i<=linenumber;i++) cout<<' '; for(j=10;j> 2*linenumber-1;j--) cout<<'*'; cout<<endl; } cin.get(); return 0; Example3: