srand(time(0)) ;
int n; cout << "n: " ; cin>> n;
int a ;
for (int i= 1 ; i <= n; i++) {
a = rand() ;
if (a % 2 == 0) {
cout << a << " " ;
}
}
return 0 ;
}
Dastur natijasi
14
Xj= (-14,5; 3,2; 6,8; - 4,3; 11,2; 5,6; - 7,8) massivining juft indeksli elementlarini V massivga, toq indeksli elementlarini esa S massivga tartiblab yozing.
Dastur kodi:
#include
#include
using namespace std ;
int main() {
int a[] = {-14 , 5,3, 2 , 6, 8, -4 ,3,11,2,5,6,-7,8} ;
vector juft ;
vector toq ;
for (int i = 0 ; i < sizeof(a) / sizeof(int) ; i++) {
if (i % 2 ==0) {
juft.push_back(a[i]) ;
} else {
toq.push_back(a[i]) ;
}
}
for (int i= 0 ; i < juft.size() ; i++) {
cout << juft[i] << " " ;
}
cout << endl ;
for (int i =0 ;i < toq.size() ;i++) {
cout << toq[i] << " " ;
}
return 0 ;
}