Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Napisz program, który mając dwie tablice liczb całkowitych o dowolnych długościach utworzy trzecią
- zawierającą tylko te liczby, które występują w obu tablicach.*
- #include "stdafx.h"
- #include <cmath>
- #include <cstdlib>
- #include <cstdio>
- #include <iostream>
- #include <ctime>
- #include <time.h>
- using namespace std;
- int _tmain(int argc, _TCHAR* argv[])
- {
- srand(time(NULL));
- int *tab1;
- int *tab2;
- int *tab3;
- int size1,size2;
- cout<<"podaj rozmiar 1 tablicy : ";
- cin>>size1;
- tab1=new int [size1];
- cout<<"Podaj rozmiar 2 tablicy : ";
- cin>>size2;
- tab2=new int [size2];
- for(int i=0;i<size1;i++)
- {
- tab1[i]=rand()%5+1;
- cout<<tab1[i]<<" ";
- }
- cout<<endl;
- for(int j=0;j<size2;j++)
- {
- tab2[j]=rand()%5+1;
- cout<<tab2[j]<<" ";
- }
- int licznik=0; //ile takich samych
- for(int i=0;i<size1;i++)
- {
- for(int j=0;j<size2;j++)
- {
- if(tab1[i]==tab2[j])
- {
- licznik++;
- }
- }
- }
- cout<<endl<<"LICZNIK WYNOSI !!! "<<licznik<<" !!!!!"<<endl<<endl;
- int l=0;
- tab3=new int [licznik];
- for(int i=0;i<size1;i++)
- {
- for(int j=0;j<size2;j++)
- {
- if(tab1[i]==tab2[j])
- {
- tab3[l]=tab1[i];
- l++;
- }
- }
- }
- for(int i=0;i<licznik;i++)
- {
- cout<<tab3[i]<<" ";
- }
- system("PAUSE");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment