Вы находитесь на странице: 1из 4

EL_REHIM@HOTMAIL.

COM

// 1. Write a C++ program that reads three integers, and then prints the smalles t, and the largest of these numbers. // Using only the single selection form of if statement. #include <iostream> using namespace std; int main(int nNumberofArgs, char* pszArgs[]) { cout << "Enter Three Numbers"; int no1; cout << "Enter No1: "; cin >> no1; int no2; cout << "Enter No2: "; cin >> no2; int no3; cout << "Enter No3: "; cin >> no3; if (no1 > no2 && no1>no3 ) { cout << "No1 is the greatest" << endl; } if (no2 > no1 && no2>no3 ) { cout << "No2 is the greatest" << endl; } if (no3 > no1 && no3>no2 ) { cout << "No3 is the greatest" << endl; } system("PAUSE"); return 0; } // 2. Write a C++ program that reads an integer and determines and prints whethe r it is odd or even. // (Hint: Use the modulus operator. An even number is a multiple of 2, and any m ultiple of two leaves a remainder of zero when divided by 2). #include <iostream> using namespace std; int main(int nNumberofArgs, char* pszArgs[]) {

cout << "Enter Two Numbers"; int no1; cout << "Enter No1: "; cin >> no1; int no2; cout << "Enter No2: "; cin >> no2; if (no1 % 2 != 0 ) cout << "No 1 is the Odd And No 2 is Even"; else cout << "No 2 is the Odd And No 1 is Even"; system("PAUSE"); return 0; } //3. Write a C++ program that reads two integers and determines and prints if th e first is a multiple of the second. // (Hint: use the modulus operator %). #include <iostream> using namespace std; int main(int nNumberofArgs, char* pszArgs[]) { cout << "Enter Two Numbers"; int no1; cout << "Enter No1: "; cin >> no1; int no2; cout << "Enter No2: "; cin >> no2; if (no1 % no2 == 0 ) cout << "No 1 is a multiple of No 2 "; else cout << "No 1 is a not multiple of No 2 "; system("PAUSE"); return 0; }

/ 5 Write a C++ program that reads three nonzero Float values and determines and prints if they could represent the side of a right triangle.

#include <iostream> using namespace std; int main(int nNumberofArgs, char* pszArgs[]) { cout << "Enter Three Numbers"; double x; cout << "Enter X: "; cin >> x; double y; cout << "Enter Y: "; cin >> y; double z; cout << "Enter Z: "; cin >> z; if (x <=0 y <=0 z <=0) { cout << "Invalid Input. Please Try again" << endl; } else { if ( ((x+y) > z) && ((x+z) > y) && ((y+z) > x)) { cout << "The entered lenghts are the sides of a valid triangle" << endl; } else cout << "The entered lengths cannot represent a triangle" << endl; } system("PAUSE"); return 0; } // 7. Write a C++ program, using the case-switch structure that asks the user to enter the // worker s category and the number of working hours to calculate and display his payment. // Payment calculation is based on this table: #include <iostream> using namespace std; int main(int nNumberofArgs, char* pszArgs[]) { cout << "Enter Worker s Category"; int x,y; cout << "Enter Worker s Category: "; cin >> x; switch (x) { case 1: cout << "Number of Worker Working Hours : ";

cin >> y; cout << "Worker s Payment = " << x*y; break; case 2: cout << "Number of Worker Working Hours : "; cin >> y; cout << "Worker s Payment = " << x*y; break; case 3 : cout << "Number of WorkerWorking Hours : "; cin >> y; cout << "Worker Payment Is = " << x*y; break; default: break; } system("PAUSE"); return 0; }

Вам также может понравиться