using namespace std;
int main()
{
int arr[20];
int number;
cout << "please put a number between 10 & 100 : ";
for( int i =0 ; i < 20; i++)
{
cin >> number;
while ( number < 10 || number > 100)
{
cout << "invalid number .. " <<endl;
cin >> number;
}
for(int j = 0 ; j < i ; j++)
{
if (number == arr[j] )
{
cout <<"Duplicated number .." <<endl;
cin >> number;
}
}
cout << "number add " << endl;
arr = number;
}
cout << "--------------------------------------------------------" << endl;
cout << "nonduplicate values are : " <<endl;
for ( int z =0 ; z < 20 ; z++)
{
cout << arr[z] << " " ;
}
cout << "please enter a number between 1 and 20: " <<endl;
int choose;
int avarge;
int calculate=0;
cin >> choose;
for ( int y = 0 ; y < choose ; y++)
{
calculate += arr[y];
}
avarge = calculate / choose;
cout << "the avarge of first " << choose << " element(s) in array is : " << endl;
cout << avarge << endl;
cout << " -------------------------------------------------" <<endl;
cout << " the firest element in array is " << endl;
cout << arr[0] <<endl;
cout << " the last element in array is " << endl;
cout << arr[19] << endl;
cout << "the middele element in array is " << endl;
int mid;
mid = 20 / 2 ;
cout << arr[mid] <<" and " << arr[mid+1] << endl;
cout << "------------------------------------------------------------------" <<endl;
bool sort = true;
for ( int k =0; k < 20 ; k ++ )
{
if (arr[k] > arr[k+1])
{
sort = false;
break;
}
}
if(sort == true )
{
cout << "array is sorted .... " <<endl;
}
else
{
cout << " array is not sorted... " << endl;
}
return 0;
}
#include <iostream>
في هذآ الكود عندي خطأ بسيط لا اعلم مآ هوٍ .. لكن الخطأ يقع في هذه المنطقه من الكود ..
for( int i =0 ; i < 20; i++)
{
cin >> number;
while ( number < 10 || number > 100)
{
cout << "invalid number .. " <<endl;
cin >> number;
}
for(int j = 0 ; j < i ; j++)
{
if (number == arr[j] )
{
cout <<"Duplicated number .." <<endl;
cin >> number;
}
}
cout << "number add " << endl;
arr = number;
}
الخطأ في المخرجات عندما اشغل البرنامج َ يطلب مني اول رقم ثم ادخله ..
ثم يطلب مني الرقم الثاني .. عندما ادخل الرقم الثاني يقول ان هناك رقم اخر مشابه له في المصفوفه !
هنا تطلع لي هذه الرساله
"Duplicated number .."
اتمنى تجريب الكود لـ تفهموآ المقصد بالضبط =(
