Sheet 04
Sheet 04
كليـة الهندسة
برامج الساعات المعتمدة
1/3
جامعة عين شمس
كليـة الهندسة
برامج الساعات المعتمدة
2/3
جامعة عين شمس
كليـة الهندسة
برامج الساعات المعتمدة
3/3
جامعة عين شمس
كليـة الهندسة
برامج الساعات المعتمدة
4/3
جامعة عين شمس
كليـة الهندسة
برامج الساعات المعتمدة
int i, j;
for (i = 0; i < 10; ++i)
{
for (j = 0; j < i; j++)
cout << i * j;
cout << "Good Luck";
}
a) How many times does the first call to cout execute? Answer: 45
b) How many times does the second call to cout execute? Answer: 10
c) What is the last value displayed? Answer: "Good Luck"
d) Evaluate the output of the program manually showing each step in detail.
i j (j<i) First cout Second cout
i=0 False Good Luck → 1
i=1 j=0 True i*j=0 → 1
Good Luck → 2
i=2 j=0 True i*j=0 → 2
5/3
جامعة عين شمس
كليـة الهندسة
برامج الساعات المعتمدة
int main()
{
long num=654;
do
{
cout << (num%10);
num /= 10;
} while (num != 0);
cout << endl;
return (0(;
}
Answer: 456
7/3
جامعة عين شمس
كليـة الهندسة
برامج الساعات المعتمدة
int main()
{
float grade;
cin >> grade;
if (grade > 75)
cout << "very good\n";
else if (grade > 85)
cout << "excellent\n";
return 0;
Answer:
Answer: 30
int x, i, n, count=0;
for (i=0; i<n; i++)
{
cin >> x;
if (x==i) ++count;
}
Answer:
int x, i = 0, n, count = 0;
while (i < n) {
cin >> x;
if (x == i) {
++count;
}
++i;
}
1 1 1 1 1
b) 1 + + + + + ............ +
2 3 4 5 n
3 5 7 2n - 1
c) 1 + 2 + 2 + 2 + ... 2
2 3 4 n
d) k + 2 * k + 3 * k + 4 * k + ........... + N * k
1 1 1 1 1
e) + + + + ........... +
A A + B A + 2B A + 3B A + NB
14. Write a program that computes and prints the sum of all integers from 1 to 100,
and divisible by 2 and 3.
15. Write a program to read the number of exam scores then read the exam scores
themselves. Your program needs to find and print the average.
9/3
جامعة عين شمس
كليـة الهندسة
برامج الساعات المعتمدة
*
***
*****
*******
10/3