Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- *Napisz program, który z jednej tablicy
- typu zawierającej liczby całkowite o długości n zrobi dwie tablice do
- jednej wpisując liczby parzyste, do drugiej liczby nieparzyste.*/
- #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 *tab;
- int *tab1; //parzyste
- int *tab2; // nieparzyste
- int n; //rozmiar
- cout<<"Podaj rozmiar tablicy : ";
- cin>>n;
- tab=new int [n];
- for(int i=0;i<n;i++)
- {
- tab[i]=rand()%10+1;
- cout<<tab[i]<<" ";
- }
- int parzyste=0;
- int nieparzyste=0;
- for(int i=0;i<n;i++)
- {
- if(tab[i]%2==0)
- {
- parzyste++;
- }
- else
- {nieparzyste++;}
- }
- tab1=new int [parzyste];
- tab2=new int [nieparzyste];
- int temp=0;
- for(int i=0;i<n;i++)
- {
- if(tab[i]%2==0)
- {
- tab1[temp]=tab[i];
- temp++;
- }
- }
- cout<<endl<<"TABLICA LICZB PARZYSTYCH "<<endl;
- for(int i=0;i<temp;i++)
- {
- cout<<tab1[i]<<" ";
- }
- int temp1=0;
- for(int i=0;i<n;i++)
- {
- if(tab[i]%2!=0)
- {
- tab2[temp1]=tab[i];
- temp1++;
- }
- }
- cout<<endl<<"TABLICA LICZB NIEPARZYSTYCH "<<endl;
- for(int i=0;i<temp1;i++)
- {
- cout<<tab2[i]<<" ";
- }
- system("PAUSE");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment