ParsX.com
پذیرش پروژه از دانشجویی ... تا سازمانی 09376225339
 
   ProfileProfile   Log in to check your private messagesLog in to check your private messages  |  FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups Log inLog in   RegisterRegister 

کمک

 
Post new topic   Reply to topic    ParsX.com Forum Index -> C/C++ Programming
View previous topic :: View next topic  
Author Message
omid_pascal
مهمون يكي دو روزه


Joined: 01 Jun 2006
Posts: 14

PostPosted: Mon Oct 23, 2006 4:39 pm    Post subject: کمک Reply with quote

لطفا برنامه اجتماع و اشتراک دو آرایه 5 تایی رادر یک آریه ی 10تایی را به زبان c++ بنویسید
با تشکر
Back to top
arash
مدير بخش سي
مدير بخش سي


Joined: 27 Nov 2004
Posts: 1232
Location: www.parsx.com

PostPosted: Tue Oct 24, 2006 12:03 am    Post subject: Reply with quote


#include <iostream.h>
#include <conio.h>
#include <stdlib.h>

int index=0;
int a[5],b[5],result[10]={0};

void eshterak(int a[],int b[]);
void ejtema(int a[],int b[]);
int found(int Number ,int Temp[],int Max);

 main(void)
{
   clrscr();
   randomize();
   for (int i=0;i<5;i++)
         {
      a[i]=random(10);
      b[i]=random(10);
         }
   for(i=0 ;i<5;i++)
      cout<<" "<<a[i];
   cout<<"\n\n";
   for(i=0 ;i<5;i++)
      cout<<" "<<b[i];
   ejtema(a,b);
   cout<<"\n\n ejtema :\n \n ";
   for(i=0 ;i<index;i++)
      cout<<" "<<result[i];
   eshterak(a,b);
   cout<<"\n\n\n eshterak :\n\n";
   for(i=0 ;i<index;i++)
      cout<<" "<<result[i];
   getch();
 return 0;
}
void eshterak(int a[],int b[])
{
   index=0;
   for(int i=0;i<5;i++)
      if ( found(a[i],b,5) )
         if ( !found(a[i],result,i) )
            result[index++]=a[i];
}
void ejtema(int a[],int b[])
{
   index=0;
   for(int i=0;i<5;i++)
      if ( !found(a[i],b,5) )
         if ( !found(a[i],result,i) )
            result[index++]=a[i];
   for(int j=0;j<5;j++)
      if ( !found(b[j],result,5+j) )
         result[index++]=b[j];
}
int found(int Number,int Temp[],int Max)
{
    for (int i=0;i<Max;i++)
   if (Number==Temp[i])return 1;
    return 0;
}
Back to top
Display posts from previous:   
Post new topic   Reply to topic    ParsX.com Forum Index -> C/C++ Programming All times are GMT + 3.5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum