ahmedfci
Active Member
- تاريخ التسجيل
- 8 مارس 2012
- المشاركات
- 32
- المجموعة
- ذكر
- الدفعة الدراسية
- معلومة خاصة
- الكلية
- كلية تقنية المعلومات
Insert Between Odds
كود:
#include <iostream>
using namespace std;
const int Max_Size=10;
//The first function
void Print(int arr[],int length)
{
cout<<"Your Items : "<<endl;
for(int i=0;i<length;i++)
{
cout<<arr[i]<<endl;
}
cin.get();
}
//the second function
void ShiftToRight(int Arr[],int pos,int length)
{
for(int i=length-1;i>=pos;i--)
{
Arr[i+1]=Arr[i];
}
cin.get();
}
void insertBetweenOdds(int List[],int Length,int Max_Size)
{
int sum=0;
for(int i=0;i<Length;i++)
{
if(List[i]%2==1)
if(List[i+1]%2==1)
{
if(Length+1 >= Max_Size)
{
cout<<"The array is full"<<endl;
cin.get();
return;
}
else
{
sum=List[i]+List[i+1];
ShiftToRight(List,i+1,Length);
List[i+1]=sum;
Length=Length+1;
}
}
}
Print(List,Length);
cin.get();
}
void main()
{
int myArray[Max_Size];
int length;
cout<<"Please enter the number of elements"<<endl;
cin>>length;
//take the values from the user
cout<<"\nNow enter "<<length<<" values"<<endl;
for(int i=0;i<length;i++)
{
cin>>myArray[i];
}
//Calling the function
insertBetweenOdds(myArray,length,Max_Size);
cin.get();
}


بس اذا مش واضح قوليلي انشاء الله بشرح بطريقه اوضح

