#include <iostream>
#include <time.h>
using namespace std;
int main() {
srand(time(0));
int k, n=0;
cin>>k;
double arr[k];
for (int i=0; i<k; ++i) {
arr[i]=rand()%2001-1000;
if (arr[i]>0) ++n;
}
for (int i=0; i<k; ++i) cout<<arr[i]<<" ";
cout<<endl;
double arra[n];
n=0;
for (int i=0; i<k; ++i)
if (arr[i]>0) {
arra[n]=arr[i];
++n;
for (int i=0; i<n; ++i) cout<<arra[i]<<" ";
return 0;
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
#include <iostream>
#include <time.h>
using namespace std;
int main() {
srand(time(0));
int k, n=0;
cin>>k;
double arr[k];
for (int i=0; i<k; ++i) {
arr[i]=rand()%2001-1000;
if (arr[i]>0) ++n;
}
for (int i=0; i<k; ++i) cout<<arr[i]<<" ";
cout<<endl;
double arra[n];
n=0;
for (int i=0; i<k; ++i)
if (arr[i]>0) {
arra[n]=arr[i];
++n;
}
for (int i=0; i<n; ++i) cout<<arra[i]<<" ";
cout<<endl;
return 0;
}