حل السي بلس بلس


(system) #1

Princess Nora Bint Abdulrahman University Course: Computer Programming 1 (CS240)
College of Computer and Information Sciences Assignment # 4
Q1: Compute the number of times the statement in the body of the following for loops will be executed:
a) int i,sum;
for(i=3;i<=5;++i)
sum=sum+i;
b) int i, sum;
for (i=1;i<=5;i+=2)
sum=sum+i;
Q2: Find the error in each of the following code segments, and explain how to correct it:
a) for(x=100,x>=150;x++)
cout<<x<<endl;
b) the following code should output odd integers from 999 to 1:
for(x=999;x>=1;x+=2)
cout<<x<<endl;
Q3: Rewrite the following if structure as condition expression by using conditional operator:
if(a>b)
c=20
else
c=30
Q4: Write the Output of the Following Code:
int n; int stop = 3; int start = 8; cout << “start on 8” << endl; for(n = (start-1); n >= stop; n–) { if(n=stop) cout << "stop on " << n << endl; else cout << "down to " << n << endl; }
Q5: Write a program that asks the user to type 10 integers and writes the smallest value.
Q6: write program that reads in the side of square and prints the square out of asterisks. Your program should work for squares of all side sizes between 1 and 20. For example, if your program read a size of 4, it should print:




ابغى الحل ضروري يعطيكم العافيه اليوم