0% found this document useful (0 votes)
14 views4 pages

Exercises 3

The document contains coding exercises and solutions. It includes loops (for, while), conditional statements (if/else), input/output streams, data types, operators, and formatting (setprecision, setw). The exercises demonstrate basic programming concepts like calculating sums, formatting output, using switch statements, and iterating with counters.

Uploaded by

omarsarwt590
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)
14 views4 pages

Exercises 3

The document contains coding exercises and solutions. It includes loops (for, while), conditional statements (if/else), input/output streams, data types, operators, and formatting (setprecision, setw). The exercises demonstrate basic programming concepts like calculating sums, formatting output, using switch statements, and iterating with counters.

Uploaded by

omarsarwt590
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/ 4

Exercises 3 eng: omar sarwt

3.1

a- true

b-true

c- false , Because the expression x>y and a<b both must be true not one of both is true

d-true

-----------------------------------------------------------------------------------------------------------------------------------------

3.2

a-

int sum=1;

cout <<" sum of the odd integers between 1 and 99" << endl;

for (int count=-1 ; count<=99 ; count +=2)

sum= sum + count;

cout<< "sum = " << sum <<endl;

b-

#include <iostream>

#include <cmath>

#include <iomanip>

using namespace std;

int main()

{ double value = 333.546372;

cout << fixed << setprecision (1) << left << setw (15) << value;

cout << setprecision (2) << setw (15) << value;

cout << setprecision (3) << setw (15) << value << endl;

return 0;}
c-

#include <iostream>

#include <cmath>

#include <iomanip>

using namespace std;

int main()

double value;

value = pow (2.5, 3);

cout << fixed << setprecision (2) << setw (10) << value << endl << endl;

return 0;

d-

int x=1;

while (x <= 20)

{ cout << x;

if (x % 5 == 0)

cout << "\n";

else

cout << "\t";

x++;

cout << endl;


e-

for (int x = 1; x <= 20; x++)

cout << x;

if (x % 5 == 0)

cout << "\n";

else

cout << "\t";

cout<< endl;

------------------------------------------------------------------------------------------------------------------------------------------

3.3

a-

int x = 1;

while ( x <= 10 )

cout << x;

x++;

b-

for (int y = 1; y != 10; y++ )

cout << ( static_cast< double >( y ) / 10 ) << endl;


c-

int n;

cin >>n;

switch (n)

{ case 1:

cout << "The number is 1" << endl;

break;

case 2:

cout << "The number is 2" << endl;

break;

default:

cout << "The number is not 1 or 2" << endl;

break;}

d-

int n = 1;

while ( n < 11 )

cout << n++ << endl;

(or)

int n = 1;

while ( n <= 10 )

cout << n++ << endl;

You might also like