Skip to content

Instantly share code, notes, and snippets.

@elit69
Last active December 18, 2015 13:39
Show Gist options
  • Save elit69/5792014 to your computer and use it in GitHub Desktop.
Save elit69/5792014 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
int main(void)
{ int na;
cin >> na;
int *a = new int[na];
cout << "array a" << endl;
for(int i=0; i<na; i++) {
cin >> a[i];
}
int b[]={4,56,4,56,56,7,56,7,567};
int nb = sizeof(b)/sizeof(int);
cout << "array b" << endl;
for(int i=0; i<nb; i++) {
cout << b[i] <<endl;
}
cout<<endl;
int Old_na = na;
na = na + nb;
cout<<"old na\t"<<Old_na<<endl<<"nb\t"<<nb<<endl<<"new na\t"<<na<<endl<<endl;
int j = 0;
for(int i=Old_na; i<na; ++i) {
a[i] = b[j];
++j;
}
cout<<"new array a"<<endl;
for(int k=0; k<na; k++) {
cout<<a[k]<<endl;
}
}
#include<iostream.h>
#include<time.h>
#include<stdlib.h>
int main(void)
{
int a[]={5,4,47,3,8,435,768,45,67};
int n;
n = sizeof(a)/sizeof(int);
for(int i=0; i<n; i++) {
cout<<a[i]<<'\t';
}
cout<<endl;
srand(static_cast<unsigned int>(time(0)));
int ri = rand() % n;
cout<<"random number is\t"<<a[ri]<<endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment