Professional Documents
Culture Documents
NestedLoops C++
NestedLoops C++
Write a program that reads two positive integers that represent rows and
columns and prints a rectangle of asterisks as shown.
# include <iostream>
using namespace std; Enter two positive integers: 3 5
*****
int main ( ) *****
{ *****
int rows, cols, i, j;
return 0;
}
int n, i, j;
cin >> n;
عدددد النجددوم يددزداد كلمدا زاد رقددم
.) بالموجبi( لذا تكون،الصف
return 0;
}
int n, i, j;
cin >> n;
return 0;
}
أو بالبريد اإللكتروني9 4444 062 النوتات مجانية للنفع العام فيرجى المساهمة باإلبالغ عن أي خطأ أو مالحظات تراها ضرورية برسالة نصية
Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms, Numerical, Economy
eng-hs.com, eng-hs.net شرح ومسائل محلولة مجانا بالموقعين info@eng-hs.com 9 4444 260 حمادة شعبان.م
Oct 2013
int n, i, j;
cin >> n;
if ( j == 1 || j == n || i == j )
j=1 j=n
i=2
else
i=3 i=j
return 0;
}
int n, i, j;
أ لب األشكال يمكن اعتبارها
كمربع به نجوم ومسافات
cout << "Enter a positive integer: "; .)if (حيث يمكن استخدام
cin >> n;
if ( i == 1 || j == n || i + j == n + 1 )
return 0;
}
cin >> n;
return 0;
}
أو بالبريد اإللكتروني9 4444 062 النوتات مجانية للنفع العام فيرجى المساهمة باإلبالغ عن أي خطأ أو مالحظات تراها ضرورية برسالة نصية
Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms, Numerical, Economy
eng-hs.com, eng-hs.net شرح ومسائل محلولة مجانا بالموقعين info@eng-hs.com 9 4444 260 حمادة شعبان.م
Oct 2013
int n, i, j;
cin >> n;
return 0;
}
int n, i, j;
cin >> n;
cout << j << ' '; البدايددة فددي كددل سددطر تددزداد بازديدداد
،)n( النهايددة دائمددا نفدد قيمددة،)i(
cout << endl; .)+1( الخطوة بين كل رقمين هي
}
return 0;
}
أو بالبريد اإللكتروني9 4444 062 النوتات مجانية للنفع العام فيرجى المساهمة باإلبالغ عن أي خطأ أو مالحظات تراها ضرورية برسالة نصية
Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms, Numerical, Economy
eng-hs.com, eng-hs.net شرح ومسائل محلولة مجانا بالموقعين info@eng-hs.com 9 4444 260 حمادة شعبان.م
Oct 2013
cin >> n;
return 0;
char j;
cin >> n;
return 0;
}
int n, i;
char j;
cin >> n;
النهاية،)A( البداية في كل سطر ثابتة
الخطددوة،)1( تددزداد كددل سددطر بمقدددار
for ( i = 1; i <= n; i++ ) .)+1( بين كل رقمين هي
{
for ( j = 'A'; j <= 'A' + i - 1; j++ )
return 0;
}
cin >> n;
for ( j = ( n – i ) * 2 + 1; j >= 1; j -= 2 )
البرامج السابقة يمكن كتابتها
cout << j << ' '; بأكثر من طريقة
.output والمهم نف الـ
cout << endl;
}
return 0;
}
Exercise 2.28: Write a program that reads in the size of the side of a square
and then prints a hollow square of that size out of asterisks. Your program
should work for squares of all side sizes between 1 and 20.
# include <iostream>
using namespace std;
int main ( )
{
int size;
cout << "Enter the size of the side of the square: ";
cin >> size;
أو بالبريد اإللكتروني9 4444 062 النوتات مجانية للنفع العام فيرجى المساهمة باإلبالغ عن أي خطأ أو مالحظات تراها ضرورية برسالة نصية
Physics I/II, English 123, Statics, Dynamics, Strength, Structure I/II, C++, Java, Data, Algorithms, Numerical, Economy
eng-hs.com, eng-hs.net شرح ومسائل محلولة مجانا بالموقعين info@eng-hs.com 9 4444 260 حمادة شعبان.م
Oct 2013
Exercise 2.47: Write a program that uses for structures to print the
following patterns separately, one below the other. Use for loops to generate
the patterns. All asterisks (*) should be printed by a single statement of the
form cout << '*'; (this causes the asterisks to print side by side).
# include <iostream>
using namespace std;
int main ( )
{
int i, j, k;
return 0;
}
Exercise 2.55: A right triangle can have sides that are all integers. A set of
three integer values for the sides of a right triangle is called a Pythagorean
triple. These three sides must satisfy the relationship that the sum of the
squares of two of the sides is equal to the square of the hypotenuse. Find all
Pythagorean triples for side1, side2 and hypotenuse all no larger than 500.
Use a triple-nested for loop that tries all possibilities.
# include <iostream>
using namespace std;
int main ( )
{
int i, j, k;
cout << "The Phytagorean triples from 1 to 500 are: " << endl;
return 0;
}