أعتذر على التأخير هذه بعض الأمثلة ادرسوها ثم نشرحها سطر سطر
كود PHP:
[LEFT]#include <iostream.h>
void main()
{
int number1, number2; // Variables to hold the values
cout << "Enter the value of the first number : "; // Prompet the user to enter the first number
cin >> number1;
cout << "Enter the value of the second number : "; // Prompet the user to enter the second numbre
cin >> number2;
// Calculate the sum
cout << "The result of SUM is " << number1 + number2;
// Calculate the product
cout << "The result of PRODUCT is " << number1 * number2;
// Calculate the difference
cout << "\nThe result of DIFFERENCE is " << number1 - number2;
// Calculate the quotient
cout << "\nThe result of QUOTIENT is " << number1 / number2;
}
1.25 Solution
#include <iostream.h>
void main()
{
int number1, number2; // Variables to hold the values
cout << "Enter the value of the first number : "; // Prompet the user to enter the first number
cin >> number1;
cout << "\nEnter the value of the second number : "; // Prompet the user to enter the second numbre
cin >> number2;
if ( number1 > number2 )
cout << number1 << " is greater than " << number2;
else
cout << number2 << " is greater than " << number1;
}
1.26 Solution
#include <iostream.h>
void main()
{
int number1, number2, number3 ; // Variables to hold the values
cout << "Enter the value of the first number : "; // Prompet the user to enter the first number
cin >> number1;
cout << "Enter the value of the second number : "; // Prompet the user to enter the second numbre
cin >> number2;
cout << "Enter the value of the third number : "; // Prompet the user to enter the second numbre
cin >> number3;
// Calculate the sum
cout << "The result of SUM is " << ( number1 + number2 + number3 );
// Calculate the product
cout << "\nThe result of PRODUCT is " << ( number1 * number2 * number3 );
// Calculate the average
cout << "\nThe result of AVERAGE is " << ( number1 + number2 + number3 ) / 3;
if ( ( number1 > number2 ) && ( number2 > number3 ) )
cout << "\n The GREATEST is : " << number1;
else
if ( ( number1 < number2 ) && ( number2 < number3 ) )
cout << "\n The SMALLEST is : " << number1;
if ( ( number2 > number1 ) && ( number1 > number3 ) )
cout << "\n The GREATEST is : " << number2;
else
if ( ( number2 < number1 ) && ( number1 < number3 ) )
cout << "\n The SMALLEST is : " << number2;
if ( ( number3 > number1 ) && ( number1 > number2 ) )
cout << "\n The GREATEST is : " << number3;
else
if ( ( number3 < number1 ) && ( number1 < number2 ) )
cout << "\n The SMALLEST is : " << number3;
}
1.27 Solution
#include <iostream.h>
#include <math.h>
void main()
{
const int cval = 3.14159;
int raduis;
cout << "Enter the value of the Raduis : ";
cin >> raduis;
cout << "The circle's diameter is : " << raduis * 2;
cout << "\nThe circle's circumference is : " << cval * 2 * raduis;
cout << "\nThe circle's area is : " << cval * pow( raduis, 2 );
}
1.28 Soltuion
#include <iostream.h>
void main()
{
cout << "********\t" << " *** \t" << " * \t" << " * \n";
cout << "* *\t" << " * * \t" << " *** \t" << " * * \n";
cout << "* *\t" << "* * \t" << " ***** \t" << " * * \n";
cout << "* *\t" << "* * \t" << " * \t" << " * * \n";
cout << "* *\t" << "* * \t" << " * \t" << "* *\n";
cout << "* *\t" << "* * \t" << " * \t" << " * * \n";
cout << "* *\t" << "* * \t" << " * \t" << " * * \n";
cout << "* *\t" << " * * \t" << " * \t" << " * * \n";
cout << "********\t" << " *** \t" << " * \t" << " * \n";
}
1.29 Solution
*
**
***
****
*****
1.30 Solution[/LEFT]
يمكننا حل المسالة باستخدام التوابع ، و تكون بالتالي أسهل و أقل من ناحية عدد الأسطر
[LEFT]#include <iostream.h>
int greatest( int, int );
int smallest( int, int );
void main()
{
int integer1, integer2, integer3, integer4, integer5;
cout << "Enter the five integers : ";
cin >> integer1 ;
cin >> integer2 ;
cin >> integer3 ;
cin >> integer4 ;
cin >> integer5;
cout << "The GREATEST number is :";
cout << ( greatest( greatest( greatest( integer1, integer2 ), greatest( integer3, integer4 ) ), integer5 ) );
cout << endl;
cout << "The SMALLEST number is :";
cout << ( smallest( smallest( smallest( integer1, integer2 ), smallest( integer3, integer4 ) ), integer5 ) );
cout << endl;
}
int greatest( int a, int b )
{
if ( a > b )
return a;
else
return b;
}
int smallest( int a, int b )
{
if ( a < b )
return a;
else
return b;
}
1.31 Solution
#include <iostream.h>
int test( int );
void main()
{
int integer;
cout << "Enter the integer : ";
cin >> integer;
if ( test( integer ) == 1 )
cout << integer << " IS AN EVEN INTEGER ";
else
cout << integer << " IS AN ODD INTEGER ";
cin >> a;
}
int test( int n )
{
if ( n % 2 == 0 )
return 1;
else
return -1;
}
1.32 Solution
#include <iostream.h>
int test_mul( int, int );
void main()
{
int integer1, integer2;
cout << "Enter the tow integers : ";
cin >> integer1 >> integer2;
if ( test_mul( integer1, integer2 ) == 1 )
cout << integer2 << " is multiple of " << integer1;
else
cout << integer2 << " is not multiple of " << integer1;
}
int test_mul( int n1, int n2 )
{
if ( n2 % n1 == 0 )
return 1;
else
return -1;
}
1.33 Solution
#include <iostream.h>
void main()
{
cout << "* * * * * * * *\n";
cout << " * * * * * * * *\n";
cout << "* * * * * * * *\n";
cout << " * * * * * * * *\n";
cout << "* * * * * * * *\n";
cout << " * * * * * * * *\n";
cout << "* * * * * * * *\n";
cout << " * * * * * * * *\n";
}
Or
#include <iostream.h>
void main()
{
cout << "* * * * * * * *\n * * * * * * * *\n";
cout << "* * * * * * * *\n * * * * * * * *\n";
cout << "* * * * * * * *\n * * * * * * * *\n";
cout << "* * * * * * * *\n * * * * * * * *\n";
}
Or
#include <iostream.h>
void main()
{
cout << "* * * * * * * *\n * * * * * * * *\n* * * * * * * *\n * * * * * * * *\n";
cout << "* * * * * * * *\n * * * * * * * *\n* * * * * * * *\n * * * * * * * *\n";
}
Or
#include <iostream.h>
void main()
{
cout << "* * * * * * * *\n * * * * * * * *\n* * * * * * * *\n * * * * * * * *\n* * * * * * * *\n * * * * * * * *\n* * * * * * * *\n * * * * * * * *\n";
}
1.36 Solution
#include <iostream.h>
void main()
{
int a, b, c, d, e, f, g, h;
int number;
cout << "Enter the number : ";
cin >> number;
a = number / 10000;
b = number % 10000;
c = b / 1000;
d = b % 1000;
e = d / 100;
f = d % 100;
g = f / 10;
h = f % 10;
cout << a << " " << c << " " << e << " " << g << " " << h ;
}
1.37 Solution[/LEFT]
حل التمرين باستخدام الحلقات
[LEFT]#include <iostream.h>
void main()
{
cout <<"Number \tSquare\tCube\n";
for ( int i=0; i <= 10; i++ )
cout <<i << "\t" << i*i <<"\t" << i*i*i << "\n";[/LEFT]
}